git ssb

1+

Matt McKegg / mutant



Commit 5be33c01238870a66c608fed4ece3fbc43069a51

html-element: don't bind to classList unless contains observerables

Matt McKegg committed on 7/27/2016, 9:46:54 AM
Parent: 64b0f0923c1d166b21f730eb06c7e34533e6605d

Files changed

lib/apply-properties.jschanged
set.jschanged
lib/apply-properties.jsView
@@ -61,13 +61,24 @@
6161 }
6262 }
6363 }
6464
65- if (classList.getLength()) {
65+ if (containsObservables(classList)) {
6666 data.bindings.push(new Binding(bindClassList, target, classList, 'className'))
67+ } else {
68+ // OPTIMISATION: no need to create a binding if the list is never going to change
69+ target.className = classList().join(' ')
6770 }
6871 }
6972
73+function containsObservables (obs) {
74+ for (var i = 0, len = obs.getLength(); i < len; i++) {
75+ if (isObservable(obs.get(i))) {
76+ return true
77+ }
78+ }
79+}
80+
7081 function bindClassList (target, obs, key) {
7182 return watch(obs, function (value) {
7283 value = [].concat.apply([], value).filter(present).join(' ')
7384 if (value || target[key]) {
set.jsView
@@ -59,8 +59,12 @@
5959 })
6060 refresh()
6161 }
6262
63+ observable.get = function (index) {
64+ return sources[index]
65+ }
66+
6367 observable.getLength = function () {
6468 return sources.length
6569 }
6670

Built with git-ssb-web