mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-16 18:39:18 +08:00
19 lines
739 B
JavaScript
19 lines
739 B
JavaScript
function linkState(component, key, eventPath) {
|
|
let path = key.split('.'), cache = component.__lsc || (component.__lsc = {});
|
|
|
|
return cache[key + eventPath] || (cache[key + eventPath] = function(e) {
|
|
let t = e && e.target || this, state = {}, obj = state,
|
|
v = typeof eventPath === 'string' ?
|
|
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]] || {});
|
|
}
|
|
obj[path[i]] = v;
|
|
component.setState(state);
|
|
});
|
|
}
|