-
Notifications
You must be signed in to change notification settings - Fork 2
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
onKeyValue should dispatch the resolved value #30
Conversation
var globals = new Globals(); | ||
var foo = 'foo'; | ||
globals.define('foo', ''); | ||
globals.onKeyValue('foo', function(value){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to unbind this listener so it doesn't effect other tests in the future
@@ -7,6 +7,9 @@ function dispatch(key, value) { | |||
var handlers = this.eventHandlers[key]; | |||
if (handlers) { | |||
var handlersCopy = handlers.slice(); | |||
if (typeof value === 'function') { | |||
value = value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this fix my can-util problem? Looks like it'll dispatch undefined, when what I need is the default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, this should fix my problem, but if value() returns undefined I still expect it to return the default value.
can-globals-proto.js
Outdated
value = value(); | ||
} | ||
if (value === undefined) { | ||
value = this.properties[key].default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrejewski so you're thinking something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@imaustink Yep. But unless I'm misunderstanding the code, default
can also be a function so that would need called as well to return a value.
Fixes #29