Commit 5be49af9cc03aa1519439c1576fd40202cf243eb
html-element: fix applying of functions as event handlers
Matt McKegg committed on 9/10/2016, 6:08:58 AMParent: f5910e3be7de0ef9ad989e4646cf08a5cc427a82
Files changed
lib/apply-properties.js | changed |
lib/apply-properties.js | ||
---|---|---|
@@ -11,12 +11,12 @@ | ||
11 | 11 | } |
12 | 12 | |
13 | 13 | for (var key in properties) { |
14 | 14 | var valueOrObs = properties[key] |
15 | - var value = resolve(valueOrObs) | |
16 | 15 | |
17 | 16 | if (key === 'style') { |
18 | 17 | // TODO: handle observable at root for style objects |
18 | + var value = resolve(valueOrObs) | |
19 | 19 | for (var k in value) { |
20 | 20 | var styleObs = isObservable(value[k]) ? value[k] : null |
21 | 21 | if (styleObs) { |
22 | 22 | data.bindings.push(new Binding(bindStyle, target, styleObs, k)) |
@@ -24,14 +24,16 @@ | ||
24 | 24 | target.style.setProperty(k, value[k]) |
25 | 25 | } |
26 | 26 | } |
27 | 27 | } else if (key === 'hooks') { |
28 | + var value = resolve(valueOrObs) | |
28 | 29 | if (Array.isArray(value)) { |
29 | 30 | value.forEach(function (v) { |
30 | 31 | data.bindings.push(new HookBinding(v, target)) |
31 | 32 | }) |
32 | 33 | } |
33 | 34 | } else if (key === 'attributes') { |
35 | + var value = resolve(valueOrObs) | |
34 | 36 | for (var k in value) { |
35 | 37 | var attrObs = isObservable(value[k]) ? value[k] : null |
36 | 38 | if (attrObs) { |
37 | 39 | data.bindings.push(new Binding(bindAttr, target, attrObs, k)) |
@@ -39,13 +41,13 @@ | ||
39 | 41 | target.setAttribute(k, value[k]) |
40 | 42 | } |
41 | 43 | } |
42 | 44 | } 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) | |
45 | 47 | } |
46 | 48 | } else if (key.slice(0, 3) === 'ev-') { |
47 | - target.addEventListener(key.slice(3), value, false) | |
49 | + target.addEventListener(key.slice(3), valueOrObs, false) | |
48 | 50 | } else if (key === 'className' || key === 'classList') { |
49 | 51 | if (Array.isArray(valueOrObs)) { |
50 | 52 | valueOrObs.forEach(function (v) { |
51 | 53 | classList.add(v) |
@@ -53,9 +55,9 @@ | ||
53 | 55 | } else { |
54 | 56 | classList.add(valueOrObs) |
55 | 57 | } |
56 | 58 | } else { |
57 | - target[key] = value | |
59 | + target[key] = resolve(valueOrObs) | |
58 | 60 | var obs = isObservable(valueOrObs) ? valueOrObs : null |
59 | 61 | if (obs) { |
60 | 62 | data.bindings.push(new Binding(bind, target, obs, key)) |
61 | 63 | } |
Built with git-ssb-web