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

Remove run and computed dot access #19653

Merged
merged 1 commit into from Jul 21, 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
45 changes: 0 additions & 45 deletions lib/overrides.js
Expand Up @@ -4,7 +4,6 @@ const validSemverRange = require('semver/ranges/valid');

const DEFAULT_OPTIONS = Object.freeze({
showAllEmberGlobalDeprecations: false,
showAllDotAccessDeprecations: false,
});

function* walkAddonTree(project, pathToAddon = []) {
Expand Down Expand Up @@ -32,8 +31,6 @@ module.exports = class Overrides {
} else {
return new Overrides(Overrides.addonsInfoFor(project), {
showAllEmberGlobalDeprecations: env.EMBER_GLOBAL_DEPRECATIONS === 'all',
showAllDotAccessDeprecations:
env.EMBER_RUNLOOP_AND_COMPUTED_DOT_ACCESS_DEPRECATIONS === 'all',
});
}
}
Expand Down Expand Up @@ -216,10 +213,6 @@ module.exports = class Overrides {
return !this.hasActionableSuggestions || this.options.showAllEmberGlobalDeprecations;
}

get showAllDotAccessDeprecations() {
return !this.hasActionableSuggestions || this.options.showAllDotAccessDeprecations;
}

get details() {
let details =
'\n### Details ###\n\n' +
Expand Down Expand Up @@ -333,8 +326,6 @@ module.exports = class Overrides {
toModule() {
return `
export let onEmberGlobalAccess;
export let onComputedDotAccess;
export let onRunloopDotAccess;

${this.toJS()};
`;
Expand All @@ -358,17 +349,10 @@ module.exports = class Overrides {
${this.onDotAcces}

onEmberGlobalAccess = ${this.onEmberGlobalAccess};
onComputedDotAccess = onDotAccess;
onRunloopDotAccess = onDotAccess;

if (!${this.showAllEmberGlobalDeprecations}) {
onEmberGlobalAccess = once(onEmberGlobalAccess);
}

if (!${this.showAllDotAccessDeprecations}) {
onComputedDotAccess = once(onComputedDotAccess);
onRunloopDotAccess = once(onRunloopDotAccess);
}
`;
}

Expand All @@ -379,33 +363,4 @@ module.exports = class Overrides {
}
`;
}

get onDotAcces() {
return `
function onDotAccess(dotKey, importKey, module) {
let message =
'Using \`' + dotKey + '\` has been deprecated. Instead, import the value directly from ' + module + ':\\n\\n' +
' import { ' + importKey + ' } from \\'' + module + '\\';\\n\\n' +
'These usages may be caused by an outdated ember-cli-babel dependency. ' +
'Usages of the Ember Global may be caused by an outdated ember-cli-babel dependency. ' +
'The following steps may help:\\n\\n' +
${JSON.stringify(Overrides.printList(this.suggestions))};

if (!${this.showAllDotAccessDeprecations}) {
message +=
'\\n### Important ###\\n\\n' +
'In order to avoid repeatedly showing the same deprecation messages, ' +
'no further deprecation messages will be shown for theses deprecated usages ' +
'until ember-cli-babel is upgraded to v7.26.6 or above.\\n\\n' +
'To see all instances of this deprecation message, ' +
'set the \`EMBER_RUNLOOP_AND_COMPUTED_DOT_ACCESS_DEPRECATIONS\` environment variable to "all", ' +
'e.g. \`EMBER_RUNLOOP_AND_COMPUTED_DOT_ACCESS_DEPRECATIONS=all ember test\`.\\n';
}

message += ${JSON.stringify(this.details)};

return message;
}
`;
}
};
3 changes: 0 additions & 3 deletions packages/@ember/-internals/overrides/index.d.ts
Expand Up @@ -5,8 +5,5 @@ type Callback<TArgs extends unknown[], TReturn> = (...args: TArgs) => TReturn;
*/
type Handler<TArgs extends unknown[]> = Callback<TArgs, string | null>;
type GlobalAccessHandler = Handler<[]>;
type DotAccessHandler = Handler<[dotKey: string, importKey: string, module: string]>;

export let onEmberGlobalAccess: GlobalAccessHandler | undefined;
export let onComputedDotAccess: DotAccessHandler | undefined;
export let onRunloopDotAccess: DotAccessHandler | undefined;
2 changes: 0 additions & 2 deletions packages/@ember/-internals/overrides/index.js
@@ -1,3 +1 @@
export let onEmberGlobalAccess;
export let onComputedDotAccess;
export let onRunloopDotAccess;
Expand Up @@ -345,7 +345,9 @@ moduleFor(
assert.ok(get(SubClass.create(), 'foo'), 'FOO', 'super value is fetched');
}

['@test observing computed.reads prop and overriding it in create() works'](assert) {
['@test observing prop installed with computed macro reads and overriding it in create() works'](
assert
) {
let Obj = EmberObject.extend({
name: reads('model.name'),
nameDidChange: observer('name', function () {}),
Expand Down
134 changes: 1 addition & 133 deletions packages/@ember/object/index.js
@@ -1,7 +1,5 @@
import { DEBUG } from '@glimmer/env';
import { assert, deprecate } from '@ember/debug';
import { assert } from '@ember/debug';
import { isElementDescriptor, setClassicDecorator } from '@ember/-internals/metal';
import { onComputedDotAccess } from '@ember/-internals/overrides';

export { Object as default } from '@ember/-internals/runtime';

Expand All @@ -17,136 +15,6 @@ export {
trySet,
} from '@ember/-internals/metal';

import { computed } from '@ember/-internals/metal';

import {
alias,
and,
bool,
collect,
deprecatingAlias,
empty,
equal,
filterBy,
filter,
gte,
gt,
intersect,
lte,
lt,
mapBy,
map,
match,
max,
min,
none,
notEmpty,
not,
oneWay,
or,
readOnly,
setDiff,
sort,
sum,
union,
uniqBy,
uniq,
} from '@ember/object/computed';

// eslint-disable-next-line no-undef
if (DEBUG) {
let defaultHandler = (dotKey, importKey, module) => {
return `Using \`${dotKey}\` has been deprecated. Instead, import the value directly from ${module}:\n\n import { ${importKey} } from '${module}';`;
};

let handler = onComputedDotAccess || defaultHandler;

let defineDeprecatedComputedFunc = (key, func) => {
Object.defineProperty(computed, key, {
get() {
let message = handler(`computed.${key}`, key, '@ember/object/computed');

deprecate(message, message === null, {
id: 'deprecated-run-loop-and-computed-dot-access',
until: '4.0.0',
for: 'ember-source',
since: {
enabled: '3.27.0',
},
});

return func;
},
});
};

defineDeprecatedComputedFunc('alias', alias);
defineDeprecatedComputedFunc('and', and);
defineDeprecatedComputedFunc('bool', bool);
defineDeprecatedComputedFunc('collect', collect);
defineDeprecatedComputedFunc('deprecatingAlias', deprecatingAlias);
defineDeprecatedComputedFunc('empty', empty);
defineDeprecatedComputedFunc('equal', equal);
defineDeprecatedComputedFunc('filterBy', filterBy);
defineDeprecatedComputedFunc('filter', filter);
defineDeprecatedComputedFunc('gte', gte);
defineDeprecatedComputedFunc('gt', gt);
defineDeprecatedComputedFunc('intersect', intersect);
defineDeprecatedComputedFunc('lte', lte);
defineDeprecatedComputedFunc('lt', lt);
defineDeprecatedComputedFunc('mapBy', mapBy);
defineDeprecatedComputedFunc('map', map);
defineDeprecatedComputedFunc('match', match);
defineDeprecatedComputedFunc('max', max);
defineDeprecatedComputedFunc('min', min);
defineDeprecatedComputedFunc('none', none);
defineDeprecatedComputedFunc('notEmpty', notEmpty);
defineDeprecatedComputedFunc('not', not);
defineDeprecatedComputedFunc('oneWay', oneWay);
defineDeprecatedComputedFunc('reads', oneWay);
defineDeprecatedComputedFunc('or', or);
defineDeprecatedComputedFunc('readOnly', readOnly);
defineDeprecatedComputedFunc('setDiff', setDiff);
defineDeprecatedComputedFunc('sort', sort);
defineDeprecatedComputedFunc('sum', sum);
defineDeprecatedComputedFunc('union', union);
defineDeprecatedComputedFunc('uniqBy', uniqBy);
defineDeprecatedComputedFunc('uniq', uniq);
} else {
computed.alias = alias;
computed.and = and;
computed.bool = bool;
computed.collect = collect;
computed.deprecatingAlias = deprecatingAlias;
computed.empty = empty;
computed.equal = equal;
computed.filterBy = filterBy;
computed.filter = filter;
computed.gte = gte;
computed.gt = gt;
computed.intersect = intersect;
computed.lte = lte;
computed.lt = lt;
computed.mapBy = mapBy;
computed.map = map;
computed.match = match;
computed.max = max;
computed.min = min;
computed.none = none;
computed.notEmpty = notEmpty;
computed.not = not;
computed.oneWay = oneWay;
computed.reads = oneWay;
computed.or = or;
computed.readOnly = readOnly;
computed.setDiff = setDiff;
computed.sort = sort;
computed.sum = sum;
computed.union = union;
computed.uniqBy = uniqBy;
computed.uniq = uniq;
}

/**
Decorator that turns the target function into an Action which can be accessed
directly by reference.
Expand Down
23 changes: 12 additions & 11 deletions packages/@ember/object/lib/computed/computed_macros.js
Expand Up @@ -24,7 +24,7 @@ function expandPropertiesToArray(predicateName, properties) {
for (let i = 0; i < properties.length; i++) {
let property = properties[i];
assert(
`Dependent keys passed to computed.${predicateName}() can't have spaces.`,
`Dependent keys passed to \`${predicateName}\` computed macro can't have spaces.`,
property.indexOf(' ') < 0
);

Expand Down Expand Up @@ -988,11 +988,11 @@ export const or = generateComputedWithPredicate('or', (value) => !value);
*/

/**
Where `computed.alias` aliases `get` and `set`, and allows for bidirectional
data flow, `computed.oneWay` only provides an aliased `get`. The `set` will
not mutate the upstream property, rather causes the current property to become
the value set. This causes the downstream property to permanently diverge from
the upstream property.
Where the `alias` computed macro aliases `get` and `set`, and allows for
bidirectional data flow, the `oneWay` computed macro only provides an aliased
`get`. The `set` will not mutate the upstream property, rather causes the
current property to become the value set. This causes the downstream property
to permanently diverge from the upstream property.
Example:
Expand Down Expand Up @@ -1061,8 +1061,8 @@ export function oneWay(dependentKey) {
}

/**
This is a more semantically meaningful alias of `computed.oneWay`, whose name
is somewhat ambiguous as to which direction the data flows.
This is a more semantically meaningful alias of the `oneWay` computed macro,
whose name is somewhat ambiguous as to which direction the data flows.
@method reads
@static
Expand All @@ -1074,9 +1074,10 @@ export function oneWay(dependentKey) {
*/

/**
Where `computed.oneWay` provides oneWay bindings, `computed.readOnly` provides
a readOnly one way binding. Very often when using `computed.oneWay` one does
not also want changes to propagate back up, as they will replace the value.
Where `oneWay` computed macro provides oneWay bindings, the `readOnly`
computed macro provides a readOnly one way binding. Very often when using
the `oneWay` macro one does not also want changes to propagate back up, as
they will replace the value.
This prevents the reverse flow, and also throws an exception when it occurs.
Expand Down
18 changes: 9 additions & 9 deletions packages/@ember/object/lib/computed/reduce_computed_macros.js
Expand Up @@ -8,7 +8,7 @@ import { compare, isArray, A as emberA, uniqBy as uniqByArray } from '@ember/-in

function reduceMacro(dependentKey, callback, initialValue, name) {
assert(
`Dependent key passed to \`computed.${name}\` shouldn't contain brace expanding pattern.`,
`Dependent key passed to \`${name}\` computed macro shouldn't contain brace expanding pattern.`,
!/[[\]{}]/g.test(dependentKey)
);

Expand Down Expand Up @@ -43,7 +43,7 @@ function arrayMacro(dependentKey, additionalDependentKeys, callback) {

function multiArrayMacro(_dependentKeys, callback, name) {
assert(
`Dependent keys passed to \`computed.${name}\` shouldn't contain brace expanding pattern.`,
`Dependent keys passed to \`${name}\` computed macro shouldn't contain brace expanding pattern.`,
_dependentKeys.every((dependentKey) => !/[[\]{}]/g.test(dependentKey))
);
let dependentKeys = _dependentKeys.map((key) => `${key}.[]`);
Expand Down Expand Up @@ -516,12 +516,12 @@ export function mapBy(dependentKey, propertyKey) {
);

assert(
'`computed.mapBy` expects a property string for its second argument, ' +
'`mapBy` computed macro expects a property string for its second argument, ' +
'perhaps you meant to use "map"',
typeof propertyKey === 'string'
);
assert(
`Dependent key passed to \`computed.mapBy\` shouldn't contain brace expanding pattern.`,
`Dependent key passed to \`mapBy\` computed macro shouldn't contain brace expanding pattern.`,
!/[[\]{}]/g.test(dependentKey)
);

Expand Down Expand Up @@ -745,7 +745,7 @@ export function filterBy(dependentKey, propertyKey, value) {
);

assert(
`Dependent key passed to \`computed.filterBy\` shouldn't contain brace expanding pattern.`,
`Dependent key passed to \`filterBy\` computed macro shouldn't contain brace expanding pattern.`,
!/[[\]{}]/g.test(dependentKey)
);

Expand Down Expand Up @@ -913,7 +913,7 @@ export function uniqBy(dependentKey, propertyKey) {
);

assert(
`Dependent key passed to \`computed.uniqBy\` shouldn't contain brace expanding pattern.`,
`Dependent key passed to \`uniqBy\` computed macro shouldn't contain brace expanding pattern.`,
!/[[\]{}]/g.test(dependentKey)
);

Expand Down Expand Up @@ -1164,9 +1164,9 @@ export function setDiff(setAProperty, setBProperty) {
!isElementDescriptor(Array.prototype.slice.call(arguments))
);

assert('`computed.setDiff` requires exactly two dependent arrays.', arguments.length === 2);
assert('`setDiff` computed macro requires exactly two dependent arrays.', arguments.length === 2);
assert(
`Dependent keys passed to \`computed.setDiff\` shouldn't contain brace expanding pattern.`,
`Dependent keys passed to \`setDiff\` computed macro shouldn't contain brace expanding pattern.`,
!/[[\]{}]/g.test(setAProperty) && !/[[\]{}]/g.test(setBProperty)
);

Expand Down Expand Up @@ -1448,7 +1448,7 @@ export function sort(itemsKey, additionalDependentKeys, sortDefinition) {
}

assert(
'`computed.sort` can either be used with an array of sort properties or with a sort function. If used with an array of sort properties, it must receive exactly two arguments: the key of the array to sort, and the key of the array of sort properties. If used with a sort function, it may receive up to three arguments: the key of the array to sort, an optional additional array of dependent keys for the computed property, and the sort function.',
'The `sort` computed macro can either be used with an array of sort properties or with a sort function. If used with an array of sort properties, it must receive exactly two arguments: the key of the array to sort, and the key of the array of sort properties. If used with a sort function, it may receive up to three arguments: the key of the array to sort, an optional additional array of dependent keys for the computed property, and the sort function.',
argumentsValid
);
}
Expand Down