Skip to content
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

Allow users provide code to handle context-level events #126

Open
AnAppAMonth opened this issue Jul 17, 2013 · 6 comments
Open

Allow users provide code to handle context-level events #126

AnAppAMonth opened this issue Jul 17, 2013 · 6 comments
Milestone

Comments

@AnAppAMonth
Copy link

It's similar in spirit to the init, ready and destroy built-in facets. The majority of users don't write plugins, if they can't write user code to handle context-level events, these events aren't very useful.

As to how to do it, I don't know. Maybe through new options to the wire factory? But then you can't handle events of the root context. Maybe an additional parameter to the global wire() function.

The same mechanism may also be used to allow users to also handle component events in the context level, I mean those general lifecycle listeners, in user code.

@briancavalier
Copy link
Member

Hey @halfninety, this seems like it could be useful. Do you have any particular use cases in mind?

As for how it could be done, it may make sense to provide facets similar to init, ready, and destroy. For example maybe something like:

myComponent: {
    create: //...,
    contextReady: 'doSomething'
}

Or, maybe it makes sense to namespace them:

myComponent: {
    create: //...,
    context: {
        ready: 'doSomething'
    }
}

Any thoughts about those options?

@AnAppAMonth
Copy link
Author

Very nice. I like the second option.

I don't have any use case in mind yet, just thought this could be useful.

@briancavalier
Copy link
Member

Cool, thanks for the feedback. I kinda like the second one as well. I'd like to see if @unscriptable and @scothis have any thoughts. Maybe they can think of some interesting use cases, or ideas for the DSL/API.

@unscriptable
Copy link
Member

I think I need some use cases before I can comment coherently on this. :)

@AnAppAMonth
Copy link
Author

What are the use cases you had in mind when adding context-level events? How are these events used now?

@briancavalier
Copy link
Member

@halfninety Typically, they are used by plugins to do setup or teardown. For example, it's quite common for a facet that provides some sort of connection functionality (like wire/connect, wire/on, wire/aop, etc.) to listen for context.destroy or context.shutdown and tear down all the connections it created.

I'm just not sure yet what things user-level code might do with them. One thought is that you might use context.ready to do something "when the entire application is ready". So far, though, the fact that wiring occurs in dependency order has been good enough, i.e. having a component with a ready method will tend to be executed around the same time as context.ready since it will be near the root of the dependency tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants