-
Notifications
You must be signed in to change notification settings - Fork 12
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
Decomplect the event notification #35
Comments
Are you thinking something like this This will be a problem for Thoughts? |
Hmmm.... Good point. One way would be to constrain the attributes to the position arguments. This would be in keeping with the way other microstates are constructed: {{let object=(Object (hash foo="bar") on-assign=(action 'onAssign')}} Another option would be to blacklist anything starting with |
I would prefer the former. Alternatively, I could allow both but event binding would only work when constructed via the first param. |
Yeah, making the object attributes feels right from the implementers perspective, and it is in keeping with the idea that a microstate "boxes" a real object. Still, it does make the api a little more awkward. So are you saying that with one argument, it's the value, with two arguments, the first is the value, the second is the options? |
No, I was thinking that it might work like this: {{let object=(Object (hash hello="world") on-init=(action 'foo'))}} or {{let object=(Object foo="bar")}} The user can use either of these but with the 2nd, they can't bind transitions. But really, I think we should accept the "little more awkward" and only allow |
I agree. I think simplicity of interface in this case is called for. The general form of microstate is:
That means when you're using it, you don't have to think about each individual constructor api. |
I'm going to start with this:
I'd like to exclude |
@cowboyd is the intention that we continue to use |
In our file upload helper we use {{#each files as |file|}}
{{let upload=(file-upload file on-init=(action "startImmediately"))}}
{{/each}} vs manually starting: {{#each files as |file|}}
{{let upload=(file-upload file)}} <button onclick={{action upload.start}}>Upload</button>
{{/each}} |
I'm good with this. |
@cowboyd I'm going to refactor the tests to only test for |
To the exclusion of |
Oh, nvm, we need |
One of the consistent pieces of feedback on authoring your own microstates is that the event notification API is confusing. The
setState
function accepts an optional initial string is the name of the event that gets fired. This is really non intuitive, flummoxes everyone who comes across it, and needs to go.Let's take a step backwards and implement a modest event regimen with much less magic that is simple, predictable and easy to understand. There are three, and only three kinds of events that a microstate fires automatically.
on-init
Fires whenever a microstate helper recomputes because its parameter changes.
on-state
Fires whenever a new state is available to the microstate for any reason.
on-[transition-name]
Fired whenever a transition is invoked, receives the state resulting from that transition. So for example, on the boolean microstate
on-toggle
will be fired whenever the boolean transition is invoked.The text was updated successfully, but these errors were encountered: