-
Notifications
You must be signed in to change notification settings - Fork 307
Clarification on construction and creation of events #372
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
Comments
Also, if I want to have cancelable as true as default, do I need to have that as an override on
|
s/if I want to have cancelable as true/if I want to have cancelable as true as default |
Examples and explanations are always good; we should add some. In general "create an event" should be used very rarely, in specialized situations where you need to separate event creation from event dispatch, or want to customize the realm the event is created in. Fire an event is usually more appropriate.
Sure, but why would you need to? "create an event" runs all the constructor logic. Compare create an event and event constructor
Yep. You can do that yourself pretty easily though. "Initialize event's
It's cleaner to explicitly state what you're setting, than passing it in as an unnamed argument. (And if you pass it in as a named argument, you aren't really saving anything.)
You should never override the default of basic properties of events like However, you can just ensure that whenever you fire or dispatch an event yourself in your spec, you initialize (Speaking of which, @annevk, the doAction example should probably be marked as cancelable, otherwise doAction is always true, right?) |
Thanks @domenic!
Ok, maybe we should clarify the above in the spec? In particular, warn people that they should really go and just use "fire an event". In fire an event, "eventConstructor" should maybe be renamed "eventInterface" as to avoid confusion (it confused me initially as I thought it needed a constructor function).
Yeah, true. |
So, more concretely, in relation to creation, I have the following:
In the create algo, the spec says:
But My intention was so developers could construct these events and have var x = new BeforeInstallPromptEvent("beforeinstalmprompt", {userChoice: "accepted"})
x.prompt().then(({userChoice}) => `The user selected: ${userChoice}`) But not realizing that this is incompatible with the create algo 😢. I should probably drop |
That's kind of implied by the spec's "Create an event is meant to be used by other specifications which need to separately create and dispatch events, instead of simply firing them," but it could be clearer I suppose.
Oh, then it's an invalid event.
Yeah, it's not really OK for an event to be able to synchronously provide a value but not synchronously read it back. So either remove the ability to initialize it with a given userChoice, or just add a userChoice property to BeforeInstallPromptEvent. |
Thanks for the clarification... and hugs during these shitty times. |
Reopening since it seems some work might be needed still. |
So I think the takeaways are:
Anything else that would be helpful? |
Could you kindly provide a bit more guidance with respect to creation and construction of events? Right now, one can do:
But, the algorithm has not called x's constructor - not has it set its type.
If I'm using "create an event", do I then call the constructor straight after with the type? Why not allow
type
to be provided with "create an event"?Maybe the spec could provide an example of the ideal order for these.
The text was updated successfully, but these errors were encountered: