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

Add a Event.once and Key.once #201

Closed
ngryman opened this issue Mar 4, 2018 · 2 comments
Closed

Add a Event.once and Key.once #201

ngryman opened this issue Mar 4, 2018 · 2 comments
Assignees
Milestone

Comments

@ngryman
Copy link

ngryman commented Mar 4, 2018

Hi @kasper, first and foremost, this is awesome tool! Thanks for your work.

Description

This is a small feature request for convenience, it would be nice to be able to subscribe to an event only once so when it's called, the event is automatically unsubscribed.
Most of event managers out there provide this feature and I think it could be cool.

As a bonus, if the handler explicitly returns false the event is not unsubscribed. So it lets the user filter the event he wants to be executed one.

Example

const filteredCallback = (appName, callback) =>
  (app) =>
    app.name() === appName
      ? callback(app)
      : _.stubFalse()

Event.on('appDidLaunch', filteredCallback('Code', () => {
  Event.once('appDidActivate', filteredCallback('Code', () => {
    // do stuff only once
  })
})
@kasper
Copy link
Owner

kasper commented Mar 5, 2018

Hi @ngryman! Thanks for the kind words! This definitely seems like a good addition to the API and is easy to implement in the JavaScript library. I will look into it!

@kasper
Copy link
Owner

kasper commented Apr 8, 2018

Implemented!

@kasper kasper closed this as completed Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants