git ssb

1+

Matt McKegg / mutant



Commit 5be49af9cc03aa1519439c1576fd40202cf243eb

html-element: fix applying of functions as event handlers

Matt McKegg committed on 9/10/2016, 6:08:58 AM
Parent: f5910e3be7de0ef9ad989e4646cf08a5cc427a82

Files changed

lib/apply-properties.jschanged
lib/apply-properties.jsView
@@ -11,12 +11,12 @@
1111 }
1212
1313 for (var key in properties) {
1414 var valueOrObs = properties[key]
15- var value = resolve(valueOrObs)
1615
1716 if (key === 'style') {
1817 // TODO: handle observable at root for style objects
18+ var value = resolve(valueOrObs)
1919 for (var k in value) {
2020 var styleObs = isObservable(value[k]) ? value[k] : null
2121 if (styleObs) {
2222 data.bindings.push(new Binding(bindStyle, target, styleObs, k))
@@ -24,14 +24,16 @@
2424 target.style.setProperty(k, value[k])
2525 }
2626 }
2727 } else if (key === 'hooks') {
28+ var value = resolve(valueOrObs)
2829 if (Array.isArray(value)) {
2930 value.forEach(function (v) {
3031 data.bindings.push(new HookBinding(v, target))
3132 })
3233 }
3334 } else if (key === 'attributes') {
35+ var value = resolve(valueOrObs)
3436 for (var k in value) {
3537 var attrObs = isObservable(value[k]) ? value[k] : null
3638 if (attrObs) {
3739 data.bindings.push(new Binding(bindAttr, target, attrObs, k))
@@ -39,13 +41,13 @@
3941 target.setAttribute(k, value[k])
4042 }
4143 }
4244 } else if (key === 'events') {
43- for (var name in value) {
44- target.addEventListener(name, value[name], false)
45+ for (var name in valueOrObs) {
46+ target.addEventListener(name, valueOrObs[name], false)
4547 }
4648 } else if (key.slice(0, 3) === 'ev-') {
47- target.addEventListener(key.slice(3), value, false)
49+ target.addEventListener(key.slice(3), valueOrObs, false)
4850 } else if (key === 'className' || key === 'classList') {
4951 if (Array.isArray(valueOrObs)) {
5052 valueOrObs.forEach(function (v) {
5153 classList.add(v)
@@ -53,9 +55,9 @@
5355 } else {
5456 classList.add(valueOrObs)
5557 }
5658 } else {
57- target[key] = value
59+ target[key] = resolve(valueOrObs)
5860 var obs = isObservable(valueOrObs) ? valueOrObs : null
5961 if (obs) {
6062 data.bindings.push(new Binding(bind, target, obs, key))
6163 }

Built with git-ssb-web