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

Event listening support #3

Open
mikesir87 opened this issue Jun 1, 2017 · 1 comment
Open

Event listening support #3

mikesir87 opened this issue Jun 1, 2017 · 1 comment

Comments

@mikesir87
Copy link

Would be nice to allow me to hook in functions to hear and act on various events (like newly exposed/removed ports). There's a few ways this could be done, so figured I'd start the discussion.

What I'd like to propose is API similar to this...

pwd.on('event-name', cbFunction) => Function - returned function removes the listener when invoked

Using this approach, I can add an arbitrary number of listeners at any point in time, making it easy to add new plugins, etc.

This issue is more about plugging in the event API and not adding a particular event hook yet, as I feel those should be separate issues and keeps this discussion more focuses. Thoughts?

Example

The parameters are ones I just picked and would be dependent on the actual event being published.

pwd.on('instance.ports.new', function(instanceMetaData, port, url) {
  // Add a button that will display the port and open the url when clicked
});
@mikesir87
Copy link
Author

On second thought... maybe the .on method shouldn't return an unsubscribe function to allow for chaining of commands. There should be a separate .off (or similar) function that removes the event listener.

It looks like there are several event emitters already available too... making less code we'd have to maintain. Here's a library that already does event handling that we can simply integrate...

https://github.com/scottcorgan/tiny-emitter - super small and has a once method, which could be nice for one-time listeners (although not sure what they might be here)

mikesir87 added a commit to mikesir87/sdk that referenced this issue Jun 1, 2017
mikesir87 added a commit to mikesir87/sdk that referenced this issue Jun 1, 2017
mikesir87 added a commit to mikesir87/sdk that referenced this issue Jun 1, 2017
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

1 participant