diff options
Diffstat (limited to 'thirdparty/preact/src/linked-state.js')
-rw-r--r-- | thirdparty/preact/src/linked-state.js | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/thirdparty/preact/src/linked-state.js b/thirdparty/preact/src/linked-state.js index ed72bd8bc..b6959df73 100644 --- a/thirdparty/preact/src/linked-state.js +++ b/thirdparty/preact/src/linked-state.js @@ -8,21 +8,17 @@ import { isString, delve } from './util'; * @private */ export function createLinkedState(component, key, eventPath) { - let path = key.split('.'), - p0 = path[0]; + let path = key.split('.'); return function(e) { - let t = e && e.currentTarget || this, - s = component.state, - obj = s, - v = isString(eventPath) ? delve(e, eventPath) : t.nodeName ? ((t.nodeName+t.type).match(/^input(che|rad)/i) ? t.checked : t.value) : e, - i; - if (path.length>1) { - for (i=0; i<path.length-1; i++) { - obj = obj[path[i]] || (obj[path[i]] = {}); - } - obj[path[i]] = v; - v = s[p0]; + let t = e && e.target || this, + state = {}, + obj = state, + v = isString(eventPath) ? delve(e, eventPath) : t.nodeName ? (t.type.match(/^che|rad/) ? t.checked : t.value) : e, + i = 0; + for ( ; i<path.length-1; i++) { + obj = obj[path[i]] || (obj[path[i]] = !i && component.state[path[i]] || {}); } - component.setState({ [p0]: v }); + obj[path[i]] = v; + component.setState(state); }; } |