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

onChange only fires once during initialization #6

Closed
cookmscott opened this issue Apr 3, 2019 · 3 comments
Closed

onChange only fires once during initialization #6

cookmscott opened this issue Apr 3, 2019 · 3 comments

Comments

@cookmscott
Copy link

Hey Samuel and friends... My expectation of the below is that foo() will execute each time the active font is changed. In other words, the onChange function of the constructor should fire every time a user selects a new font. However, it seems foo() is only executed once on initialization.

let fontPicker = new FontPicker(
    'keysdgjlkjsdg', // Google API key
    'Open Sans', // default font
    {limit: 20},
    foo()
);    

function foo() {
    console.log ('font changed')
}

Let me know if you'd like a fiddle.

@samuelmeuli
Copy link
Owner

Hi @cookmscott,

The problem is that you're executing the function when you pass it to the picker as a paremter. Instead, you should only pass a reference to the function (no parentheses):

let fontPicker = new FontPicker(
    'keysdgjlkjsdg', // Google API key
    'Open Sans', // default font
    {limit: 20},
    foo
);    

function foo() {
    console.log ('font changed')
}

Let me know if this works as expected :)

@samuelmeuli
Copy link
Owner

It's probably unexpected behavior that the function also fires on initialization, though. I think I might change that.

@cookmscott
Copy link
Author

Omahgerd... Simply specifying foo as a parameter to the picker works like a charm. Thanks for catching my mistake!

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

2 participants