-
Notifications
You must be signed in to change notification settings - Fork 4
Durandal Compose convention
Anders Malmgren edited this page Jan 17, 2014
·
3 revisions
(function(ko) {
isViewOrModel = function(value) {
return value.indexOf("viewmodels/") === 0 || value.indexOf("views/") === 0;
};
delete ko.bindingConventions.conventionBinders.template;
ko.bindingConventions.conventionBinders.compose = {
rules: [function(name, element, bindings, unwrapped, type) { return (type === "object" || (type === "string" && isViewOrModel(unwrapped))) && !ko.bindingConventions.utils.nodeHasContent(element); }],
apply: function(name, element, bindings, unwrapped, type, dataFn) {
bindings.compose = dataFn;
}
};
ko.bindingConventions.conventionBinders.text.rules.push(function(name, element, bindings, unwrapped, type) {
return !isViewOrModel(unwrapped);
});
})(ko);
Above snippet will delete template convention and add a Compose convention. There limitations that you need to known about, if you want to supply it with a model or view url string the path most begin with "viewmodels/" or "views/".