Skip to content

Commit

Permalink
Merge pull request #1276 from glimmerjs/bugfix/do-not-eagerly-consume…
Browse files Browse the repository at this point in the history
…-args-during-destruction
  • Loading branch information
rwjblue authored Mar 16, 2021
2 parents f80fc66 + a6dc74b commit 3e966bf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,52 @@ abstract class ModifierManagerTest extends RenderTest {
/You attempted to update `foo` on `.*`, but it had already been used previously in the same computation/
);
}

@test
'does not eagerly access arguments during destruction'(assert: Assert) {
class Foo extends CustomModifier {}

let foo = this.defineModifier(Foo);

let Main = defineComponent(
{ foo },
'{{#if @state.show}}<h1 {{foo @state.bar [email protected]}}>hello world</h1>{{/if}}'
);

let barCount = 0;
let bazCount = 0;

class State {
@tracked show = true;

get bar() {
if (this.show === false) {
barCount++;
}

return;
}

get baz() {
if (this.show === false) {
bazCount++;
}

return;
}
}

let state = new State();

this.renderComponent(Main, { state });

state.show = false;

this.rerender();

assert.equal(barCount, 0, 'bar was not accessed during detruction');
assert.equal(bazCount, 0, 'baz was not accessed during detruction');
}
}

class ModifierManagerTest313 extends ModifierManagerTest {
Expand Down
5 changes: 3 additions & 2 deletions packages/@glimmer/manager/lib/public/modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export class CustomModifierManager<O extends Owner, ModifierInstance>

let { useArgsProxy, passFactoryToCreate } = delegate.capabilities;

let args = useArgsProxy ? argsProxyFor(capturedArgs, 'modifier') : reifyArgs(capturedArgs);
let argsProxy = argsProxyFor(capturedArgs, 'modifier');
let args = useArgsProxy ? argsProxy : reifyArgs(capturedArgs);

let instance: ModifierInstance;

Expand Down Expand Up @@ -168,7 +169,7 @@ export class CustomModifierManager<O extends Owner, ModifierInstance>
state.debugName = typeof definition === 'function' ? definition.name : definition.toString();
}

registerDestructor(state, () => delegate.destroyModifier(instance, state.args));
registerDestructor(state, () => delegate.destroyModifier(instance, argsProxy));

return state;
}
Expand Down

0 comments on commit 3e966bf

Please sign in to comment.