Skip to content

Commit 07d7d0d

Browse files
committed
Deprecate methods with placeholder messages
1 parent 2fe9ba3 commit 07d7d0d

File tree

15 files changed

+234
-83
lines changed

15 files changed

+234
-83
lines changed

packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -956,35 +956,35 @@ moduleFor(
956956
}
957957
);
958958

959-
assert.ok(!isEmpty(instance), 'a instance was created');
959+
assert.ok(instance, 'the component instance exinstance was created');
960960
assert.equal(previousInstance, undefined, 'no previous component exists');
961961
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
962962
assert.equal(this.$().text(), 'open', 'the components text is "open"');
963963

964964
runTask(() => this.rerender());
965965

966-
assert.ok(!isEmpty(instance), 'the component instance exists');
966+
assert.ok(instance, 'the component instance exists');
967967
assert.equal(previousInstance, undefined, 'no previous component exists');
968968
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
969969
assert.equal(this.$().text(), 'open', 'the components text is "open"');
970970

971971
runTask(() => this.context.set('isOpen', false));
972972

973-
assert.ok(!isEmpty(instance), 'the component instance exists');
973+
assert.ok(instance, 'the component instance exists');
974974
assert.equal(previousInstance, undefined, 'no previous component exists');
975975
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
976976
assert.equal(this.$().text(), 'closed', 'the component text is "closed"');
977977

978978
runTask(() => this.rerender());
979979

980-
assert.ok(!isEmpty(instance), 'the component instance exists');
980+
assert.ok(instance, 'the component instance exists');
981981
assert.equal(previousInstance, undefined, 'no previous component exists');
982982
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
983983
assert.equal(this.$().text(), 'closed', 'the component text is "closed"');
984984

985985
runTask(() => this.context.set('isOpen', true));
986986

987-
assert.ok(!isEmpty(instance), 'the component instance exists');
987+
assert.ok(instance, 'the component instance exists');
988988
assert.equal(previousInstance, undefined, 'no previous component exists');
989989
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
990990
assert.equal(this.$().text(), 'open', 'the components text is "open"');
@@ -1021,35 +1021,35 @@ moduleFor(
10211021
}
10221022
);
10231023

1024-
assert.ok(!isEmpty(instance), 'a instance was created');
1024+
assert.ok(instance, 'a instance was created');
10251025
assert.equal(previousInstance, undefined, 'no previous component exists');
10261026
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
10271027
assert.equal(this.$().text(), 'open', 'the components text is "open"');
10281028

10291029
runTask(() => this.rerender());
10301030

1031-
assert.ok(!isEmpty(instance), 'the component instance exists');
1031+
assert.ok(instance, 'the component instance exists');
10321032
assert.equal(previousInstance, undefined, 'no previous component exists');
10331033
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
10341034
assert.equal(this.$().text(), 'open', 'the components text is "open"');
10351035

10361036
runTask(() => this.context.set('isOpen', false));
10371037

1038-
assert.ok(!isEmpty(instance), 'the component instance exists');
1038+
assert.ok(instance, 'the component instance exists');
10391039
assert.equal(previousInstance, undefined, 'no previous component exists');
10401040
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
10411041
assert.equal(this.$().text(), 'closed', 'the component text is "closed"');
10421042

10431043
runTask(() => this.rerender());
10441044

1045-
assert.ok(!isEmpty(instance), 'the component instance exists');
1045+
assert.ok(instance, 'the component instance exists');
10461046
assert.equal(previousInstance, undefined, 'no previous component exists');
10471047
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
10481048
assert.equal(this.$().text(), 'closed', 'the component text is "closed"');
10491049

10501050
runTask(() => this.context.set('isOpen', true));
10511051

1052-
assert.ok(!isEmpty(instance), 'the component instance exists');
1052+
assert.ok(instance, 'the component instance exists');
10531053
assert.equal(previousInstance, undefined, 'no previous component exists');
10541054
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
10551055
assert.equal(this.$().text(), 'open', 'the components text is "open"');
@@ -1099,22 +1099,22 @@ moduleFor(
10991099
}
11001100
);
11011101

