Commit 3f1b6be7 authored by Aaron-P's avatar Aaron-P

Check if other bindings exist before trying to attach

parent 6dabdcbf
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
$element.multiselect(config); $element.multiselect(config);
if (allBindings.has('options')) {
var options = allBindings.get('options'); var options = allBindings.get('options');
if (ko.isObservable(options)) { if (ko.isObservable(options)) {
ko.computed({ ko.computed({
...@@ -34,10 +35,12 @@ ...@@ -34,10 +35,12 @@
disposeWhenNodeIsRemoved: element disposeWhenNodeIsRemoved: element
}); });
} }
}
//value and selectedOptions are two-way, so these will be triggered even by our own actions. //value and selectedOptions are two-way, so these will be triggered even by our own actions.
//It needs some way to tell if they are triggered because of us or because of outside change. //It needs some way to tell if they are triggered because of us or because of outside change.
//It doesn't loop but it's a waste of processing. //It doesn't loop but it's a waste of processing.
if (allBindings.has('value')) {
var value = allBindings.get('value'); var value = allBindings.get('value');
if (ko.isObservable(value)) { if (ko.isObservable(value)) {
ko.computed({ ko.computed({
...@@ -50,9 +53,11 @@ ...@@ -50,9 +53,11 @@
disposeWhenNodeIsRemoved: element disposeWhenNodeIsRemoved: element
}).extend({ rateLimit: 100, notifyWhenChangesStop: true }); }).extend({ rateLimit: 100, notifyWhenChangesStop: true });
} }
}
//Switched from arrayChange subscription to general subscription using 'refresh'. //Switched from arrayChange subscription to general subscription using 'refresh'.
//Not sure performance is any better using 'select' and 'deselect'. //Not sure performance is any better using 'select' and 'deselect'.
if (allBindings.has('selectedOptions')) {
var selectedOptions = allBindings.get('selectedOptions'); var selectedOptions = allBindings.get('selectedOptions');
if (ko.isObservable(selectedOptions)) { if (ko.isObservable(selectedOptions)) {
ko.computed({ ko.computed({
...@@ -65,6 +70,7 @@ ...@@ -65,6 +70,7 @@
disposeWhenNodeIsRemoved: element disposeWhenNodeIsRemoved: element
}).extend({ rateLimit: 100, notifyWhenChangesStop: true }); }).extend({ rateLimit: 100, notifyWhenChangesStop: true });
} }
}
ko.utils.domNodeDisposal.addDisposeCallback(element, function() { ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$element.multiselect('destroy'); $element.multiselect('destroy');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment