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

Binding handlers should be able to use the init function to manage updates #500

Closed
mbest opened this issue May 25, 2012 · 9 comments
Closed
Assignees
Milestone

Comments

@mbest
Copy link
Member

mbest commented May 25, 2012

Currently a binding handler that uses a computed observable created in its init function to manage updates won't work in all cases.

It will work if the observable value is directly available through the valueAccessor function and can be "unwrapped" in the computed observable.

It will not work if an observable is unwrapped when the binding is parsed or if an observable view model is used.

An advantage of using this pattern is that one can set up persistent values in the init function that will be available during updates via closure.

In order to fully support this pattern, the valueAccessor function must provide notification for all observables that may cause the binding to update.

@mbest
Copy link
Member Author

mbest commented May 25, 2012

Wow, we're at 500 issues!

@rniemeyer
Copy link
Member

This particular issue causes me problems frequently.

@mbest
Copy link
Member Author

mbest commented May 26, 2012

Once #321 is in, this will be easy.

@ghost ghost assigned mbest May 31, 2012
@mbest
Copy link
Member Author

mbest commented Jun 13, 2012

I'd also like to add that observables accessed directly in init (not wrapped in a computed) shouldn't set any dependencies for the binding (or other bindings). @SteveSanderson mentioned in #326 that this is a breaking change, but it's likely a change that provides more good than bad (in my mind we'd be fixing a bug).

@rniemeyer
Copy link
Member

I am on board with that change too. I always thought it was odd for the init to register what amounts to a one-time dependency.

@mbest
Copy link
Member Author

mbest commented Jun 14, 2012

Another related issue is that when an element has multiple bindings, the init functions for all bindings are run before all the update functions. This needs to be changed so that for each binding, init is run first and then update (and then on to the next binding). Without this change, it's impossible for a binding that uses init to manage updates to run after a binding that uses update.

@mbest
Copy link
Member Author

mbest commented Jul 11, 2012

In order to fully support this pattern, the valueAccessor function must provide notification for all observables that may cause the binding to update.

This will have a side-effect that if the value of a binding is the result of a function call, that function will be run each time valueAccessor is called. Currently such a function is run once for each update of the element's bindings. It's probably not a big deal but just something to keep in mind.

@rniemeyer
Copy link
Member

That side-effect sounds reasonable to me. Does not sound like a problematic change.

@mbest
Copy link
Member Author

mbest commented May 7, 2013

Completed with #946.

@mbest mbest closed this as completed May 7, 2013
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