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

Removes deprecated Private INVOKE API #19639

Merged
merged 2 commits into from Jul 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/@ember/-internals/glimmer/index.ts
Expand Up @@ -388,7 +388,6 @@ export { DOMChanges, NodeDOMTreeConstruction, DOMTreeConstruction } from './lib/
// TODO just test these through public API
// a lot of these are testing how a problem was solved
// rather than the problem was solved
export { INVOKE } from './lib/helpers/action';
export { default as OutletView } from './lib/views/outlet';
export { OutletState } from './lib/utils/outlet';
export {
Expand Down
68 changes: 21 additions & 47 deletions packages/@ember/-internals/glimmer/lib/helpers/action.ts
Expand Up @@ -2,8 +2,7 @@
@module ember
*/
import { get } from '@ember/-internals/metal';
import { symbol } from '@ember/-internals/utils';
import { assert, deprecate } from '@ember/debug';
import { assert } from '@ember/debug';
import { flaggedInstrument } from '@ember/instrumentation';
import { join } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';
Expand All @@ -19,7 +18,6 @@ import { _WeakSet } from '@glimmer/util';
import { internalHelper } from './internal-helper';

export const ACTIONS = new _WeakSet();
export const INVOKE: unique symbol = symbol('INVOKE') as any;

/**
The `{{action}}` helper provides a way to pass triggers for behavior (usually
Expand Down Expand Up @@ -363,7 +361,7 @@ function makeArgsProcessor(valuePathRef: Reference | false, actionArgsRef: Refer
function makeDynamicClosureAction(
context: object,
targetRef: Reference<MaybeActionHandler>,
actionRef: Reference<string | Function | Invokable>,
actionRef: Reference<string | Function>,
processArgs: (args: unknown[]) => unknown[],
debugKey: string
) {
Expand Down Expand Up @@ -393,14 +391,10 @@ interface MaybeActionHandler {
actions?: Record<string, Function>;
}

interface Invokable {
[INVOKE]: Function;
}

function makeClosureAction(
context: object,
target: MaybeActionHandler,
action: string | Function | Invokable,
action: string | Function,
processArgs: (args: unknown[]) => unknown[],
debugKey: string
) {
Expand All @@ -412,46 +406,26 @@ function makeClosureAction(
action !== undefined && action !== null
);

if (typeof action[INVOKE] === 'function') {
deprecate(
`Usage of the private INVOKE API to make an object callable via action or fn is no longer supported. Please update to pass in a callback function instead. Received: ${String(
action
)}`,
false,
{
until: '3.25.0',
id: 'actions.custom-invoke-invokable',
for: 'ember-source',
since: {
enabled: '3.23.0-beta.1',
},
}
);

self = action as Invokable;
fn = action[INVOKE];
} else {
let typeofAction = typeof action;
let typeofAction = typeof action;

if (typeofAction === 'string') {
self = target;
fn = target.actions! && target.actions![action as string];
if (typeofAction === 'string') {
self = target;
fn = target.actions! && target.actions![action as string];

assert(`An action named '${action}' was not found in ${target}`, Boolean(fn));
} else if (typeofAction === 'function') {
self = context;
fn = action as Function;
} else {
// tslint:disable-next-line:max-line-length
assert(
`An action could not be made for \`${
debugKey || action
}\` in ${target}. Please confirm that you are using either a quoted action name (i.e. \`(action '${
debugKey || 'myAction'
}')\`) or a function available in ${target}.`,
false
);
}
assert(`An action named '${action}' was not found in ${target}`, Boolean(fn));
} else if (typeofAction === 'function') {
self = context;
fn = action as Function;
} else {
// tslint:disable-next-line:max-line-length
assert(
`An action could not be made for \`${
debugKey || action
}\` in ${target}. Please confirm that you are using either a quoted action name (i.e. \`(action '${
debugKey || 'myAction'
}')\`) or a function available in ${target}.`,
false
);
}

return (...args: any[]) => {
Expand Down
22 changes: 0 additions & 22 deletions packages/@ember/-internals/glimmer/lib/modifiers/action.ts
Expand Up @@ -16,7 +16,6 @@ import { setInternalModifierManager } from '@glimmer/manager';
import { isInvokableRef, updateRef, valueForRef } from '@glimmer/reference';
import { createUpdatableTag, UpdatableTag } from '@glimmer/validator';
import { SimpleElement } from '@simple-dom/interface';
import { INVOKE } from '../helpers/action';

const MODIFIERS = ['alt', 'shift', 'meta', 'ctrl'];
const POINTER_EVENT_TYPE_REGEX = /^click|mouse|touch/;
Expand Down Expand Up @@ -148,27 +147,6 @@ export class ActionState {
target,
name: null,
};
if (typeof actionName[INVOKE] === 'function') {
deprecate(
`Usage of the private INVOKE API to make an object callable via action or fn is no longer supported. Please update to pass in a callback function instead. Received: ${String(
actionName
)}`,
false,
{
until: '3.25.0',
id: 'actions.custom-invoke-invokable',
for: 'ember-source',
since: {
enabled: '3.23.0-beta.1',
},
}
);

flaggedInstrument('interaction.ember-action', payload, () => {
actionName[INVOKE].apply(actionName, args);
});
return;
}
if (isInvokableRef(actionName)) {
flaggedInstrument('interaction.ember-action', payload, () => {
updateRef(actionName, args[0]);
Expand Down
Expand Up @@ -8,7 +8,7 @@ import { _getCurrentRunLoop } from '@ember/runloop';
import { set, computed } from '@ember/-internals/metal';
import { EMBER_IMPROVED_INSTRUMENTATION } from '@ember/canary-features';

import { Component, INVOKE } from '../../utils/helpers';
import { Component } from '../../utils/helpers';

if (EMBER_IMPROVED_INSTRUMENTATION) {
moduleFor(
Expand Down Expand Up @@ -1043,56 +1043,6 @@ moduleFor(
this.assert.ok(capturedRunLoop, 'action is called within a run loop');
}

// TODO: This is for intimate APIs, specifically ember-concurrency
['@test objects that define INVOKE can be casted to actions']() {
expectDeprecation(() => {
let innerComponent;
let actionArgs;
let invokableArgs;

let InnerComponent = Component.extend({
init() {
this._super(...arguments);
innerComponent = this;
},
fireAction() {
actionArgs = this.attrs.submit(4, 5, 6);
},
});

let OuterComponent = Component.extend({
foo: 123,
submitTask: computed(function () {
return {
[INVOKE]: (...args) => {
invokableArgs = args;
return this.foo;
},
};
}),
});

this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner',
});

this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: `{{inner-component submit=(action this.submitTask 1 2 3)}}`,
});

this.render('{{outer-component}}');

runTask(() => {
innerComponent.fireAction();
});

this.assert.equal(actionArgs, 123);
this.assert.deepEqual(invokableArgs, [1, 2, 3, 4, 5, 6]);
}, /Usage of the private INVOKE API to make an object callable/);
}

['@test closure action with `(mut undefinedThing)` works properly [GH#13959]']() {
let component;

Expand Down
1 change: 0 additions & 1 deletion packages/@ember/-internals/glimmer/tests/utils/helpers.js
Expand Up @@ -2,7 +2,6 @@ export { precompile } from 'ember-template-compiler';
export { compile } from 'internal-test-helpers';

export {
INVOKE,
Helper,
helper,
Component,
Expand Down