Commit 5be33c01238870a66c608fed4ece3fbc43069a51
html-element: don't bind to classList unless contains observerables
Matt McKegg committed on 7/27/2016, 9:46:54 AMParent: 64b0f0923c1d166b21f730eb06c7e34533e6605d
Files changed
lib/apply-properties.js | changed |
set.js | changed |
lib/apply-properties.js | ||
---|---|---|
@@ -61,13 +61,24 @@ | ||
61 | 61 | } |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | - if (classList.getLength()) { | |
65 | + if (containsObservables(classList)) { | |
66 | 66 | 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(' ') | |
67 | 70 | } |
68 | 71 | } |
69 | 72 | |
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 | + | |
70 | 81 | function bindClassList (target, obs, key) { |
71 | 82 | return watch(obs, function (value) { |
72 | 83 | value = [].concat.apply([], value).filter(present).join(' ') |
73 | 84 | if (value || target[key]) { |
Built with git-ssb-web