Skip to content

Commit

Permalink
Remove run and computed dot access
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jul 18, 2021
1 parent 9149433 commit 975b18d
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 374 deletions.
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

0 comments on commit 975b18d

Please sign in to comment.