Skip to content

Commit cfc6f8b

Browse files
committed
context extraction
1 parent 375b861 commit cfc6f8b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/dom.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const walkerFilter = NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT;
1414

1515
const bindMap = new WeakMap();
1616

17+
const extract = (ctx) => (typeof ctx === 'function' ? ctx() : ctx);
18+
1719
export function createBind(source, target, property, execution) {
1820
let propToTarget = bindMap.get(source) || bindMap.set(source, {}).get(source);
1921
if (!propToTarget[property]) {
@@ -150,9 +152,9 @@ export function processDOM(scope, dom) {
150152
const fn = directive.noExecution
151153
? NOOP
152154
: createFunction('item', `return ${userCode}`);
153-
const update = (altContext = context) => {
155+
const update = (altContext = context()) => {
154156
try {
155-
const value = fn.call(scope, altContext);
157+
const value = fn.call(scope, extract(altContext));
156158
invocation(value, isForcedUpdate(scope));
157159
} catch (err) {
158160
console.warn(err);

0 commit comments

Comments
 (0)