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

Fix abuse of EventEmitter for callbacks #3

Open
ammmir opened this issue Sep 8, 2011 · 5 comments
Open

Fix abuse of EventEmitter for callbacks #3

ammmir opened this issue Sep 8, 2011 · 5 comments

Comments

@ammmir
Copy link
Owner

ammmir commented Sep 8, 2011

Maybe subclassing or delegation would be better...

@timoxley
Copy link

timoxley commented Jul 6, 2012

+1

@ammmir
Copy link
Owner Author

ammmir commented Jul 6, 2012

i'm not sure how serious i was about this... please provide some inspiration for a better api.

@timoxley
Copy link

timoxley commented Jul 6, 2012

Events make sense if are likely going to have multiple listeners, but in this case, you're only going to provide a single listener to those events (in-fact, because you're passing a callback, multiple listeners doesn't even make sense). Just provide overridable functions.

// roughly
var provider = OAuth2Provider.create({
  access_token: function() {

  },
  lookup_grant: function(client_id, client_secret, code, next) {

  },
  create_access_token: function(user_id, client_id, next) {

  },
  save_access_token: function(user_id, client_id, atok) {

  },
  remove_grant: function() {
      // etc
  }
})

@oveddan
Copy link
Contributor

oveddan commented Sep 25, 2012

You could also do it via dependency injection - I always prefer composition over inheritance:

The provider would act as an api, and contain a token repository. This way you have two cohesive classes, one is public facing and the other is purely responsible for saving data. You could still emit the event for backwards compatibility, but I would have that done through a contained EventEmitter rather than base one.

@oveddan
Copy link
Contributor

oveddan commented Sep 25, 2012

Working on this https://github.com/oveddan/node-oauth2-provider

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