-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Custom attributes #76
base: master
Are you sure you want to change the base?
Conversation
The current code on this branch avoids this problem by allowing custom attributes to be declared with a unique identifier that the framework tracks across consecutive renders. |
09a735a
to
06ac8f1
Compare
…tDestroy.There is a stumbling block here the container Patching code, where it seems sometimes the old declarative widget is not known, even though we have the state...
Reject bad states by erroring, instead of attempting to handle them.
It can be completely replaced by CustomAttribute
Just like in React - this makes the diffing algorithm more effective at finding the state for a declarative attribute.
Plus a function to set the default icon.
Firstly, I am aware this is all way off-piste, completely unsolicited, and probably not where you wanted to go, but I had some time and wanted to experiment...
So as I mentioned in #75 I had an idea for "custom attributes". These are attributes that can be attached to widgets in the tree, and can have arbitrary internal state and patching behaviour. So they are a bit like custom widgets, except that they don't require any new widgets to be added to the tree and that they can be composed more easily (you can add multiple custom attributes to your existing widget).
In some sense custom attributes are like a more flexible
afterCreated
attribute -- they can add custom behaviour on creation, but also on patching and destruction (and can emit events).In this branch they are used to:
Windows
example.CustomWidget
Examples
Custom attribute to add a new top-level window
Custom attribute to add a custom icon to a window
Custom attributes to implement custom widgets
Custom attributes completely replace custom widgets, since they allow you to run arbitrary create/patch/destroy code.
Downsides
Apart from the lack of tests and docs, there are a couple of downsides to this design:
Keep
/Modify
/Replace
optimisation (it always returnsIO state
-- which is equivalent toModify
). This could be changed easily enough, I think, though.I would appreciate any thoughts... or just close/ignore it 😄