1102-
assert.ok(!isEmpty(instance), 'a instance was created');
1102+
assert.ok(instance, 'a instance was created');
11031103
assert.equal(previousInstance, undefined, 'there is no previous instance');
11041104
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
11051105
assert.equal(this.$().text(), 'my-comp: open');
11061106

11071107
runTask(() => this.rerender());
11081108

1109-
assert.ok(!isEmpty(instance), 'a instance exists after rerender');
1109+
assert.ok(instance, 'a instance exists after rerender');
11101110
assert.equal(previousInstance, undefined, 'there is no previous instance after rerender');
11111111
assert.equal(initCount, 1, 'the component was constructed exactly 1 time');
11121112
assert.equal(this.$().text(), 'my-comp: open');
11131113

11141114
runTask(() => this.context.set('compName', 'your-comp'));
11151115

1116-
assert.ok(!isEmpty(instance), 'an instance was created after component name changed');
1117-
assert.ok(!isEmpty(previousInstance), 'a previous instance now exists');
1116+
assert.ok(instance, 'an instance was created after component name changed');
1117+
assert.ok(previousInstance, 'a previous instance now exists');
11181118
assert.notEqual(
11191119
instance,
11201120
previousInstance,
@@ -1125,11 +1125,8 @@ moduleFor(
11251125

11261126
runTask(() => this.rerender());
11271127

1128-
assert.ok(
1129-
!isEmpty(instance),
1130-
'an instance was created after component name changed (rerender)'
1131-
);
1132-
assert.ok(!isEmpty(previousInstance), 'a previous instance now exists (rerender)');
1128+
assert.ok(instance, 'an instance was created after component name changed (rerender)');
1129+
assert.ok(previousInstance, 'a previous instance now exists (rerender)');
11331130
assert.notEqual(
11341131
instance,
11351132
previousInstance,
@@ -1140,8 +1137,8 @@ moduleFor(
11401137

11411138
runTask(() => this.context.set('compName', 'my-comp'));
11421139

1143-
assert.ok(!isEmpty(instance), 'an instance was created after component name changed');
1144-
assert.ok(!isEmpty(previousInstance), 'a previous instance still exists');
1140+
assert.ok(instance, 'an instance was created after component name changed');
1141+
assert.ok(previousInstance, 'a previous instance still exists');
11451142
assert.notEqual(
11461143
instance,
11471144
previousInstance,

packages/@ember/-internals/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ export {
3333
teardownMandatorySetter,
3434
setWithMandatorySetter,
3535
} from './lib/mandatory-setter';
36+
export type { TypeName } from './lib/type-of';
37+
export { default as typeOf } from './lib/type-of';
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// import CoreObject from '@ember/object/core';
2+
3+
export type TypeName =
4+
| 'undefined'
5+
| 'null'
6+
| 'string'
7+
| 'number'
8+
| 'boolean'
9+
| 'function'
10+
| 'array'
11+
| 'regexp'
12+
| 'date'
13+
| 'filelist'
14+
| 'class'
15+
| 'instance'
16+
| 'error'
17+
| 'object';
18+
19+
// ........................................
20+
// TYPING & ARRAY MESSAGING
21+
//
22+
const TYPE_MAP: Record<string, TypeName> = {
23+
'[object Boolean]': 'boolean',
24+
'[object Number]': 'number',
25+
'[object String]': 'string',
26+
'[object Function]': 'function',
27+
'[object AsyncFunction]': 'function',
28+
'[object Array]': 'array',
29+
'[object Date]': 'date',
30+
'[object RegExp]': 'regexp',
31+
'[object Object]': 'object',
32+
'[object FileList]': 'filelist',
33+
} as const;
34+
35+
const { toString } = Object.prototype;
36+
37+
/**
38+
@module @ember/utils
39+
*/
40+
/**
41+
Returns a consistent type for the passed object.
42+
43+
Use this instead of the built-in `typeof` to get the type of an item.
44+
It will return the same result across all browsers and includes a bit
45+
more detail. Here is what will be returned:
46+
47+
| Return Value | Meaning |
48+
|---------------|------------------------------------------------------|
49+
| 'string' | String primitive or String object. |
50+
| 'number' | Number primitive or Number object. |
51+
| 'boolean' | Boolean primitive or Boolean object. |
52+
| 'null' | Null value |
53+
| 'undefined' | Undefined value |
54+
| 'function' | A function |
55+
| 'array' | An instance of Array |
56+
| 'regexp' | An instance of RegExp |
57+
| 'date' | An instance of Date |
58+
| 'filelist' | An instance of FileList |
59+
| 'class' | An Ember class (created using EmberObject.extend()) |
60+
| 'instance' | An Ember object instance |
61+
| 'error' | An instance of the Error object |
62+
| 'object' | A JavaScript object not inheriting from EmberObject |
63+
64+
Examples:
65+
66+
```javascript
67+
import { A } from '@ember/array';
68+
import { typeOf } from '@ember/utils';
69+
import EmberObject from '@ember/object';
70+
71+
typeOf(); // 'undefined'
72+
typeOf(null); // 'null'
73+
typeOf(undefined); // 'undefined'
74+
typeOf('michael'); // 'string'
75+
typeOf(new String('michael')); // 'string'
76+
typeOf(101); // 'number'
77+
typeOf(new Number(101)); // 'number'
78+
typeOf(true); // 'boolean'
79+
typeOf(new Boolean(true)); // 'boolean'
80+
typeOf(A); // 'function'
81+
typeOf(A()); // 'array'
82+
typeOf([1, 2, 90]); // 'array'
83+
typeOf(/abc/); // 'regexp'
84+
typeOf(new Date()); // 'date'
85+
typeOf(event.target.files); // 'filelist'
86+
typeOf(EmberObject.extend()); // 'class'
87+
typeOf(EmberObject.create()); // 'instance'
88+
typeOf(new Error('teamocil')); // 'error'
89+
90+
// 'normal' JavaScript object
91+
typeOf({ a: 'b' }); // 'object'
92+
```
93+
94+
@method typeOf
95+
@for @ember/-internals/utils
96+
@param item the item to check
97+
@return {String} the type
98+
@public
99+
@static
100+
*/
101+
export default function typeOf(item: unknown): TypeName {
102+
if (item === null) {
103+
return 'null';
104+
}
105+
if (item === undefined) {
106+
return 'undefined';
107+
}
108+
let ret = TYPE_MAP[toString.call(item)] || 'object';
109+
110+
if (ret === 'function') {
111+
// if (CoreObject.detect(item)) {
112+
// ret = 'class';
113+
// }
114+
} else if (ret === 'object') {
115+
if (item instanceof Error) {
116+
ret = 'error';
117+
// } else if (item instanceof CoreObject) {
118+
// ret = 'instance';
119+
} else if (item instanceof Date) {
120+
ret = 'date';
121+
}
122+
}
123+
124+
return ret;
125+
}

packages/@ember/array/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import Mixin from '@ember/object/mixin';
1616
import { assert } from '@ember/debug';
1717
import Enumerable from '@ember/enumerable';
1818
import MutableEnumerable from '@ember/enumerable/mutable';
19-
import { compare, typeOf } from '@ember/utils';
19+
import { compare } from '@ember/utils';
20+
import { typeOf } from '@ember/-internals/utils';
2021
import Observable from '@ember/object/observable';
2122
import type { MethodNamesOf, MethodParams, MethodReturns } from '@ember/-internals/utility-types';
2223
import type { ComputedPropertyCallback } from '@ember/-internals/metal';

packages/@ember/debug/container-debug-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { classify, dasherize } from '@ember/-internals/string';
22
import EmberObject from '@ember/object';
3-
import { typeOf } from '@ember/utils';
3+
import { typeOf } from '@ember/-internals/utils';
44
import type Owner from '@ember/owner';
55
import { getOwner } from '@ember/-internals/owner';
66
import type { Resolver } from '@ember/owner';

packages/@ember/object/lib/computed/computed_macros.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ function generateComputedWithPredicate(name: string, predicate: (value: unknown)
9696
@public
9797
*/
9898
export function empty(dependentKey: string) {
99+
deprecate('empty is deprecated. Define your own property using @ember/legacy-utils.', false, {
100+
id: 'ember-object.deprecate-empty',
101+
until: '7.0.0',
102+
for: 'ember-source',
103+
since: { available: '6.8.0' },
104+
});
105+
99106
assert(
100107
'You attempted to use @empty as a decorator directly, but it requires a `dependentKey` parameter',
101108
!isElementDescriptor(Array.prototype.slice.call(arguments))
@@ -142,6 +149,13 @@ export function empty(dependentKey: string) {
142149
@public
143150
*/
144151
export function notEmpty(dependentKey: string) {
152+
deprecate('notEmpty is deprecated. Define your own property using @ember/legacy-utils.', false, {
153+
id: 'ember-object.deprecate-not-empty',
154+
until: '7.0.0',
155+
for: 'ember-source',
156+
since: { available: '6.8.0' },
157+
});
158+
145159
assert(
146160
'You attempted to use @notEmpty as a decorator directly, but it requires a `dependentKey` parameter',
147161
!isElementDescriptor(Array.prototype.slice.call(arguments))
@@ -185,6 +199,13 @@ export function notEmpty(dependentKey: string) {
185199
@public
186200
*/
187201
export function none(dependentKey: string) {
202+
deprecate('none is deprecated. Define your own property using @ember/legacy-utils.', false, {
203+
id: 'ember-object.deprecate-none',
204+
until: '7.0.0',
205+
for: 'ember-source',
206+
since: { available: '6.8.0' },
207+
});
208+
188209
assert(
189210
'You attempted to use @none as a decorator directly, but it requires a `dependentKey` parameter',
190211
!isElementDescriptor(Array.prototype.slice.call(arguments))

packages/@ember/routing/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import EmberObject, { computed, get, set, getProperties, setProperties } from '@
1212
import Evented from '@ember/object/evented';
1313
import { A as emberA } from '@ember/array';
1414
import { ActionHandler } from '@ember/-internals/runtime';
15-
import { typeOf } from '@ember/utils';
16-
import { isProxy, lookupDescriptor } from '@ember/-internals/utils';
15+
import { isProxy, lookupDescriptor, typeOf } from '@ember/-internals/utils';
1716
import type { AnyFn } from '@ember/-internals/utility-types';
1817
import Controller from '@ember/controller';
1918
import type { ControllerQueryParamType } from '@ember/controller';

packages/@ember/routing/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
import type RouterService from '@ember/routing/router-service';
2222
import EmberObject from '@ember/object';
2323
import { A as emberA } from '@ember/array';
24-
import { typeOf } from '@ember/utils';
24+
import { typeOf } from '@ember/-internals/utils';
2525
import Evented from '@ember/object/evented';
2626
import { assert, info } from '@ember/debug';
2727
import { cancel, once, run, scheduleOnce } from '@ember/runloop';

packages/@ember/utils/lib/compare.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { TypeName } from './type-of';
22
import typeOf from './type-of';
33
import { Comparable } from '@ember/-internals/runtime';
4-
import { assert } from '@ember/debug';
4+
import { assert, deprecate } from '@ember/debug';
55

66
const TYPE_ORDER: Record<TypeName, number> = {
77
undefined: 0,
@@ -97,6 +97,13 @@ function spaceship(a: number, b: number): Compare {
9797
@public
9898
*/
9999
export default function compare<T>(v: T, w: T): Compare {
100+
deprecate('compare is deprecated. Use @ember/legacy-utils instead.', false, {
101+
for: 'ember-source',
102+
id: 'ember-utils.deprecate-compare',
103+
since: { available: '6.8.0' },
104+
until: '7.0.0',
105+
});
106+
100107
if (v === w) {
101108
return 0;
102109
}

packages/@ember/utils/lib/is-equal.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
@module @ember/utils
33
*/
4+
5+
import { deprecate } from '@ember/debug';
6+
47
/**
58
Compares two objects, returning true if they are equal.
69
@@ -48,6 +51,13 @@
4851
@public
4952
*/
5053
export default function isEqual(a: unknown, b: unknown): boolean {
54+
deprecate('isEqual is deprecated. Use @ember/legacy-utils instead.', false, {
55+
for: 'ember-source',
56+
id: 'ember-utils.deprecate-isEqual',
57+
since: { available: '6.8.0' },
58+
until: '7.0.0',
59+
});
60+
5161
if (a && typeof (a as IsEqual).isEqual === 'function') {
5262
return (a as IsEqual).isEqual(b);
5363
}

0 commit comments

Comments
 (0)