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

Listener has no knowledge of what property it is registered for #13

Open
erotavlas opened this issue Mar 29, 2017 · 2 comments
Open

Listener has no knowledge of what property it is registered for #13

erotavlas opened this issue Mar 29, 2017 · 2 comments

Comments

@erotavlas
Copy link
Contributor

erotavlas commented Mar 29, 2017

The listener that is passed to observe(listener, options) is a function that is provided two values, 'newvalue' and 'oldvalue when the property it was registered for in the model was changed. However once inside the listener function, there is no way to know what property these values correspond to.

For example say you are trying to set up all your observers dynamically like this in a for loop

                    widget.observeHandles[property] = widget.propertyObjects[property].observe(
         
                        function (newValue, oldValue) {
                            
                            console.log(property + " old value: " + oldValue);
                            console.log(property + " new value: " + newValue);

                            that.properties[property] = newValue;
                            that.propertyFunctions[property](newValue);
                        },
                        {
                            onlyFutureUpdates: onlyFutureUpdatesFlag
                        }

                    );

Once inside the function there is no knowledge of the property change which activated this function call, therefore you cannot run any code that depends on the name of that property.

Can this be added as a third parameter to the listener - like function(newValue, oldValue, property)?

@dylans
Copy link

dylans commented Apr 11, 2017

@erotavlas this seems like a reasonable suggestion. Would you be interested in creating a pull request to add the third parameter?

@erotavlas
Copy link
Contributor Author

Ok I'd be willing to do it, but I already tried modifying Model.js on my own without success.

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