-
Notifications
You must be signed in to change notification settings - Fork 162
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
Comments
+1 |
i'm not sure how serious i was about this... please provide some inspiration for a better api. |
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
}
}) |
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. |
Working on this https://github.com/oveddan/node-oauth2-provider |
Maybe subclassing or delegation would be better...
The text was updated successfully, but these errors were encountered: