-
Notifications
You must be signed in to change notification settings - Fork 4
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
make 'with' more lightweight #9
Comments
ko.bindingHandlers['withlight'] = {
'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var bindingValue = valueAccessor();
if (typeof bindingValue != 'object' || bindingValue === null)
throw new Error('withlight must be used with an object');
var innerContext = bindingContext['createChildContext'](bindingValue);
ko.applyBindingsToDescendants(innerContext, element);
return { 'controlsDescendantBindings': true };
}
}; |
Oops. Last commit also included some unrelated changes to dependentObservable. |
Any chance I can use this with containerless bindings? .... It's pretty hard to generate elements without a container otherwise.The "with binding" sucks, at it replaces the html itself, thus all the pre-filled values, jquery event bindings etc. will be lost! |
Not at this point. It would require some changes within Knockout. |
Too bad :( "with" makes ko unusable. It should for sure not "recreate" the DOM! |
Why not updating KO itself? |
I've submitted a pull request for Knockout to support custom container-less binding: knockout#290 |
Where did the withlight binding go in the latest v2.1.0pre? |
I don't think it was ever included in 2.1. I'm hoping we'll get it in as part of 2.2. |
maybe withlite can be renamed to "using"? |
Please can we have this included in KO? This is a core feature and maintaining this as a custom binding outside of KO can introduce bugs. I also vote that "using" is an appropriate name for this binding, and sounds better than "withlight", because rather than being a lighter version of "with" it is really a replacement for it. This naming would permit phasing out of "with". |
I've opened an issue for the improved |
So what's the current status? |
We're planning to include an improved |
Knockout 2.2 includes a new implementation of |
Already in the docs? |
We didn't update the docs for it since it's not exactly a feature. It just makes the binding work more like people expect. |
Will it appear in the docs? :) |
The above |
I'd like to see what you're talking about. Can you put together an example for me? |
Do you konw
|
The 'with' binding currently uses the native template template engine, which adds a lot of overhead. The main purpose of the 'with' binding is to push a new binding context to the stack for child elements (doesn't affect any other bindings on the same element as 'with').
The current implementation also does an 'if' with the target of 'with', which I think is incorrect (doesn't match the way 'with' works in JS or in other languages). So although removing the templating code under with would remove the 'if' functionality, I thinks that it's better anyway.
'with' should still work in container-less bindings (), which would need to be modified to work with non-template bindings.
The text was updated successfully, but these errors were encountered: