forked from knockout/knockout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'version-3.0.0-development' into merge-2.3.0-updates
Conflicts: src/binding/defaultBindings/options.js
- Loading branch information
Showing
30 changed files
with
1,942 additions
and
778 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
describe('Binding preprocessing', function() { | ||
it('Should allow binding to modify value through "preprocess" method', function() { | ||
delete ko.bindingHandlers.a; | ||
// create binding that has a default value of false | ||
ko.bindingHandlers.b = { | ||
preprocess: function(value) { | ||
return value || "false"; | ||
} | ||
}; | ||
var rewritten = ko.expressionRewriting.preProcessBindings("a: 1, b"); | ||
var parsedRewritten = eval("({" + rewritten + "})"); | ||
expect(parsedRewritten.a).toEqual(1); | ||
expect(parsedRewritten.b).toEqual(false); | ||
}); | ||
|
||
it('Should allow binding to add/replace bindings through "preprocess" method\'s "addBinding" callback', function() { | ||
ko.bindingHandlers.a = { | ||
preprocess: function(value, key, addBinding) { | ||
// the a binding will be copied to a2 | ||
addBinding(key+"2", value); | ||
return value; | ||
} | ||
}; | ||
ko.bindingHandlers.b = { | ||
preprocess: function(value, key, addBinding) { | ||
// the b binding will be replaced by b2 | ||
addBinding(key+"2", value); | ||
} | ||
}; | ||
var rewritten = ko.expressionRewriting.preProcessBindings("a: 1, b: 2"); | ||
var parsedRewritten = eval("({" + rewritten + "})"); | ||
|
||
expect(parsedRewritten.a).toEqual(1); | ||
expect(parsedRewritten.a2).toEqual(1); | ||
|
||
expect(parsedRewritten.b).toBeUndefined(); | ||
expect(parsedRewritten.b2).toEqual(2); | ||
}); | ||
|
||
it('Should be able to chain "preprocess" calls when one adds a binding for another', function() { | ||
ko.bindingHandlers.a = { | ||
preprocess: function(value, key, addBinding) { | ||
// replace with b | ||
addBinding("b", value); | ||
} | ||
}; | ||
ko.bindingHandlers.b = { | ||
preprocess: function(value, key, addBinding) { | ||
// adds 1 to value | ||
return '' + (+value + 1); | ||
} | ||
}; | ||
var rewritten = ko.expressionRewriting.preProcessBindings("a: 2"); | ||
var parsedRewritten = eval("({" + rewritten + "})"); | ||
expect(parsedRewritten.a).toBeUndefined(); | ||
expect(parsedRewritten.b).toEqual(3); | ||
}); | ||
|
||
it('Should be able to get a dynamically created binding handler during preprocessing', function() { | ||
var oldGetHandler = ko.getBindingHandler; | ||
ko.getBindingHandler = function(bindingKey) { | ||
return { | ||
preprocess: function(value) { | ||
return value + '2'; | ||
} | ||
}; | ||
}; | ||
var rewritten = ko.expressionRewriting.preProcessBindings("a: 1"); | ||
ko.getBindingHandler = oldGetHandler; // restore original function | ||
|
||
var parsedRewritten = eval("({" + rewritten + "})"); | ||
expect(parsedRewritten.a).toEqual(12); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.