Skip to content

Commit 14bdd33

Browse files
authored
Merge pull request #20937 from wagenet/remove-observable-methods
Remove observable methods
2 parents 362f70c + 096f7fe commit 14bdd33

File tree

122 files changed

+1688
-3096
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1688
-3096
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,4 @@
389389
}
390390
},
391391
"packageManager": "[email protected]"
392-
}
392+
}

packages/@ember/-internals/glimmer/lib/component-managers/curly.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252

5353
import ComponentStateBucket from '../utils/curly-component-state-bucket';
5454
import { processComponentArgs } from '../utils/process-args';
55+
import { setProperties } from '@ember/-internals/metal';
5556

5657
export const ARGS = enumerableSymbol('ARGS');
5758
export const HAS_BLOCK = enumerableSymbol('HAS_BLOCK');
@@ -440,7 +441,7 @@ export default class CurlyComponentManager
440441
bucket.argsRevision = valueForTag(argsTag);
441442

442443
component[IS_DISPATCHING_ATTRS] = true;
443-
component.setProperties(props);
444+
setProperties(component, props);
444445
component[IS_DISPATCHING_ATTRS] = false;
445446

446447
component.trigger('didUpdateAttrs');

packages/@ember/-internals/glimmer/lib/component-managers/mount.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { InternalOwner } from '@ember/-internals/owner';
22
import { generateControllerFactory } from '@ember/routing/-internals';
33
import { assert } from '@ember/debug';
44
import EngineInstance from '@ember/engine/instance';
5+
import { get, set } from '@ember/object';
56
import { associateDestroyableChild } from '@glimmer/destroyable';
67
import type {
78
CapturedArguments,
@@ -95,7 +96,7 @@ class MountManager
9596
let modelRef;
9697

9798
if (args.named.has('model')) {
98-
modelRef = args.named.get('model');
99+
modelRef = get(args.named, 'model') as Reference;
99100
}
100101

101102
if (modelRef === undefined) {
@@ -163,7 +164,7 @@ class MountManager
163164
let { controller, modelRef } = bucket;
164165

165166
if (modelRef !== undefined) {
166-
controller.set('model', valueForRef(modelRef));
167+
set(controller, 'model', valueForRef(modelRef));
167168
}
168169
}
169170
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ declare const SIGNATURE: unique symbol;
268268
269269
```app/components/my-widget.js
270270
import Component from '@ember/component';
271-
import EmberObject from '@ember/object';
271+
import CoreObject from '@ember/object/core';
272272
273273
export default class extends Component {
274274
classNameBindings = ['messages.empty'];
275275
276-
messages = EmberObject.create({
276+
messages = CoreObject.create({
277277
empty: true
278278
});
279279
}
@@ -867,7 +867,7 @@ class Component<S = unknown>
867867

868868
getAttr(key: string) {
869869
// TODO Intimate API should be deprecated
870-
return this.get(key);
870+
return get(this, key);
871871
}
872872

873873
/**

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/lib/helpers/mut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { internalHelper } from './internal-helper';
2929
// my-child.js
3030
export default class MyChild extends Component {
3131
click() {
32-
this.incrementProperty('childClickCount');
32+
set(this, 'childClickCount', this.childClickCount + 1);
3333
}
3434
}
3535
```

packages/@ember/-internals/glimmer/lib/helpers/readonly.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { internalHelper } from './internal-helper';
3434
```app/components/my-child.js
3535
export default class MyChild extends Component {
3636
click() {
37-
this.incrementProperty('childClickCount');
37+
set(this, 'childClickCount', this.childClickCount + 1);
3838
}
3939
}
4040
```
@@ -95,7 +95,7 @@ import { internalHelper } from './internal-helper';
9595
9696
export default class MyChild extends Component {
9797
click() {
98-
this.get('clicks').incrementProperty('total');
98+
set(this.clicks, 'total', this.clicks.total + 1);
9999
}
100100
}
101101
```

packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { ENV } from '@ember/-internals/environment';
99
import { Component, setComponentManager } from '@ember/-internals/glimmer';
1010
import type { InternalOwner } from '@ember/-internals/owner';
11+
import { set } from '@ember/object';
1112
import Route from '@ember/routing/route';
1213
import Controller from '@ember/controller';
1314
import { assert, captureRenderTree } from '@ember/debug';
@@ -313,7 +314,8 @@ if (ENV._DEBUG_RENDER_TREE) {
313314
]);
314315

315316
runTask(() => {
316-
this.controllerFor('application')!.set('engineName', 'bar');
317+
const controller = this.controllerFor('application')!;
318+
set(controller, 'engineName', 'bar');
317319
});
318320

319321
this.assertRenderTree([
@@ -362,7 +364,8 @@ if (ENV._DEBUG_RENDER_TREE) {
362364
]);
363365

364366
runTask(() => {
365-
this.controllerFor('application')!.set('engineName', undefined);
367+
const controller = this.controllerFor('application')!;
368+
set(controller, 'engineName', undefined);
366369
});
367370

368371
this.assertRenderTree([
@@ -396,10 +399,9 @@ if (ENV._DEBUG_RENDER_TREE) {
396399
};
397400

398401
runTask(() => {
399-
this.controllerFor('application')!.setProperties({
400-
showMore: true,
401-
engineModel: model,
402-
});
402+
const controller = this.controllerFor('application')!;
403+
set(controller, 'showMore', true);
404+
set(controller, 'engineModel', model);
403405
});
404406

405407
this.assertRenderTree([
@@ -458,7 +460,8 @@ if (ENV._DEBUG_RENDER_TREE) {
458460
]);
459461

460462
runTask(() => {
461-
this.controllerFor('application')!.set('engineName', 'bar');
463+
const controller = this.controllerFor('application')!;
464+
set(controller, 'engineName', 'bar');
462465
});
463466

464467
this.assertRenderTree([
@@ -569,10 +572,9 @@ if (ENV._DEBUG_RENDER_TREE) {
569572
]);
570573

571574
runTask(() => {
572-
this.controllerFor('application')!.setProperties({
573-
showMore: false,
574-
engineName: undefined,
575-
});
575+
const controller = this.controllerFor('application')!;
576+
set(controller, 'showMore', false);
577+
set(controller, 'engineName', undefined);
576578
});
577579

578580
this.assertRenderTree([
@@ -720,7 +722,7 @@ if (ENV._DEBUG_RENDER_TREE) {
720722
runTask(() => {
721723
let controller = instance!.lookup('controller:application');
722724
assert('Expected an instance of controller', controller instanceof Controller);
723-
controller.set('message', 'World');
725+
set(controller, 'message', 'World');
724726
});
725727

726728
this.assertRenderTree([
@@ -776,7 +778,7 @@ if (ENV._DEBUG_RENDER_TREE) {
776778
runTask(() => {
777779
let controller = instance!.lookup('controller:application');
778780
assert('Expected an instance of controller', controller instanceof Controller);
779-
controller.set('message', undefined);
781+
set(controller, 'message', undefined);
780782
});
781783

782784
this.assertRenderTree([
@@ -870,7 +872,8 @@ if (ENV._DEBUG_RENDER_TREE) {
870872
]);
871873

872874
runTask(() => {
873-
this.controllerFor('application')!.set('showSecond', true);
875+
const controller = this.controllerFor('application')!;
876+
set(controller, 'showSecond', true);
874877
});
875878

876879
this.assertRenderTree([
@@ -895,7 +898,8 @@ if (ENV._DEBUG_RENDER_TREE) {
895898
]);
896899

897900
runTask(() => {
898-
this.controllerFor('application')!.set('showSecond', false);
901+
const controller = this.controllerFor('application')!;
902+
set(controller, 'showSecond', false);
899903
});
900904

901905
this.assertRenderTree([
@@ -943,7 +947,8 @@ if (ENV._DEBUG_RENDER_TREE) {
943947
]);
944948

945949
runTask(() => {
946-
this.controllerFor('application')!.set('showSecond', true);
950+
const controller = this.controllerFor('application')!;
951+
set(controller, 'showSecond', true);
947952
});
948953

949954
this.assertRenderTree([
@@ -968,7 +973,8 @@ if (ENV._DEBUG_RENDER_TREE) {
968973
]);
969974

970975
runTask(() => {
971-
this.controllerFor('application')!.set('showSecond', false);
976+
const controller = this.controllerFor('application')!;
977+
set(controller, 'showSecond', false);
972978
});
973979

974980
this.assertRenderTree([
@@ -1018,7 +1024,8 @@ if (ENV._DEBUG_RENDER_TREE) {
10181024
]);
10191025

10201026
runTask(() => {
1021-
this.controllerFor('application')!.set('showSecond', true);
1027+
const controller = this.controllerFor('application')!;
1028+
set(controller, 'showSecond', true);
10221029
});
10231030

10241031
this.assertRenderTree([
@@ -1043,7 +1050,8 @@ if (ENV._DEBUG_RENDER_TREE) {
10431050
]);
10441051

10451052
runTask(() => {
1046-
this.controllerFor('application')!.set('showSecond', false);
1053+
const controller = this.controllerFor('application')!;
1054+
set(controller, 'showSecond', false);
10471055
});
10481056

10491057
this.assertRenderTree([
@@ -1091,7 +1099,8 @@ if (ENV._DEBUG_RENDER_TREE) {
10911099
]);
10921100

10931101
runTask(() => {
1094-
this.controllerFor('application')!.set('showSecond', true);
1102+
const controller = this.controllerFor('application')!;
1103+
set(controller, 'showSecond', true);
10951104
});
10961105

10971106
this.assertRenderTree([
@@ -1116,7 +1125,8 @@ if (ENV._DEBUG_RENDER_TREE) {
11161125
]);
11171126

11181127
runTask(() => {
1119-
this.controllerFor('application')!.set('showSecond', false);
1128+
const controller = this.controllerFor('application')!;
1129+
set(controller, 'showSecond', false);
11201130
});
11211131

11221132
this.assertRenderTree([
@@ -1176,7 +1186,8 @@ if (ENV._DEBUG_RENDER_TREE) {
11761186
]);
11771187

11781188
runTask(() => {
1179-
this.controllerFor('application')!.set('showSecond', true);
1189+
const controller = this.controllerFor('application')!;
1190+
set(controller, 'showSecond', true);
11801191
});
11811192

11821193
this.assertRenderTree([
@@ -1201,7 +1212,8 @@ if (ENV._DEBUG_RENDER_TREE) {
12011212
]);
12021213

12031214
runTask(() => {
1204-
this.controllerFor('application')!.set('showSecond', false);
1215+
const controller = this.controllerFor('application')!;
1216+
set(controller, 'showSecond', false);
12051217
});
12061218

12071219
this.assertRenderTree([
@@ -1295,7 +1307,7 @@ if (ENV._DEBUG_RENDER_TREE) {
12951307
},
12961308
]);
12971309

1298-
runTask(() => target.set('showSecond', true));
1310+
runTask(() => set(target, 'showSecond', true));
12991311

13001312
const secondModifiers: ExpectedRenderNode['children'] = [
13011313
{
@@ -1366,7 +1378,7 @@ if (ENV._DEBUG_RENDER_TREE) {
13661378
},
13671379
]);
13681380

1369-
runTask(() => target.set('showSecond', false));
1381+
runTask(() => set(target, 'showSecond', false));
13701382

13711383
this.assertRenderTree([
13721384
{
@@ -1462,7 +1474,8 @@ if (ENV._DEBUG_RENDER_TREE) {
14621474
this.assertRenderTree([textareaNode('first', this.element!.firstChild, firstModifiers)]);
14631475

14641476
runTask(() => {
1465-
this.controllerFor('application')!.set('showSecond', true);
1477+
const controller = this.controllerFor('application')!;
1478+
set(controller, 'showSecond', true);
14661479
});
14671480

14681481
const secondModifiers: ExpectedRenderNode['children'] = [
@@ -1519,7 +1532,8 @@ if (ENV._DEBUG_RENDER_TREE) {
15191532
]);
15201533

15211534
runTask(() => {
1522-
this.controllerFor('application')!.set('showSecond', false);
1535+
const controller = this.controllerFor('application')!;
1536+
set(controller, 'showSecond', false);
15231537
});
15241538

15251539
this.assertRenderTree([textareaNode('first', this.element!.firstChild, firstModifiers)]);
@@ -1571,7 +1585,8 @@ if (ENV._DEBUG_RENDER_TREE) {
15711585
]);
15721586

15731587
runTask(() => {
1574-
this.controllerFor('application')!.set('showSecond', true);
1588+
const controller = this.controllerFor('application')!;
1589+
set(controller, 'showSecond', true);
15751590
});
15761591

15771592
const secondModifiers: ExpectedRenderNode['children'] = [
@@ -1608,7 +1623,8 @@ if (ENV._DEBUG_RENDER_TREE) {
16081623
]);
16091624

16101625
runTask(() => {
1611-
this.controllerFor('application')!.set('showSecond', false);
1626+
const controller = this.controllerFor('application')!;
1627+
set(controller, 'showSecond', false);
16121628
});
16131629

16141630
this.assertRenderTree([

packages/@ember/-internals/glimmer/tests/integration/application/helper-registration-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { moduleFor, ApplicationTestCase } from 'internal-test-helpers';
22
import Controller from '@ember/controller';
3+
import { get } from '@ember/object';
34
import Service, { service } from '@ember/service';
45
import { Helper, helper } from '@ember/-internals/glimmer';
56

@@ -96,7 +97,7 @@ moduleFor(
9697
nameBuilder;
9798

9899
compute() {
99-
this.get('nameBuilder').build();
100+
get(this, 'nameBuilder').build();
100101
}
101102
}
102103
);

packages/@ember/-internals/glimmer/tests/integration/application/hot-reload-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { moduleFor, ApplicationTestCase, strip, runTask } from 'internal-test-helpers';
22

3+
import { set } from '@ember/object';
34
import Service, { service } from '@ember/service';
45
import { Component, Helper } from '@ember/-internals/glimmer';
56

@@ -182,7 +183,7 @@ moduleFor(
182183
tagName = '';
183184
init() {
184185
super.init(...arguments);
185-
this.set('id', id++);
186+
set(this, 'id', id++);
186187
}
187188
},
188189
template: 'x-foo: {{@name}} ({{this.id}})',
@@ -193,7 +194,7 @@ moduleFor(
193194
tagName = '';
194195
init() {
195196
super.init(...arguments);
196-
this.set('id', id++);
197+
set(this, 'id', id++);
197198
}
198199
},
199200
template: 'x-bar ({{this.id}})',

0 commit comments

Comments
 (0)