Skip to content

Commit

Permalink
Merge pull request #1334 from nlfurniss/cleanup-modifier-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Sep 22, 2021
2 parents 2dc926f + f062098 commit 9408799
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 61 deletions.
7 changes: 0 additions & 7 deletions packages/@glimmer/interfaces/lib/managers/modifier.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { SimpleElement } from '@simple-dom/interface';
import { Arguments } from '../runtime';
import { Capabilities } from './capabilities';

export interface ModifierCapabilitiesVersions {
'3.13': {
disableAutoTracking?: boolean;
};

// passes factoryFor(...).class to `.createModifier`
// uses args proxy, does not provide a way to opt-out
'3.22': {
Expand All @@ -16,8 +11,6 @@ export interface ModifierCapabilitiesVersions {

export interface ModifierCapabilities extends Capabilities {
disableAutoTracking: boolean;
useArgsProxy: boolean;
passFactoryToCreate: boolean;
}

export interface ModifierManager<ModifierStateBucket> {
Expand Down
65 changes: 11 additions & 54 deletions packages/@glimmer/manager/lib/public/modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
Owner,
} from '@glimmer/interfaces';
import { registerDestructor } from '@glimmer/destroyable';
import { setOwner } from '@glimmer/owner';
import { valueForRef } from '@glimmer/reference';
import { assign, castToBrowser, dict } from '@glimmer/util';
import { castToBrowser, dict } from '@glimmer/util';
import { createUpdatableTag, untrack, UpdatableTag } from '@glimmer/validator';
import { SimpleElement } from '@simple-dom/interface';
import { buildCapabilities, FROM_CAPABILITIES } from '../util/capabilities';
Expand All @@ -28,11 +27,6 @@ export function modifierCapabilities<Version extends keyof ModifierCapabilitiesV

return buildCapabilities({
disableAutoTracking: Boolean(optionalFeatures.disableAutoTracking),
useArgsProxy: true,

// This capability is used in Ember, exclusively in resolution mode. See the
// Ember glimmer resolver for details.
passFactoryToCreate: false,
});
}

Expand All @@ -45,10 +39,6 @@ export interface CustomModifierState<ModifierInstance> {
debugName?: string;
}

interface Factory {
create(params: Record<string, unknown>): object;
}

/**
The CustomModifierManager allows addons to provide custom modifier
implementations that integrate seamlessly into Ember. This is accomplished
Expand Down Expand Up @@ -105,58 +95,25 @@ export class CustomModifierManager<O extends Owner, ModifierInstance>
create(owner: O, element: SimpleElement, definition: object, capturedArgs: CapturedArguments) {
let delegate = this.getDelegateFor(owner);

let { useArgsProxy, passFactoryToCreate } = delegate.capabilities;

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

let factoryOrDefinition = definition;

if (passFactoryToCreate) {
// Make a fake factory. While not perfect, this should generally prevent
// breakage in users of older modifier capabilities.
factoryOrDefinition = {
create(args: Record<string, unknown>) {
let params = assign({}, args);
setOwner(params, owner);

return (definition as Factory).create(args);
},

class: definition,
};
}

let instance: ModifierInstance = delegate.createModifier(factoryOrDefinition, args);
let args = argsProxyFor(capturedArgs, 'modifier');
let instance: ModifierInstance = delegate.createModifier(definition, args);

let tag = createUpdatableTag();
let state: CustomModifierState<ModifierInstance>;

if (useArgsProxy) {
state = {
tag,
element,
delegate,
args,
modifier: instance!,
};
} else {
state = {
tag,
element,
modifier: instance!,
delegate,
get args() {
return reifyArgs(capturedArgs);
},
};
}
state = {
tag,
element,
delegate,
args,
modifier: instance!,
};

if (DEBUG) {
state.debugName = typeof definition === 'function' ? definition.name : definition.toString();
}

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

return state;
}
Expand Down

0 comments on commit 9408799

Please sign in to comment.