Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Make modifier manager 3.22 accept the resolved value directly. #19170

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/@ember/-internals/glimmer/lib/modifiers/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface OptionalCapabilities {
disableAutoTracking?: boolean;
};

// passes factoryFor(...).class to `.createModifier`
// uses args proxy, does not provide a way to opt-out
'3.22': {
disableAutoTracking?: boolean;
Expand All @@ -27,6 +28,7 @@ export interface OptionalCapabilities {
export interface Capabilities {
disableAutoTracking: boolean;
useArgsProxy: boolean;
passFactoryToCreate: boolean;
}

export function capabilities<Version extends keyof OptionalCapabilities>(
Expand All @@ -41,6 +43,7 @@ export function capabilities<Version extends keyof OptionalCapabilities>(
return {
disableAutoTracking: Boolean(optionalFeatures.disableAutoTracking),
useArgsProxy: managerAPI === '3.13' ? false : true,
passFactoryToCreate: managerAPI === '3.13',
};
}

Expand Down Expand Up @@ -126,10 +129,13 @@ class InteractiveCustomModifierManager<ModifierInstance>
typeof delegate.capabilities === 'object' && delegate.capabilities !== null
);

let useArgsProxy = delegate.capabilities.useArgsProxy;
let { useArgsProxy, passFactoryToCreate } = delegate.capabilities;

let args = useArgsProxy ? argsProxyFor(capturedArgs, 'modifier') : reifyArgs(capturedArgs);
let instance = delegate.createModifier(ModifierClass, args);
let instance = delegate.createModifier(
passFactoryToCreate ? ModifierClass : ModifierClass.class,
args
);

let tag = createUpdatableTag();
let state: CustomModifierState<ModifierInstance>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,6 @@ import { setModifierManager, modifierCapabilities } from '@ember/-internals/glim
import { set, tracked } from '@ember/-internals/metal';
import { backtrackingMessageFor } from '../utils/backtracking-rerender';

class CustomModifierManager {
constructor(owner) {
this.owner = owner;
}

createModifier(factory, args) {
return factory.create(args);
}

installModifier(instance, element, args) {
instance.element = element;
let { positional, named } = args;
instance.didInsertElement(positional, named);
}

updateModifier(instance, args) {
let { positional, named } = args;
instance.didUpdate(positional, named);
}

destroyModifier(instance) {
instance.willDestroyElement();
}
}
class ModifierManagerTest extends RenderingTestCase {
'@test throws a useful error when missing capabilities'() {
this.registerModifier(
Expand Down Expand Up @@ -295,8 +271,32 @@ class ModifierManagerTest extends RenderingTestCase {
moduleFor(
'Basic Custom Modifier Manager: 3.13',
class extends ModifierManagerTest {
CustomModifierManager = class extends CustomModifierManager {
CustomModifierManager = class CustomModifierManager {
capabilities = modifierCapabilities('3.13');

constructor(owner) {
this.owner = owner;
}

createModifier(factory, args) {
// factory is the owner.factoryFor result
return factory.create(args);
}

installModifier(instance, element, args) {
instance.element = element;
let { positional, named } = args;
instance.didInsertElement(positional, named);
}

updateModifier(instance, args) {
let { positional, named } = args;
instance.didUpdate(positional, named);
}

destroyModifier(instance) {
instance.willDestroyElement();
}
};

'@test modifers consume all arguments'(assert) {
Expand Down Expand Up @@ -355,8 +355,31 @@ moduleFor(
moduleFor(
'Basic Custom Modifier Manager: 3.22',
class extends ModifierManagerTest {
CustomModifierManager = class extends CustomModifierManager {
CustomModifierManager = class CustomModifierManager {
capabilities = modifierCapabilities('3.22');

constructor(owner) {
this.owner = owner;
}

createModifier(Modifier, args) {
return Modifier.create(args);
}

installModifier(instance, element, args) {
instance.element = element;
let { positional, named } = args;
instance.didInsertElement(positional, named);
}

updateModifier(instance, args) {
let { positional, named } = args;
instance.didUpdate(positional, named);
}

destroyModifier(instance) {
instance.willDestroyElement();
}
};

'@test modifers only track positional arguments they consume'(assert) {
Expand Down Expand Up @@ -475,7 +498,89 @@ moduleFor(
return { isInteractive: false };
}

[`@test doesn't trigger lifecycle hooks when non-interactive`](assert) {
[`@test doesn't trigger lifecycle hooks when non-interactive: modifierCapabilities('3.13')`](
assert
) {
class CustomModifierManager {
capabilities = modifierCapabilities('3.13');

constructor(owner) {
this.owner = owner;
}

createModifier(factory, args) {
return factory.create(args);
}

installModifier(instance, element, args) {
instance.element = element;
let { positional, named } = args;
instance.didInsertElement(positional, named);
}

updateModifier(instance, args) {
let { positional, named } = args;
instance.didUpdate(positional, named);
}

destroyModifier(instance) {
instance.willDestroyElement();
}
}
let ModifierClass = setModifierManager(
owner => {
return new CustomModifierManager(owner);
},
EmberObject.extend({
didInsertElement() {
assert.ok(false);
},
didUpdate() {
assert.ok(false);
},
willDestroyElement() {
assert.ok(false);
},
})
);

this.registerModifier('foo-bar', ModifierClass);

this.render('<h1 {{foo-bar baz}}>hello world</h1>');
runTask(() => this.context.set('baz', 'Hello'));

this.assertHTML('<h1>hello world</h1>');
}

[`@test doesn't trigger lifecycle hooks when non-interactive: modifierCapabilities('3.22')`](
assert
) {
class CustomModifierManager {
capabilities = modifierCapabilities('3.22');

constructor(owner) {
this.owner = owner;
}

createModifier(Modifier, args) {
return Modifier.create(args);
}

installModifier(instance, element, args) {
instance.element = element;
let { positional, named } = args;
instance.didInsertElement(positional, named);
}

updateModifier(instance, args) {
let { positional, named } = args;
instance.didUpdate(positional, named);
}

destroyModifier(instance) {
instance.willDestroyElement();
}
}
let ModifierClass = setModifierManager(
owner => {
return new CustomModifierManager(owner);
Expand Down