Skip to content

Commit 4e331d1

Browse files
committed
Remove global observer helper since it doesn't work with native classes
1 parent 7f9f6e3 commit 4e331d1

File tree

20 files changed

+783
-1284
lines changed

20 files changed

+783
-1284
lines changed

packages/@ember/-internals/glimmer/lib/helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export default class Helper<S = unknown> extends FrameworkObject {
136136
assert('expected compute to be defined', this.compute);
137137
}
138138

139+
// TODO: Update example to not use observer
139140
/**
140141
On a class-based helper, it may be useful to force a recomputation of that
141142
helpers value. This is akin to `rerender` on a component.

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

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
equalTokens,
77
equalsElement,
88
runTask,
9-
runLoopSettled,
109
} from 'internal-test-helpers';
1110

1211
import { tracked as trackedBuiltIn } from 'tracked-built-ins';
@@ -17,7 +16,7 @@ import { DEBUG } from '@glimmer/env';
1716
import { tracked } from '@ember/-internals/metal';
1817
import { alias } from '@ember/object/computed';
1918
import Service, { service } from '@ember/service';
20-
import EmberObject, { set, get, computed, observer } from '@ember/object';
19+
import EmberObject, { set, get, computed } from '@ember/object';
2120

2221
import { Component, compile, htmlSafe } from '../../utils/helpers';
2322
import { backtrackingMessageFor } from '../../utils/debug-stack';
@@ -3096,44 +3095,6 @@ moduleFor(
30963095
this.assertText('things');
30973096
}
30983097

3099-
async ['@test didReceiveAttrs fires after .init() but before observers become active'](assert) {
3100-
let barCopyDidChangeCount = 0;
3101-
3102-
this.registerComponent('foo-bar', {
3103-
ComponentClass: Component.extend({
3104-
init() {
3105-
this._super(...arguments);
3106-
this.didInit = true;
3107-
},
3108-
3109-
didReceiveAttrs() {
3110-
assert.ok(this.didInit, 'expected init to have run before didReceiveAttrs');
3111-
this.set('barCopy', this.attrs.bar.value + 1);
3112-
},
3113-
3114-
barCopyDidChange: observer('barCopy', () => {
3115-
barCopyDidChangeCount++;
3116-
}),
3117-
}),
3118-
3119-
template: '{{this.bar}}-{{this.barCopy}}',
3120-
});
3121-
3122-
await this.render(`{{foo-bar bar=this.bar}}`, { bar: 3 });
3123-
3124-
this.assertText('3-4');
3125-
3126-
assert.strictEqual(barCopyDidChangeCount, 1, 'expected observer firing for: barCopy');
3127-
3128-
set(this.context, 'bar', 7);
3129-
3130-
await runLoopSettled();
3131-
3132-
this.assertText('7-8');
3133-
3134-
assert.strictEqual(barCopyDidChangeCount, 2, 'expected observer firing for: barCopy');
3135-
}
3136-
31373098
['@test overriding didReceiveAttrs does not trigger deprecation'](assert) {
31383099
this.registerComponent('foo-bar', {
31393100
ComponentClass: class extends Component {

packages/@ember/-internals/metal/tests/accessors/get_test.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { ENV } from '@ember/-internals/environment';
2-
import EmberObject, { observer } from '@ember/object';
2+
import EmberObject from '@ember/object';
33
import { get } from '../..';
4-
import Mixin from '@ember/object/mixin';
54
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
65
import { run } from '@ember/runloop';
7-
import { destroy } from '@glimmer/destroyable';
86

97
function aget(x, y) {
108
return x[y];
@@ -179,29 +177,5 @@ moduleFor(
179177
/The key provided to get must be a string or number, you passed false/
180178
);
181179
}
182-
183-
// ..........................................................
184-
// BUGS
185-
//
186-
187-
['@test (regression) watched properties on unmodified inherited objects should still return their original value'](
188-
assert
189-
) {
190-
let MyMixin = Mixin.create({
191-
someProperty: 'foo',
192-
propertyDidChange: observer('someProperty', () => {}),
193-
});
194-
195-
let baseObject = MyMixin.apply({});
196-
let theRealObject = Object.create(baseObject);
197-
198-
assert.equal(
199-
get(theRealObject, 'someProperty'),
200-
'foo',
201-
'should return the set value, not false'
202-
);
203-
204-
run(() => destroy(baseObject));
205-
}
206180
}
207181
);

packages/@ember/-internals/metal/tests/observer_test.js

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010
get,
1111
set,
1212
} from '..';
13-
import { observer } from '@ember/object';
14-
import Mixin, { mixin } from '@ember/object/mixin';
1513
import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
1614
import { destroy } from '@glimmer/destroyable';
1715
import { meta as metaFor } from '@ember/-internals/meta';
@@ -35,40 +33,6 @@ moduleFor(
3533
}
3634
}
3735

38-
['@test observer should assert to invalid input']() {
39-
expectAssertion(() => {
40-
observer(() => {});
41-
}, 'observer called without valid path');
42-
43-
expectAssertion(() => {
44-
observer(null);
45-
}, 'observer must be provided a function or an observer definition');
46-
47-
expectAssertion(() => {
48-
observer({});
49-
}, 'observer called without a function');
50-
51-
expectAssertion(() => {
52-
observer({
53-
fn() {},
54-
});
55-
}, 'observer called without valid path');
56-
57-
expectAssertion(() => {
58-
observer({
59-
fn() {},
60-
dependentKeys: [],
61-
});
62-
}, 'observer called without valid path');
63-
64-
expectAssertion(() => {
65-
observer({
66-
fn() {},
67-
dependentKeys: ['foo'],
68-
});
69-
}, 'observer called without sync');
70-
}
71-
7236
async ['@test observer should fire when property is modified'](assert) {
7337
obj = {};
7438
let count = 0;
@@ -189,79 +153,6 @@ moduleFor(
189153
assert.equal(observerCount, 10, 'should continue to fire indefinitely');
190154
}
191155

192-
async ['@test observers watching multiple properties via brace expansion should fire when the properties change'](
193-
assert
194-
) {
195-
obj = {};
196-
let count = 0;
197-
198-
mixin(obj, {
199-
observeFooAndBar: observer('{foo,bar}', function () {
200-
count++;
201-
}),
202-
});
203-
204-
set(obj, 'foo', 'foo');
205-
await runLoopSettled();
206-
207-
assert.equal(count, 1, 'observer specified via brace expansion invoked on property change');
208-
209-
set(obj, 'bar', 'bar');
210-
await runLoopSettled();
211-
212-
assert.equal(count, 2, 'observer specified via brace expansion invoked on property change');
213-
214-
set(obj, 'baz', 'baz');
215-
await runLoopSettled();
216-
217-
assert.equal(count, 2, 'observer not invoked on unspecified property');
218-
}
219-
220-
async ['@test observers watching multiple properties via brace expansion should fire when dependent properties change'](
221-
assert
222-
) {
223-
obj = { baz: 'Initial' };
224-
let count = 0;
225-
226-
defineProperty(
227-
obj,
228-
'foo',
229-
computed('bar', function () {
230-
return get(this, 'bar').toLowerCase();
231-
})
232-
);
233-
234-
defineProperty(
235-
obj,
236-
'bar',
237-
computed('baz', function () {
238-
return get(this, 'baz').toUpperCase();
239-
})
240-
);
241-
242-
mixin(obj, {
243-
fooAndBarWatcher: observer('{foo,bar}', function () {
244-
count++;
245-
}),
246-
});
247-
248-
get(obj, 'foo');
249-
set(obj, 'baz', 'Baz');
250-
await runLoopSettled();
251-
252-
// fire once for foo, once for bar
253-
assert.equal(
254-
count,
255-
2,
256-
'observer specified via brace expansion invoked on dependent property change'
257-
);
258-
259-
set(obj, 'quux', 'Quux');
260-
await runLoopSettled();
261-
262-
assert.equal(count, 2, 'observer not fired on unspecified property');
263-
}
264-
265156
async ['@test removing an chain observer on change should not fail'](assert) {
266157
let foo = { bar: 'bar' };
267158
let obj1 = { foo: foo };
@@ -433,36 +324,6 @@ moduleFor(
433324
assert.equal(count, 1, "removed observer shouldn't fire");
434325
}
435326

436-
async ['@test local observers can be removed'](assert) {
437-
let barObserved = 0;
438-
439-
let MyMixin = Mixin.create({
440-
foo1: observer('bar', function () {
441-
barObserved++;
442-
}),
443-
444-
foo2: observer('bar', function () {
445-
barObserved++;
446-
}),
447-
});
448-
449-
obj = {};
450-
MyMixin.apply(obj);
451-
452-
set(obj, 'bar', 'HI!');
453-
await runLoopSettled();
454-
455-
assert.equal(barObserved, 2, 'precond - observers should be fired');
456-
457-
removeObserver(obj, 'bar', null, 'foo1');
458-
459-
barObserved = 0;
460-
set(obj, 'bar', 'HI AGAIN!');
461-
await runLoopSettled();
462-
463-
assert.equal(barObserved, 1, 'removed observers should not be called');
464-
}
465-
466327
async ['@test removeObserver should respect targets with methods'](assert) {
467328
let observed = { foo: 'foo' };
468329

packages/@ember/-internals/runtime/tests/system/core_object_test.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { getOwner, setOwner } from '@ember/-internals/owner';
2-
import { get, set, observer } from '@ember/object';
2+
import { get, set } from '@ember/object';
33
import CoreObject from '@ember/object/core';
4-
import {
5-
moduleFor,
6-
AbstractTestCase,
7-
buildOwner,
8-
runDestroy,
9-
runLoopSettled,
10-
} from 'internal-test-helpers';
4+
import { moduleFor, AbstractTestCase, buildOwner, runDestroy } from 'internal-test-helpers';
115
import { track } from '@glimmer/validator';
126
import { destroy } from '@glimmer/destroyable';
137
import { run } from '@ember/runloop';
@@ -97,32 +91,6 @@ moduleFor(
9791
TestObj.create(options);
9892
}
9993

100-
async ['@test observed properties are enumerable when set GH#14594'](assert) {
101-
let callCount = 0;
102-
let Test = CoreObject.extend({
103-
myProp: null,
104-
anotherProp: undefined,
105-
didChangeMyProp: observer('myProp', function () {
106-
callCount++;
107-
}),
108-
});
109-
110-
let test = Test.create();
111-
set(test, 'id', '3');
112-
set(test, 'myProp', { id: 1 });
113-
114-
assert.deepEqual(Object.keys(test).sort(), ['id', 'myProp']);
115-
116-
set(test, 'anotherProp', 'nice');
117-
118-
assert.deepEqual(Object.keys(test).sort(), ['anotherProp', 'id', 'myProp']);
119-
await runLoopSettled();
120-
121-
assert.equal(callCount, 1);
122-
123-
test.destroy();
124-
}
125-
12694
['@test native getters/setters do not cause rendering invalidation during init'](assert) {
12795
let objectMeta = Object.create(null);
12896

0 commit comments

Comments
 (0)