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

onKeyValue should dispatch the resolved value #30

Merged
merged 3 commits into from
Nov 2, 2017

Conversation

imaustink
Copy link
Collaborator

Fixes #29

var globals = new Globals();
var foo = 'foo';
globals.define('foo', '');
globals.onKeyValue('foo', function(value){

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();

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.

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.

value = value();
}
if (value === undefined) {
value = this.properties[key].default;
Copy link
Collaborator Author

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?

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.

@imaustink imaustink merged commit 582b0bb into master Nov 2, 2017
@imaustink imaustink deleted the 29-events-should-dispatch-resloved-value branch November 2, 2017 15:44
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

Successfully merging this pull request may close these issues.

2 participants