diff --git a/package.json b/package.json index 44f222907bc..13d84447c8a 100644 --- a/package.json +++ b/package.json @@ -389,4 +389,4 @@ } }, "packageManager": "pnpm@10.5.0" -} +} \ No newline at end of file diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts b/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts index 1f4edaf029d..c3bd95e00cd 100644 --- a/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts +++ b/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts @@ -52,6 +52,7 @@ import { import ComponentStateBucket from '../utils/curly-component-state-bucket'; import { processComponentArgs } from '../utils/process-args'; +import { setProperties } from '@ember/-internals/metal'; export const ARGS = enumerableSymbol('ARGS'); export const HAS_BLOCK = enumerableSymbol('HAS_BLOCK'); @@ -440,7 +441,7 @@ export default class CurlyComponentManager bucket.argsRevision = valueForTag(argsTag); component[IS_DISPATCHING_ATTRS] = true; - component.setProperties(props); + setProperties(component, props); component[IS_DISPATCHING_ATTRS] = false; component.trigger('didUpdateAttrs'); diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/mount.ts b/packages/@ember/-internals/glimmer/lib/component-managers/mount.ts index 1fa7a7c8e3c..83712502673 100644 --- a/packages/@ember/-internals/glimmer/lib/component-managers/mount.ts +++ b/packages/@ember/-internals/glimmer/lib/component-managers/mount.ts @@ -2,6 +2,7 @@ import type { InternalOwner } from '@ember/-internals/owner'; import { generateControllerFactory } from '@ember/routing/-internals'; import { assert } from '@ember/debug'; import EngineInstance from '@ember/engine/instance'; +import { get, set } from '@ember/object'; import { associateDestroyableChild } from '@glimmer/destroyable'; import type { CapturedArguments, @@ -95,7 +96,7 @@ class MountManager let modelRef; if (args.named.has('model')) { - modelRef = args.named.get('model'); + modelRef = get(args.named, 'model') as Reference; } if (modelRef === undefined) { @@ -163,7 +164,7 @@ class MountManager let { controller, modelRef } = bucket; if (modelRef !== undefined) { - controller.set('model', valueForRef(modelRef)); + set(controller, 'model', valueForRef(modelRef)); } } } diff --git a/packages/@ember/-internals/glimmer/lib/component.ts b/packages/@ember/-internals/glimmer/lib/component.ts index facb381a739..606576970e6 100644 --- a/packages/@ember/-internals/glimmer/lib/component.ts +++ b/packages/@ember/-internals/glimmer/lib/component.ts @@ -268,12 +268,12 @@ declare const SIGNATURE: unique symbol; ```app/components/my-widget.js import Component from '@ember/component'; - import EmberObject from '@ember/object'; + import CoreObject from '@ember/object/core'; export default class extends Component { classNameBindings = ['messages.empty']; - messages = EmberObject.create({ + messages = CoreObject.create({ empty: true }); } @@ -867,7 +867,7 @@ class Component getAttr(key: string) { // TODO Intimate API should be deprecated - return this.get(key); + return get(this, key); } /** diff --git a/packages/@ember/-internals/glimmer/lib/helper.ts b/packages/@ember/-internals/glimmer/lib/helper.ts index 1a20182a69b..dbb74262806 100644 --- a/packages/@ember/-internals/glimmer/lib/helper.ts +++ b/packages/@ember/-internals/glimmer/lib/helper.ts @@ -136,6 +136,7 @@ export default class Helper extends FrameworkObject { assert('expected compute to be defined', this.compute); } + // TODO: Update example to not use observer /** On a class-based helper, it may be useful to force a recomputation of that helpers value. This is akin to `rerender` on a component. diff --git a/packages/@ember/-internals/glimmer/lib/helpers/mut.ts b/packages/@ember/-internals/glimmer/lib/helpers/mut.ts index 2c75d05fbc2..1680bead34a 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/mut.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/mut.ts @@ -29,7 +29,7 @@ import { internalHelper } from './internal-helper'; // my-child.js export default class MyChild extends Component { click() { - this.incrementProperty('childClickCount'); + set(this, 'childClickCount', this.childClickCount + 1); } } ``` diff --git a/packages/@ember/-internals/glimmer/lib/helpers/readonly.ts b/packages/@ember/-internals/glimmer/lib/helpers/readonly.ts index 503eeefb44c..70dc3cf431e 100644 --- a/packages/@ember/-internals/glimmer/lib/helpers/readonly.ts +++ b/packages/@ember/-internals/glimmer/lib/helpers/readonly.ts @@ -34,7 +34,7 @@ import { internalHelper } from './internal-helper'; ```app/components/my-child.js export default class MyChild extends Component { click() { - this.incrementProperty('childClickCount'); + set(this, 'childClickCount', this.childClickCount + 1); } } ``` @@ -95,7 +95,7 @@ import { internalHelper } from './internal-helper'; export default class MyChild extends Component { click() { - this.get('clicks').incrementProperty('total'); + set(this.clicks, 'total', this.clicks.total + 1); } } ``` diff --git a/packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts b/packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts index b255af4502c..e3ce7922661 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts +++ b/packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts @@ -8,6 +8,7 @@ import { import { ENV } from '@ember/-internals/environment'; import { Component, setComponentManager } from '@ember/-internals/glimmer'; import type { InternalOwner } from '@ember/-internals/owner'; +import { set } from '@ember/object'; import Route from '@ember/routing/route'; import Controller from '@ember/controller'; import { assert, captureRenderTree } from '@ember/debug'; @@ -313,7 +314,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('engineName', 'bar'); + const controller = this.controllerFor('application')!; + set(controller, 'engineName', 'bar'); }); this.assertRenderTree([ @@ -362,7 +364,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('engineName', undefined); + const controller = this.controllerFor('application')!; + set(controller, 'engineName', undefined); }); this.assertRenderTree([ @@ -396,10 +399,9 @@ if (ENV._DEBUG_RENDER_TREE) { }; runTask(() => { - this.controllerFor('application')!.setProperties({ - showMore: true, - engineModel: model, - }); + const controller = this.controllerFor('application')!; + set(controller, 'showMore', true); + set(controller, 'engineModel', model); }); this.assertRenderTree([ @@ -458,7 +460,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('engineName', 'bar'); + const controller = this.controllerFor('application')!; + set(controller, 'engineName', 'bar'); }); this.assertRenderTree([ @@ -569,10 +572,9 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.setProperties({ - showMore: false, - engineName: undefined, - }); + const controller = this.controllerFor('application')!; + set(controller, 'showMore', false); + set(controller, 'engineName', undefined); }); this.assertRenderTree([ @@ -720,7 +722,7 @@ if (ENV._DEBUG_RENDER_TREE) { runTask(() => { let controller = instance!.lookup('controller:application'); assert('Expected an instance of controller', controller instanceof Controller); - controller.set('message', 'World'); + set(controller, 'message', 'World'); }); this.assertRenderTree([ @@ -776,7 +778,7 @@ if (ENV._DEBUG_RENDER_TREE) { runTask(() => { let controller = instance!.lookup('controller:application'); assert('Expected an instance of controller', controller instanceof Controller); - controller.set('message', undefined); + set(controller, 'message', undefined); }); this.assertRenderTree([ @@ -870,7 +872,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', true); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', true); }); this.assertRenderTree([ @@ -895,7 +898,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', false); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', false); }); this.assertRenderTree([ @@ -943,7 +947,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', true); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', true); }); this.assertRenderTree([ @@ -968,7 +973,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', false); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', false); }); this.assertRenderTree([ @@ -1018,7 +1024,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', true); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', true); }); this.assertRenderTree([ @@ -1043,7 +1050,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', false); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', false); }); this.assertRenderTree([ @@ -1091,7 +1099,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', true); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', true); }); this.assertRenderTree([ @@ -1116,7 +1125,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', false); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', false); }); this.assertRenderTree([ @@ -1176,7 +1186,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', true); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', true); }); this.assertRenderTree([ @@ -1201,7 +1212,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', false); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', false); }); this.assertRenderTree([ @@ -1295,7 +1307,7 @@ if (ENV._DEBUG_RENDER_TREE) { }, ]); - runTask(() => target.set('showSecond', true)); + runTask(() => set(target, 'showSecond', true)); const secondModifiers: ExpectedRenderNode['children'] = [ { @@ -1366,7 +1378,7 @@ if (ENV._DEBUG_RENDER_TREE) { }, ]); - runTask(() => target.set('showSecond', false)); + runTask(() => set(target, 'showSecond', false)); this.assertRenderTree([ { @@ -1462,7 +1474,8 @@ if (ENV._DEBUG_RENDER_TREE) { this.assertRenderTree([textareaNode('first', this.element!.firstChild, firstModifiers)]); runTask(() => { - this.controllerFor('application')!.set('showSecond', true); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', true); }); const secondModifiers: ExpectedRenderNode['children'] = [ @@ -1519,7 +1532,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', false); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', false); }); this.assertRenderTree([textareaNode('first', this.element!.firstChild, firstModifiers)]); @@ -1571,7 +1585,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', true); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', true); }); const secondModifiers: ExpectedRenderNode['children'] = [ @@ -1608,7 +1623,8 @@ if (ENV._DEBUG_RENDER_TREE) { ]); runTask(() => { - this.controllerFor('application')!.set('showSecond', false); + const controller = this.controllerFor('application')!; + set(controller, 'showSecond', false); }); this.assertRenderTree([ diff --git a/packages/@ember/-internals/glimmer/tests/integration/application/helper-registration-test.js b/packages/@ember/-internals/glimmer/tests/integration/application/helper-registration-test.js index 814f5f940c2..70df55905ce 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/application/helper-registration-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/application/helper-registration-test.js @@ -1,5 +1,6 @@ import { moduleFor, ApplicationTestCase } from 'internal-test-helpers'; import Controller from '@ember/controller'; +import { get } from '@ember/object'; import Service, { service } from '@ember/service'; import { Helper, helper } from '@ember/-internals/glimmer'; @@ -96,7 +97,7 @@ moduleFor( nameBuilder; compute() { - this.get('nameBuilder').build(); + get(this, 'nameBuilder').build(); } } ); diff --git a/packages/@ember/-internals/glimmer/tests/integration/application/hot-reload-test.js b/packages/@ember/-internals/glimmer/tests/integration/application/hot-reload-test.js index bffa987bc8a..9bdc80b5b96 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/application/hot-reload-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/application/hot-reload-test.js @@ -1,5 +1,6 @@ import { moduleFor, ApplicationTestCase, strip, runTask } from 'internal-test-helpers'; +import { set } from '@ember/object'; import Service, { service } from '@ember/service'; import { Component, Helper } from '@ember/-internals/glimmer'; @@ -182,7 +183,7 @@ moduleFor( tagName = ''; init() { super.init(...arguments); - this.set('id', id++); + set(this, 'id', id++); } }, template: 'x-foo: {{@name}} ({{this.id}})', @@ -193,7 +194,7 @@ moduleFor( tagName = ''; init() { super.init(...arguments); - this.set('id', id++); + set(this, 'id', id++); } }, template: 'x-bar ({{this.id}})', diff --git a/packages/@ember/-internals/glimmer/tests/integration/application/rendering-test.js b/packages/@ember/-internals/glimmer/tests/integration/application/rendering-test.js index 3e32631ff08..4b8cf95337b 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/application/rendering-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/application/rendering-test.js @@ -531,7 +531,7 @@ moduleFor( ComponentClass: class extends Component { init() { super.init(...arguments); - this.set('person.name', 'Ben'); + set(this, 'person.name', 'Ben'); } }, template: 'Hi {{this.person.name}} from component', diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/angle-bracket-invocation-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/angle-bracket-invocation-test.js index e35a7cf125b..6d18affa947 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/angle-bracket-invocation-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/angle-bracket-invocation-test.js @@ -427,11 +427,11 @@ moduleFor( this.assertText('Hola'); - runTask(() => this.context.set('model.bar', 'Hello')); + runTask(() => set(this.context, 'model.bar', 'Hello')); this.assertText('Hello'); - runTask(() => this.context.set('model', { bar: 'Hola' })); + runTask(() => set(this.context, 'model', { bar: 'Hola' })); this.assertText('Hola'); } @@ -453,11 +453,11 @@ moduleFor( this.assertText('Hola'); - runTask(() => this.context.set('model.bar', 'Hello')); + runTask(() => set(this.context, 'model.bar', 'Hello')); this.assertText('Hello'); - runTask(() => this.context.set('model', { bar: 'Hola' })); + runTask(() => set(this.context, 'model', { bar: 'Hola' })); this.assertText('Hola'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/attribute-bindings-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/attribute-bindings-test.js index a4c296e36b6..171e5a51bac 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/attribute-bindings-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/attribute-bindings-test.js @@ -1,6 +1,6 @@ import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers'; -import { set } from '@ember/object'; +import { get, set } from '@ember/object'; import { Component } from '../../utils/helpers'; @@ -720,11 +720,11 @@ moduleFor( let bindings = []; - if (this.get('hasFoo')) { + if (get(this, 'hasFoo')) { bindings.push('foo:data-foo'); } - if (this.get('hasBar')) { + if (get(this, 'hasBar')) { bindings.push('bar:data-bar'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/attrs-lookup-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/attrs-lookup-test.js index 9692d380469..37a323841ad 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/attrs-lookup-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/attrs-lookup-test.js @@ -1,6 +1,6 @@ import { moduleFor, RenderingTestCase, styles, runTask } from 'internal-test-helpers'; -import { set, computed } from '@ember/object'; +import { get, set, computed } from '@ember/object'; import { Component, htmlSafe } from '../../utils/helpers'; @@ -47,15 +47,15 @@ moduleFor( firstAttr: 'first attr', }); - assert.equal(instance.get('first'), 'first attr'); + assert.equal(get(instance, 'first'), 'first attr'); runTask(() => this.rerender()); - assert.equal(instance.get('first'), 'first attr'); + assert.equal(get(instance, 'first'), 'first attr'); runTask(() => set(this.context, 'firstAttr', 'second attr')); - assert.equal(instance.get('first'), 'second attr'); + assert.equal(get(instance, 'first'), 'second attr'); runTask(() => set(this.context, 'firstAttr', 'first attr')); @@ -71,7 +71,7 @@ moduleFor( } didReceiveAttrs() { - this.set('first', this.get('first').toUpperCase()); + set(this, 'first', get(this, 'first').toUpperCase()); } }; this.registerComponent('foo-bar', { @@ -81,13 +81,13 @@ moduleFor( this.render(`{{foo-bar first="first attr"}}`); - assert.equal(instance.get('first'), 'FIRST ATTR', 'component lookup uses local state'); + assert.equal(get(instance, 'first'), 'FIRST ATTR', 'component lookup uses local state'); this.assertText('FIRST ATTR'); runTask(() => this.rerender()); assert.equal( - instance.get('first'), + get(instance, 'first'), 'FIRST ATTR', 'component lookup uses local state during rerender' ); @@ -108,7 +108,7 @@ moduleFor( } didReceiveAttrs() { - assert.equal(this.get('woot'), wootVal, 'found attr in didReceiveAttrs'); + assert.equal(get(this, 'woot'), wootVal, 'found attr in didReceiveAttrs'); } }; this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); @@ -117,25 +117,25 @@ moduleFor( woot: wootVal, }); - assert.equal(instance.get('woot'), 'yes', 'component found attr'); + assert.equal(get(instance, 'woot'), 'yes', 'component found attr'); runTask(() => this.rerender()); - assert.equal(instance.get('woot'), 'yes', 'component found attr after rerender'); + assert.equal(get(instance, 'woot'), 'yes', 'component found attr after rerender'); runTask(() => { wootVal = 'nope'; set(this.context, 'woot', wootVal); }); - assert.equal(instance.get('woot'), 'nope', 'component found attr after attr change'); + assert.equal(get(instance, 'woot'), 'nope', 'component found attr after attr change'); runTask(() => { wootVal = 'yes'; set(this.context, 'woot', wootVal); }); - assert.equal(instance.get('woot'), 'yes', 'component found attr after reset'); + assert.equal(get(instance, 'woot'), 'yes', 'component found attr after reset'); } ['@test getAttr() should return the same value as get()'](assert) { @@ -149,9 +149,9 @@ moduleFor( } didReceiveAttrs() { - let rootFirstPositional = this.get('firstPositional'); - let rootFirst = this.get('first'); - let rootSecond = this.get('second'); + let rootFirstPositional = get(this, 'firstPositional'); + let rootFirst = get(this, 'first'); + let rootSecond = get(this, 'second'); let attrFirstPositional = this.getAttr('firstPositional'); let attrFirst = this.getAttr('first'); let attrSecond = this.getAttr('second'); @@ -178,39 +178,39 @@ moduleFor( second: 'second', }); - assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); - assert.equal(instance.get('first'), 'first', 'matches known value'); - assert.equal(instance.get('second'), 'second', 'matches known value'); + assert.equal(get(instance, 'firstPositional'), 'firstPositional', 'matches known value'); + assert.equal(get(instance, 'first'), 'first', 'matches known value'); + assert.equal(get(instance, 'second'), 'second', 'matches known value'); runTask(() => this.rerender()); - assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); - assert.equal(instance.get('first'), 'first', 'matches known value'); - assert.equal(instance.get('second'), 'second', 'matches known value'); + assert.equal(get(instance, 'firstPositional'), 'firstPositional', 'matches known value'); + assert.equal(get(instance, 'first'), 'first', 'matches known value'); + assert.equal(get(instance, 'second'), 'second', 'matches known value'); runTask(() => { set(this.context, 'first', 'third'); }); - assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); - assert.equal(instance.get('first'), 'third', 'matches known value'); - assert.equal(instance.get('second'), 'second', 'matches known value'); + assert.equal(get(instance, 'firstPositional'), 'firstPositional', 'matches known value'); + assert.equal(get(instance, 'first'), 'third', 'matches known value'); + assert.equal(get(instance, 'second'), 'second', 'matches known value'); runTask(() => { set(this.context, 'second', 'fourth'); }); - assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); - assert.equal(instance.get('first'), 'third', 'matches known value'); - assert.equal(instance.get('second'), 'fourth', 'matches known value'); + assert.equal(get(instance, 'firstPositional'), 'firstPositional', 'matches known value'); + assert.equal(get(instance, 'first'), 'third', 'matches known value'); + assert.equal(get(instance, 'second'), 'fourth', 'matches known value'); runTask(() => { set(this.context, 'firstPositional', 'fifth'); }); - assert.equal(instance.get('firstPositional'), 'fifth', 'matches known value'); - assert.equal(instance.get('first'), 'third', 'matches known value'); - assert.equal(instance.get('second'), 'fourth', 'matches known value'); + assert.equal(get(instance, 'firstPositional'), 'fifth', 'matches known value'); + assert.equal(get(instance, 'first'), 'third', 'matches known value'); + assert.equal(get(instance, 'second'), 'fourth', 'matches known value'); runTask(() => { set(this.context, 'firstPositional', 'firstPositional'); @@ -218,9 +218,9 @@ moduleFor( set(this.context, 'second', 'second'); }); - assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); - assert.equal(instance.get('first'), 'first', 'matches known value'); - assert.equal(instance.get('second'), 'second', 'matches known value'); + assert.equal(get(instance, 'firstPositional'), 'firstPositional', 'matches known value'); + assert.equal(get(instance, 'first'), 'first', 'matches known value'); + assert.equal(get(instance, 'second'), 'second', 'matches known value'); } ['@test bound computed properties can be overridden in extensions, set during init, and passed in as attrs']() { @@ -228,8 +228,8 @@ moduleFor( attributeBindings = ['style']; @computed('height', 'color') get style() { - let height = this.get('height'); - let color = this.get('color'); + let height = get(this, 'height'); + let color = get(this, 'color'); return htmlSafe(`height: ${height}px; background-color: ${color};`); } color = 'red'; diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/class-bindings-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/class-bindings-test.js index 56827af4aac..fa1bcf88aab 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/class-bindings-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/class-bindings-test.js @@ -1,6 +1,6 @@ import { moduleFor, RenderingTestCase, strip, classes, runTask } from 'internal-test-helpers'; -import { set, computed } from '@ember/object'; +import { get, set, computed } from '@ember/object'; import { Component } from '../../utils/helpers'; @@ -394,11 +394,11 @@ moduleFor( let bindings = (this.classNameBindings = this.classNameBindings.slice()); - if (this.get('bindIsEnabled')) { + if (get(this, 'bindIsEnabled')) { bindings.push('isEnabled:enabled'); } - if (this.get('bindIsHappy')) { + if (get(this, 'bindIsHappy')) { bindings.push('isHappy:happy:sad'); } } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js index 6d3bb671f43..3a03238f6d9 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js @@ -2,7 +2,7 @@ import { DEBUG } from '@glimmer/env'; import { moduleFor, RenderingTestCase, applyMixins, strip, runTask } from 'internal-test-helpers'; import { isEmpty } from '@ember/utils'; -import { action } from '@ember/object'; +import { action, get, set } from '@ember/object'; import { Component } from '../../utils/helpers'; @@ -66,15 +66,15 @@ moduleFor( this.assertText('Gabon Zack'); - runTask(() => this.context.set('model.greeting', 'Good morning ')); + runTask(() => set(this.context, 'model.greeting', 'Good morning ')); this.assertText('Good morning Zack'); - runTask(() => this.context.set('model.name', 'Matthew')); + runTask(() => set(this.context, 'model.name', 'Matthew')); this.assertText('Good morning Matthew'); - runTask(() => this.context.set('model', { greeting: 'Gabon ', name: 'Zack' })); + runTask(() => set(this.context, 'model', { greeting: 'Gabon ', name: 'Zack' })); this.assertText('Gabon Zack'); } @@ -104,15 +104,15 @@ moduleFor( this.assertText('Gabon Zack Zack Gabon '); - runTask(() => this.context.set('model.greeting', 'Good morning ')); + runTask(() => set(this.context, 'model.greeting', 'Good morning ')); this.assertText('Good morning Zack Zack Good morning '); - runTask(() => this.context.set('model.name', 'Matthew ')); + runTask(() => set(this.context, 'model.name', 'Matthew ')); this.assertText('Good morning Matthew Matthew Good morning '); - runTask(() => this.context.set('model', { greeting: 'Gabon ', name: 'Zack ' })); + runTask(() => set(this.context, 'model', { greeting: 'Gabon ', name: 'Zack ' })); this.assertText('Gabon Zack Zack Gabon '); } @@ -141,15 +141,15 @@ moduleFor( this.assertText('Gabon Zack'); - runTask(() => this.context.set('model.greeting', 'Good morning ')); + runTask(() => set(this.context, 'model.greeting', 'Good morning ')); this.assertText('Good morning Zack'); - runTask(() => this.context.set('model.name', 'Matthew')); + runTask(() => set(this.context, 'model.name', 'Matthew')); this.assertText('Good morning Matthew'); - runTask(() => this.context.set('model', { greeting: 'Gabon ', name: 'Zack' })); + runTask(() => set(this.context, 'model', { greeting: 'Gabon ', name: 'Zack' })); this.assertText('Gabon Zack'); } @@ -178,15 +178,15 @@ moduleFor( this.assertText('Gabon Zack Zack Gabon '); - runTask(() => this.context.set('model.greeting', 'Good morning ')); + runTask(() => set(this.context, 'model.greeting', 'Good morning ')); this.assertText('Good morning Zack Zack Good morning '); - runTask(() => this.context.set('model.name', 'Matthew ')); + runTask(() => set(this.context, 'model.name', 'Matthew ')); this.assertText('Good morning Matthew Matthew Good morning '); - runTask(() => this.context.set('model', { greeting: 'Gabon ', name: 'Zack ' })); + runTask(() => set(this.context, 'model', { greeting: 'Gabon ', name: 'Zack ' })); this.assertText('Gabon Zack Zack Gabon '); } @@ -231,11 +231,11 @@ moduleFor( this.assertText('ni hao'); - runTask(() => this.context.set('model.lookupComponent', '-hindi')); + runTask(() => set(this.context, 'model.lookupComponent', '-hindi')); this.assertText('Namaste'); - runTask(() => this.context.set('model', { lookupComponent: '-mandarin' })); + runTask(() => set(this.context, 'model', { lookupComponent: '-mandarin' })); this.assertText('ni hao'); } @@ -257,11 +257,11 @@ moduleFor( this.assertText('Hodi'); - runTask(() => this.context.set('model.greeting', 'Hola')); + runTask(() => set(this.context, 'model.greeting', 'Hola')); this.assertText('Hola'); - runTask(() => this.context.set('model', { greeting: 'Hodi' })); + runTask(() => set(this.context, 'model', { greeting: 'Hodi' })); this.assertText('Hodi'); } @@ -289,11 +289,11 @@ moduleFor( this.assertText('Hodi'); - runTask(() => this.context.set('model.greeting', 'Hola')); + runTask(() => set(this.context, 'model.greeting', 'Hola')); this.assertText('Hola'); - runTask(() => this.context.set('model', { greeting: 'Hodi' })); + runTask(() => set(this.context, 'model', { greeting: 'Hodi' })); this.assertText('Hodi'); } @@ -359,11 +359,11 @@ moduleFor( this.assertText('Hodi Sigmundur 33'); - runTask(() => this.context.set('model.greeting', 'Kaixo')); + runTask(() => set(this.context, 'model.greeting', 'Kaixo')); this.assertText('Kaixo Sigmundur 33'); - runTask(() => this.context.set('model', { greeting: 'Hodi' })); + runTask(() => set(this.context, 'model', { greeting: 'Hodi' })); this.assertText('Hodi Sigmundur 33'); } @@ -399,16 +399,16 @@ moduleFor( this.assertText('Outer 28'); - runTask(() => this.context.set('model.outerAge', 29)); + runTask(() => set(this.context, 'model.outerAge', 29)); this.assertText('Outer 29'); - runTask(() => this.context.set('model.outerName', 'Not outer')); + runTask(() => set(this.context, 'model.outerName', 'Not outer')); this.assertText('Not outer 29'); runTask(() => { - this.context.set('model', { + set(this.context, 'model', { outerName: 'Outer', outerAge: 28, }); @@ -445,16 +445,16 @@ moduleFor( this.assertText('Inner 28'); - runTask(() => this.context.set('model.outerAge', 29)); + runTask(() => set(this.context, 'model.outerAge', 29)); this.assertText('Inner 29'); - runTask(() => this.context.set('model.outerName', 'Not outer')); + runTask(() => set(this.context, 'model.outerName', 'Not outer')); this.assertText('Inner 29'); runTask(() => { - this.context.set('model', { + set(this.context, 'model', { outerName: 'Outer', outerAge: 28, }); @@ -485,11 +485,11 @@ moduleFor( this.assertText('Hodi Hodari'); - runTask(() => this.context.set('model.name', 'Sergio')); + runTask(() => set(this.context, 'model.name', 'Sergio')); this.assertText('Hodi Sergio'); - runTask(() => this.context.set('model', { name: 'Hodari' })); + runTask(() => set(this.context, 'model', { name: 'Hodari' })); this.assertText('Hodi Hodari'); } @@ -508,11 +508,11 @@ moduleFor( this.assertText(''); - runTask(() => this.context.set('componentName', 'foo-bar')); + runTask(() => set(this.context, 'componentName', 'foo-bar')); this.assertText('hello Alex'); - runTask(() => this.context.set('componentName', undefined)); + runTask(() => set(this.context, 'componentName', undefined)); this.assertText(''); } @@ -531,11 +531,11 @@ moduleFor( this.assertText('hello Alex'); - runTask(() => this.context.set('componentName', undefined)); + runTask(() => set(this.context, 'componentName', undefined)); this.assertText(''); - runTask(() => this.context.set('componentName', 'foo-bar')); + runTask(() => set(this.context, 'componentName', 'foo-bar')); this.assertText('hello Alex'); } @@ -554,11 +554,11 @@ moduleFor( this.assertText(''); - runTask(() => this.context.set('componentName', 'foo-bar')); + runTask(() => set(this.context, 'componentName', 'foo-bar')); this.assertText('hello Alex'); - runTask(() => this.context.set('componentName', null)); + runTask(() => set(this.context, 'componentName', null)); this.assertText(''); } @@ -577,11 +577,11 @@ moduleFor( this.assertText('hello Alex'); - runTask(() => this.context.set('componentName', null)); + runTask(() => set(this.context, 'componentName', null)); this.assertText(''); - runTask(() => this.context.set('componentName', 'foo-bar')); + runTask(() => set(this.context, 'componentName', 'foo-bar')); this.assertText('hello Alex'); } @@ -652,11 +652,11 @@ moduleFor( this.assertText(expectedText); - runTask(() => this.context.set('model.expectedText', 'Hola')); + runTask(() => set(this.context, 'model.expectedText', 'Hola')); this.assertText('Hola'); - runTask(() => this.context.set('model', { expectedText })); + runTask(() => set(this.context, 'model', { expectedText })); this.assertText(expectedText); } @@ -685,11 +685,11 @@ moduleFor( this.assertText(expectedText); - runTask(() => this.context.set('model.expectedText', 'Hola')); + runTask(() => set(this.context, 'model.expectedText', 'Hola')); this.assertText('Hola'); - runTask(() => this.context.set('model', { expectedText })); + runTask(() => set(this.context, 'model', { expectedText })); this.assertText(expectedText); } @@ -722,11 +722,11 @@ moduleFor( this.assertText(`${expectedText},Hola`); - runTask(() => this.context.set('model.expectedText', 'Kaixo')); + runTask(() => set(this.context, 'model.expectedText', 'Kaixo')); this.assertText('Kaixo,Hola'); - runTask(() => this.context.set('model', { expectedText })); + runTask(() => set(this.context, 'model', { expectedText })); this.assertText(`${expectedText},Hola`); } @@ -764,7 +764,7 @@ moduleFor( static positionalParams = ['my-parent-attr']; didReceiveAttrs() { - this.set('myProp', this.getAttr('my-parent-attr')); + set(this, 'myProp', this.getAttr('my-parent-attr')); } }, template: '{{this.myProp}}', @@ -779,7 +779,7 @@ moduleFor( ComponentClass: class extends Component { @action changeValue() { - this.incrementProperty('myProp'); + set(this, 'myProp', this.myProp + 1); } }, template: strip` @@ -810,7 +810,7 @@ moduleFor( assert.equal(this.$('#nested-prop').text(), '3'); - runTask(() => this.context.set('model', { myProp: 1 })); + runTask(() => set(this.context, 'model', { myProp: 1 })); assert.equal(this.$('#nested-prop').text(), '1'); } @@ -873,7 +873,7 @@ moduleFor( assert.equal(this.$('.value').text(), '10'); - runTask(() => this.context.set('model', { val2: 8 })); + runTask(() => set(this.context, 'model', { val2: 8 })); assert.equal(this.$('.value').text(), '8'); } @@ -898,7 +898,7 @@ moduleFor( message = 'hello'; @action change() { - this.set('message', 'goodbye'); + set(this, 'message', 'goodbye'); } }, template: strip` @@ -969,7 +969,7 @@ moduleFor( assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'open', 'the components text is "open"'); - runTask(() => this.context.set('isOpen', false)); + runTask(() => set(this.context, 'isOpen', false)); assert.ok(!isEmpty(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); @@ -983,7 +983,7 @@ moduleFor( assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'closed', 'the component text is "closed"'); - runTask(() => this.context.set('isOpen', true)); + runTask(() => set(this.context, 'isOpen', true)); assert.ok(!isEmpty(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); @@ -1034,7 +1034,7 @@ moduleFor( assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'open', 'the components text is "open"'); - runTask(() => this.context.set('isOpen', false)); + runTask(() => set(this.context, 'isOpen', false)); assert.ok(!isEmpty(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); @@ -1048,7 +1048,7 @@ moduleFor( assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'closed', 'the component text is "closed"'); - runTask(() => this.context.set('isOpen', true)); + runTask(() => set(this.context, 'isOpen', true)); assert.ok(!isEmpty(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); @@ -1112,7 +1112,7 @@ moduleFor( assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'my-comp: open'); - runTask(() => this.context.set('compName', 'your-comp')); + runTask(() => set(this.context, 'compName', 'your-comp')); assert.ok(!isEmpty(instance), 'an instance was created after component name changed'); assert.ok(!isEmpty(previousInstance), 'a previous instance now exists'); @@ -1139,7 +1139,7 @@ moduleFor( assert.equal(initCount, 2, 'the component was constructed exactly 2 times (rerender)'); assert.equal(this.$().text(), 'your-comp: open'); - runTask(() => this.context.set('compName', 'my-comp')); + runTask(() => set(this.context, 'compName', 'my-comp')); assert.ok(!isEmpty(instance), 'an instance was created after component name changed'); assert.ok(!isEmpty(previousInstance), 'a previous instance still exists'); @@ -1170,23 +1170,23 @@ moduleFor( this.assertText('ab'); - runTask(() => this.context.get('allParams').push('c')); + runTask(() => get(this.context, 'allParams').push('c')); this.assertText('abc'); - runTask(() => this.context.get('allParams').pop()); + runTask(() => get(this.context, 'allParams').pop()); this.assertText('ab'); - runTask(() => this.context.get('allParams').splice(0, 2)); + runTask(() => get(this.context, 'allParams').splice(0, 2)); this.assertText(''); - runTask(() => this.context.set('allParams', ['1', '2'])); + runTask(() => set(this.context, 'allParams', ['1', '2'])); this.assertText('12'); - runTask(() => this.context.set('allParams', ['a', 'b'])); + runTask(() => set(this.context, 'allParams', ['a', 'b'])); this.assertText('ab'); } @@ -1212,23 +1212,23 @@ moduleFor( this.assertText('ab'); - runTask(() => this.context.get('allParams').push('c')); + runTask(() => get(this.context, 'allParams').push('c')); this.assertText('abc'); - runTask(() => this.context.get('allParams').pop()); + runTask(() => get(this.context, 'allParams').pop()); this.assertText('ab'); - runTask(() => this.context.get('allParams').splice(0, 3)); + runTask(() => get(this.context, 'allParams').splice(0, 3)); this.assertText(''); - runTask(() => this.context.set('allParams', ['1', '2'])); + runTask(() => set(this.context, 'allParams', ['1', '2'])); this.assertText('12'); - runTask(() => this.context.set('allParams', ['a', 'b'])); + runTask(() => set(this.context, 'allParams', ['a', 'b'])); this.assertText('ab'); } @@ -1250,11 +1250,11 @@ moduleFor( this.assertStableRerender(); - runTask(() => this.context.set('value', 'bar')); + runTask(() => set(this.context, 'value', 'bar')); this.assert.strictEqual('bar', this.firstChild.value); - runTask(() => this.context.set('value', 'foo')); + runTask(() => set(this.context, 'value', 'foo')); this.assert.strictEqual('foo', this.firstChild.value); } @@ -1275,11 +1275,11 @@ moduleFor( this.assertStableRerender(); - runTask(() => this.context.set('value', 'bar')); + runTask(() => set(this.context, 'value', 'bar')); this.assert.strictEqual('bar', this.firstChild.value); - runTask(() => this.context.set('value', 'foo')); + runTask(() => set(this.context, 'value', 'foo')); this.assert.strictEqual('foo', this.firstChild.value); } @@ -1467,7 +1467,7 @@ class MutableParamTestGenerator { assert.equal(this.$('.value').text(), '10'); - runTask(() => this.context.set('model', { val2: 8 })); + runTask(() => set(this.context, 'model', { val2: 8 })); assert.equal(this.$('.value').text(), '8'); }, diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js index d92fd4aa6a4..819128e6156 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js @@ -6,7 +6,6 @@ import { equalTokens, equalsElement, runTask, - runLoopSettled, } from 'internal-test-helpers'; import { tracked as trackedBuiltIn } from 'tracked-built-ins'; @@ -17,7 +16,7 @@ import { DEBUG } from '@glimmer/env'; import { tracked } from '@ember/-internals/metal'; import { alias } from '@ember/object/computed'; import Service, { service } from '@ember/service'; -import EmberObject, { set, get, computed, observer } from '@ember/object'; +import EmberObject, { set, get, computed } from '@ember/object'; import { Component, compile, htmlSafe } from '../../utils/helpers'; import { backtrackingMessageFor } from '../../utils/debug-stack'; @@ -502,7 +501,7 @@ moduleFor( init() { super.init(...arguments); this.classNames = this.classNames.slice(); - this.classNames.push('foo', 'bar', `outside-${this.get('extraClass')}`); + this.classNames.push('foo', 'bar', `outside-${get(this, 'extraClass')}`); } }; @@ -699,11 +698,11 @@ moduleFor( this.assertText('Hola'); - runTask(() => this.context.set('model.bar', 'Hello')); + runTask(() => set(this.context, 'model.bar', 'Hello')); this.assertText('Hello'); - runTask(() => this.context.set('model', { bar: 'Hola' })); + runTask(() => set(this.context, 'model', { bar: 'Hola' })); this.assertText('Hola'); } @@ -725,11 +724,11 @@ moduleFor( this.assertText('Hola'); - runTask(() => this.context.set('model.bar', 'Hello')); + runTask(() => set(this.context, 'model.bar', 'Hello')); this.assertText('Hello'); - runTask(() => this.context.set('model', { bar: 'Hola' })); + runTask(() => set(this.context, 'model', { bar: 'Hola' })); this.assertText('Hola'); } @@ -759,7 +758,7 @@ moduleFor( init() { super.init(...arguments); instance = this; - this.set('message', 'hello'); + set(this, 'message', 'hello'); } }; @@ -1258,11 +1257,11 @@ moduleFor( this.assertStableRerender(); - runTask(() => this.context.set('somecomponent', 'not not notsomecomponent')); + runTask(() => set(this.context, 'somecomponent', 'not not notsomecomponent')); this.assertText('somecomponent'); - runTask(() => this.context.set('somecomponent', 'notsomecomponent')); + runTask(() => set(this.context, 'somecomponent', 'notsomecomponent')); this.assertText('somecomponent'); } @@ -1293,11 +1292,11 @@ moduleFor( this.assertText('In layout - someProp: something here'); - runTask(() => this.context.set('prop', 'other thing there')); + runTask(() => set(this.context, 'prop', 'other thing there')); this.assertText('In layout - someProp: other thing there'); - runTask(() => this.context.set('prop', 'something here')); + runTask(() => set(this.context, 'prop', 'something here')); this.assertText('In layout - someProp: something here'); } @@ -1317,11 +1316,11 @@ moduleFor( this.assertText('In layout - someProp: something here'); - runTask(() => this.context.set('prop', 'other thing there')); + runTask(() => set(this.context, 'prop', 'other thing there')); this.assertText('In layout - someProp: other thing there'); - runTask(() => this.context.set('prop', 'something here')); + runTask(() => set(this.context, 'prop', 'something here')); this.assertText('In layout - someProp: something here'); } @@ -1349,16 +1348,16 @@ moduleFor( this.assertText('In layout - someProp: value set in instance'); - runTask(() => this.context.set('prop', 'updated something passed when invoked')); + runTask(() => set(this.context, 'prop', 'updated something passed when invoked')); this.assertText('In layout - someProp: updated something passed when invoked'); - runTask(() => instance.set('someProp', 'update value set in instance')); + runTask(() => set(instance, 'someProp', 'update value set in instance')); this.assertText('In layout - someProp: update value set in instance'); - runTask(() => this.context.set('prop', 'something passed when invoked')); - runTask(() => instance.set('someProp', 'value set in instance')); + runTask(() => set(this.context, 'prop', 'something passed when invoked')); + runTask(() => set(instance, 'someProp', 'value set in instance')); this.assertText('In layout - someProp: value set in instance'); } @@ -1415,7 +1414,7 @@ moduleFor( this.assertText('In layout - someProp: wycats'); expectHooks({ willUpdate: true, didReceiveAttrs: true }, () => { - runTask(() => this.context.set('someProp', 'tomdale')); + runTask(() => set(this.context, 'someProp', 'tomdale')); }); this.assertText('In layout - someProp: tomdale'); @@ -1428,7 +1427,7 @@ moduleFor( this.assertText('In layout - someProp: tomdale'); expectHooks({ willUpdate: true, didReceiveAttrs: true }, () => { - runTask(() => this.context.set('someProp', 'wycats')); + runTask(() => set(this.context, 'someProp', 'wycats')); }); this.assertText('In layout - someProp: wycats'); @@ -1454,15 +1453,15 @@ moduleFor( @action myClick() { - let currentCounter = this.get('counter'); + let currentCounter = get(this, 'counter'); assert.equal(currentCounter, 0, 'the current `counter` value is correct'); let newCounter = currentCounter + 1; - this.set('counter', newCounter); + set(this, 'counter', newCounter); assert.equal( - this.get('counter'), + get(this, 'counter'), newCounter, "getting the newly set `counter` property works; it's equal to the value we just set and not `undefined`" ); @@ -1480,7 +1479,7 @@ moduleFor( runTask(() => this.$('button').click()); assert.equal( - componentInstance.get('counter'), + get(componentInstance, 'counter'), 1, '`counter` incremented on click on the component and is not `undefined`' ); @@ -1515,13 +1514,13 @@ moduleFor( this.assertStableRerender(); runTask(() => { - this.context.set('model.value', 'lul'); - this.context.set('model.items', [1]); + set(this.context, 'model.value', 'lul'); + set(this.context, 'model.items', [1]); }); this.assertText(strip`Args: lul | lul | lul111`); - runTask(() => this.context.set('model', { value: 'wat', items: [1, 2, 3] })); + runTask(() => set(this.context, 'model', { value: 'wat', items: [1, 2, 3] })); this.assertText('Args: wat | wat | wat123123123'); } @@ -1541,11 +1540,11 @@ moduleFor( this.assertText('In layout - someProp: something here'); - runTask(() => this.context.set('prop', 'something else')); + runTask(() => set(this.context, 'prop', 'something else')); this.assertText('In layout - someProp: something else'); - runTask(() => this.context.set('prop', 'something here')); + runTask(() => set(this.context, 'prop', 'something here')); this.assertText('In layout - someProp: something here'); } @@ -1571,11 +1570,11 @@ moduleFor( this.assertText('In layout - someProp: something here - In template'); - runTask(() => this.context.set('prop', 'something else')); + runTask(() => set(this.context, 'prop', 'something else')); this.assertText('In layout - someProp: something else - In template'); - runTask(() => this.context.set('prop', 'something here')); + runTask(() => set(this.context, 'prop', 'something here')); this.assertText('In layout - someProp: something here - In template'); } @@ -1612,11 +1611,11 @@ moduleFor( this.assertText('In layout - someProp: something here - In template'); - runTask(() => this.context.set('prop', 'something else')); + runTask(() => set(this.context, 'prop', 'something else')); this.assertText('In layout - someProp: something else - In template'); - runTask(() => this.context.set('prop', 'something here')); + runTask(() => set(this.context, 'prop', 'something here')); this.assertText('In layout - someProp: something here - In template'); } @@ -1642,11 +1641,11 @@ moduleFor( this.assertText('In layout - someProp: something here - In template'); - runTask(() => this.context.set('prop', 'something else')); + runTask(() => set(this.context, 'prop', 'something else')); this.assertText('In layout - someProp: something else - In template'); - runTask(() => this.context.set('prop', 'something here')); + runTask(() => set(this.context, 'prop', 'something here')); this.assertText('In layout - someProp: something here - In template'); } @@ -1714,19 +1713,19 @@ moduleFor( this.assertText('Foo4Bar'); - runTask(() => this.context.get('things').push(5)); + runTask(() => get(this.context, 'things').push(5)); this.assertText('Foo4Bar5'); - runTask(() => this.context.get('things').shift()); + runTask(() => get(this.context, 'things').shift()); this.assertText('4Bar5'); - runTask(() => this.context.get('things').splice(0, 3)); + runTask(() => get(this.context, 'things').splice(0, 3)); this.assertText(''); - runTask(() => this.context.set('things', ['Foo', 4, 'Bar'])); + runTask(() => set(this.context, 'things', ['Foo', 4, 'Bar'])); this.assertText('Foo4Bar'); } @@ -1778,17 +1777,17 @@ moduleFor( this.assertText('Foo4'); - runTask(() => this.context.set('user1', 'Bar')); + runTask(() => set(this.context, 'user1', 'Bar')); this.assertText('Bar4'); - runTask(() => this.context.set('user2', '5')); + runTask(() => set(this.context, 'user2', '5')); this.assertText('Bar5'); runTask(() => { - this.context.set('user1', 'Foo'); - this.context.set('user2', 4); + set(this.context, 'user1', 'Foo'); + set(this.context, 'user2', 4); }); this.assertText('Foo4'); @@ -1809,13 +1808,13 @@ moduleFor( this.assertComponentElement(this.firstChild, { attrs: { role: 'main' } }); - runTask(() => this.context.set('role', 'input')); + runTask(() => set(this.context, 'role', 'input')); this.assertComponentElement(this.firstChild, { attrs: { role: 'input' }, }); - runTask(() => this.context.set('role', 'main')); + runTask(() => set(this.context, 'role', 'main')); this.assertComponentElement(this.firstChild, { attrs: { role: 'main' } }); } @@ -1835,13 +1834,13 @@ moduleFor( this.assertComponentElement(this.firstChild, { attrs: {} }); - runTask(() => this.context.set('role', 'input')); + runTask(() => set(this.context, 'role', 'input')); this.assertComponentElement(this.firstChild, { attrs: { role: 'input' }, }); - runTask(() => this.context.set('role', undefined)); + runTask(() => set(this.context, 'role', undefined)); this.assertComponentElement(this.firstChild, { attrs: {} }); } @@ -1868,7 +1867,7 @@ moduleFor( this.assertComponentElement(this.firstChild, { attrs: {} }); - runTask(() => instance.set('ariaRole', 'input')); + runTask(() => set(instance, 'ariaRole', 'input')); this.assertComponentElement(this.firstChild, { attrs: {} }); } @@ -1902,11 +1901,11 @@ moduleFor( '[In layout - with-block] [In block - Whoop, whoop!][In layout - without-block] ' ); - runTask(() => this.context.set('name', 'Ole, ole')); + runTask(() => set(this.context, 'name', 'Ole, ole')); this.assertText('[In layout - with-block] [In block - Ole, ole][In layout - without-block] '); - runTask(() => this.context.set('name', 'Whoop, whoop!')); + runTask(() => set(this.context, 'name', 'Whoop, whoop!')); this.assertText( '[In layout - with-block] [In block - Whoop, whoop!][In layout - without-block] ' @@ -2034,17 +2033,17 @@ moduleFor( this.assertText('Quint4'); - runTask(() => this.context.set('myName', 'Sergio')); + runTask(() => set(this.context, 'myName', 'Sergio')); this.assertText('Sergio4'); - runTask(() => this.context.set('myAge', 2)); + runTask(() => set(this.context, 'myAge', 2)); this.assertText('Sergio2'); runTask(() => { - this.context.set('myName', 'Quint'); - this.context.set('myAge', 4); + set(this.context, 'myName', 'Quint'); + set(this.context, 'myAge', 4); }); this.assertText('Quint4'); @@ -2094,11 +2093,11 @@ moduleFor( this.assertText('Yes:Hello42'); - runTask(() => this.context.set('activated', false)); + runTask(() => set(this.context, 'activated', false)); this.assertText('No:Goodbye'); - runTask(() => this.context.set('activated', true)); + runTask(() => set(this.context, 'activated', true)); this.assertText('Yes:Hello42'); } @@ -2428,7 +2427,7 @@ moduleFor( 'x-outer receives the ambient scope as its parentView (after rerender)' ); - runTask(() => this.context.set('showInner', true)); + runTask(() => set(this.context, 'showInner', true)); assert.equal( outer.parentView, @@ -2441,7 +2440,7 @@ moduleFor( 'receives the wrapping component as its parentView in template blocks' ); - runTask(() => this.context.set('showInner', false)); + runTask(() => set(this.context, 'showInner', false)); assert.equal( outer.parentView, @@ -2475,7 +2474,7 @@ moduleFor( ComponentClass: class extends Component { value = null; didReceiveAttrs() { - middle.set('value', this.get('value')); + set(middle, 'value', get(this, 'value')); } }, template: '
{{value}}
', @@ -2503,7 +2502,7 @@ moduleFor( this.registerComponent('x-inner', { ComponentClass: class extends Component { didReceiveAttrs() { - this.get('wrapper').set('content', this.get('value')); + set(get(this, 'wrapper'), 'content', get(this, 'value')); } value = null; }, @@ -2536,7 +2535,7 @@ moduleFor( this.registerComponent('x-inner', { ComponentClass: class extends Component { didReceiveAttrs() { - this.get('wrapper').content = this.get('value'); + get(this, 'wrapper').content = get(this, 'value'); } value = null; }, @@ -2574,15 +2573,15 @@ moduleFor( this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]'); - runTask(() => this.context.get('items').push('Sergio')); + runTask(() => get(this.context, 'items').push('Sergio')); this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.][Child: Sergio.]'); - runTask(() => this.context.get('items').shift()); + runTask(() => get(this.context, 'items').shift()); this.assertText('In layout. [Child: Dick.][Child: Harry.][Child: Sergio.]'); - runTask(() => this.context.set('items', ['Tom', 'Dick', 'Harry'])); + runTask(() => set(this.context, 'items', ['Tom', 'Dick', 'Harry'])); this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]'); } @@ -2609,7 +2608,7 @@ moduleFor( `the element has the correct classes: ${this.$('button').attr('class')}` ); // `ember-view` is no longer in classNames. - // assert.deepEqual(clickyThing.get('classNames'), expectedClassNames, 'classNames are properly combined'); + // assert.deepEqual(get(clickyThing, 'classNames'), expectedClassNames, 'classNames are properly combined'); this.assertComponentElement(this.firstChild, { tagName: 'button', attrs: { class: classes(expectedClassNames.join(' ')) }, @@ -2622,7 +2621,7 @@ moduleFor( `the element has the correct classes: ${this.$('button').attr('class')} (rerender)` ); // `ember-view` is no longer in classNames. - // assert.deepEqual(clickyThing.get('classNames'), expectedClassNames, 'classNames are properly combined (rerender)'); + // assert.deepEqual(get(clickyThing, 'classNames'), expectedClassNames, 'classNames are properly combined (rerender)'); this.assertComponentElement(this.firstChild, { tagName: 'button', attrs: { class: classes(expectedClassNames.join(' ')) }, @@ -2680,19 +2679,19 @@ moduleFor( this.assertText('initial value - initial value'); runTask(() => { - component.set('bar', 'updated value'); + set(component, 'bar', 'updated value'); }); this.assertText('updated value - updated value'); runTask(() => { - component.set('bar', undefined); + set(component, 'bar', undefined); }); this.assertText(' - '); runTask(() => { - this.component.set('localBar', 'initial value'); + set(this.component, 'localBar', 'initial value'); }); this.assertText('initial value - initial value'); @@ -2732,13 +2731,13 @@ moduleFor( this.assertText('initial value - initial value'); runTask(() => { - component.set('bar', 'updated value'); + set(component, 'bar', 'updated value'); }); this.assertText('updated value - updated value'); runTask(() => { - this.component.set('localBar', 'initial value'); + set(this.component, 'localBar', 'initial value'); }); this.assertText('initial value - initial value'); @@ -2778,13 +2777,13 @@ moduleFor( this.assertText('initial value'); runTask(() => { - component.set('bar', 'updated value'); + set(component, 'bar', 'updated value'); }); this.assertText('updated value'); runTask(() => { - this.component.set('localBar', 'initial value'); + set(this.component, 'localBar', 'initial value'); }); this.assertText('initial value'); @@ -2824,8 +2823,8 @@ moduleFor( set value(value) { let vals = value.split('|'); - this.set('a', vals[0]); - this.set('b', vals[1]); + set(this, 'a', vals[0]); + set(this, 'b', vals[1]); } }; @@ -2844,7 +2843,7 @@ moduleFor( ); runTask(() => { - child.set('a', 'Foo'); + set(child, 'a', 'Foo'); }); this.assert.equal(parent.string, 'Foo|World', 'parent value updated'); @@ -2856,7 +2855,7 @@ moduleFor( ); runTask(() => { - child.set('a', 'Hello'); + set(child, 'a', 'Hello'); }); this.assert.equal(parent.string, 'Hello|World', 'parent value reset'); @@ -2897,13 +2896,13 @@ moduleFor( this.assertText('Jackson'); runTask(() => { - serviceInstance.set('last', 'McGuffey'); + set(serviceInstance, 'last', 'McGuffey'); }); this.assertText('McGuffey'); runTask(() => { - serviceInstance.set('last', 'Jackson'); + set(serviceInstance, 'last', 'Jackson'); }); this.assertText('Jackson'); @@ -2959,7 +2958,7 @@ moduleFor( change() { let value = this.readDOMAttr('value'); - this.set('value', value); + set(this, 'value', value); } }, }); @@ -3012,21 +3011,21 @@ moduleFor( } updateValue() { - let newValue = this.get('options.lastObject.value'); + let newValue = get(this, 'options.lastObject.value'); - this.set('value', newValue); + set(this, 'value', newValue); } registerOption(option) { - if (this.get('options').indexOf(option) === -1) { - this.get('options').push(option); + if (get(this, 'options').indexOf(option) === -1) { + get(this, 'options').push(option); } } unregisterOption(option) { - let index = this.get('options').indexOf(option); + let index = get(this, 'options').indexOf(option); if (index > -1) { - this.get('options').splice(index, 1); + get(this, 'options').splice(index, 1); } this.updateValue(); @@ -3044,17 +3043,17 @@ moduleFor( didInsertElement() { super.didInsertElement(...arguments); - this.get('select').registerOption(this); + get(this, 'select').registerOption(this); } @computed('select.value') get selected() { - return this.get('value') === this.get('select.value'); + return get(this, 'value') === get(this, 'select.value'); } willDestroyElement() { super.willDestroyElement(...arguments); - this.get('select').unregisterOption(this); + get(this, 'select').unregisterOption(this); } }, }); @@ -3082,7 +3081,7 @@ moduleFor( } willDestroyElement() { - this.set('showFoo', false); + set(this, 'showFoo', false); assert.ok(true, 'willDestroyElement was fired'); super.willDestroyElement(...arguments); } @@ -3096,49 +3095,11 @@ moduleFor( this.assertText('things'); } - async ['@test didReceiveAttrs fires after .init() but before observers become active'](assert) { - let barCopyDidChangeCount = 0; - - this.registerComponent('foo-bar', { - ComponentClass: Component.extend({ - init() { - this._super(...arguments); - this.didInit = true; - }, - - didReceiveAttrs() { - assert.ok(this.didInit, 'expected init to have run before didReceiveAttrs'); - this.set('barCopy', this.attrs.bar.value + 1); - }, - - barCopyDidChange: observer('barCopy', () => { - barCopyDidChangeCount++; - }), - }), - - template: '{{this.bar}}-{{this.barCopy}}', - }); - - await this.render(`{{foo-bar bar=this.bar}}`, { bar: 3 }); - - this.assertText('3-4'); - - assert.strictEqual(barCopyDidChangeCount, 1, 'expected observer firing for: barCopy'); - - set(this.context, 'bar', 7); - - await runLoopSettled(); - - this.assertText('7-8'); - - assert.strictEqual(barCopyDidChangeCount, 2, 'expected observer firing for: barCopy'); - } - ['@test overriding didReceiveAttrs does not trigger deprecation'](assert) { this.registerComponent('foo-bar', { ComponentClass: class extends Component { didReceiveAttrs() { - assert.equal(1, this.get('foo'), 'expected attrs to have correct value'); + assert.equal(1, get(this, 'foo'), 'expected attrs to have correct value'); } }, @@ -3152,7 +3113,7 @@ moduleFor( this.registerComponent('foo-bar', { ComponentClass: class extends Component { didUpdateAttrs() { - assert.equal(5, this.get('foo'), 'expected newAttrs to have new value'); + assert.equal(5, get(this, 'foo'), 'expected newAttrs to have new value'); } }, diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/dynamic-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/dynamic-components-test.js index f43968b9047..ed9f7894bcc 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/dynamic-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/dynamic-components-test.js @@ -1,7 +1,7 @@ import { DEBUG } from '@glimmer/env'; import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers'; -import { set, computed } from '@ember/object'; +import { get, set, computed } from '@ember/object'; import { Component } from '../../utils/helpers'; import { backtrackingMessageFor } from '../../utils/debug-stack'; @@ -168,7 +168,7 @@ moduleFor( init() { super.init(); instance = this; - this.set('message', 'hello'); + set(this, 'message', 'hello'); } }; @@ -224,7 +224,7 @@ moduleFor( ComponentClass: class extends Component { willDestroy() { super.willDestroy(); - destroyed[this.get('id')]++; + destroyed[get(this, 'id')]++; } }, }); @@ -382,7 +382,7 @@ moduleFor( ComponentClass: class extends Component { init() { super.init(...arguments); - this.set('locationCopy', this.get('location')); + set(this, 'locationCopy', get(this, 'location')); } }, }); @@ -392,7 +392,7 @@ moduleFor( ComponentClass: class extends Component { init() { super.init(...arguments); - this.set('locationCopy', this.get('location')); + set(this, 'locationCopy', get(this, 'location')); } }, }); @@ -402,7 +402,7 @@ moduleFor( ComponentClass: class extends Component { @computed('location') get componentName() { - if (this.get('location') === 'Caracas') { + if (get(this, 'location') === 'Caracas') { return 'foo-bar'; } else { return 'foo-bar-baz'; @@ -526,7 +526,7 @@ moduleFor( willRender() { // store internally available name to ensure that the name available in `this.attrs.name` // matches the template lookup name - set(this, 'internalName', this.get('name')); + set(this, 'internalName', get(this, 'name')); } }, }); @@ -705,17 +705,17 @@ moduleFor( this.assertText('Foo4'); - runTask(() => this.context.set('user1', 'Bar')); + runTask(() => set(this.context, 'user1', 'Bar')); this.assertText('Bar4'); - runTask(() => this.context.set('user2', '5')); + runTask(() => set(this.context, 'user2', '5')); this.assertText('Bar5'); runTask(() => { - this.context.set('user1', 'Foo'); - this.context.set('user2', 4); + set(this.context, 'user1', 'Foo'); + set(this.context, 'user2', 4); }); this.assertText('Foo4'); @@ -726,7 +726,7 @@ moduleFor( ComponentClass: class extends Component { init() { super.init(...arguments); - this.set('person', { + set(this, 'person', { name: 'Alex', toString() { return `Person (${this.name})`; @@ -741,7 +741,7 @@ moduleFor( ComponentClass: class extends Component { init() { super.init(...arguments); - this.set('person.name', 'Ben'); + set(this, 'person.name', 'Ben'); } }, template: '{{this.person.name}}', diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js index 3a64c22ceb1..0703521a924 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js @@ -1,7 +1,7 @@ import { classes, moduleFor, RenderingTestCase, runTask, strip } from 'internal-test-helpers'; import { schedule } from '@ember/runloop'; -import { set, setProperties } from '@ember/object'; +import { get, set, setProperties } from '@ember/object'; import { getViewElement, getViewId } from '@ember/-internals/views'; import { Component } from '../../utils/helpers'; @@ -1319,7 +1319,7 @@ moduleFor( width = '5'; didInsertElement() { schedule('afterRender', () => { - this.set('width', '10'); + set(this, 'width', '10'); }); } }; @@ -1340,8 +1340,8 @@ moduleFor( let ComponentClass = class extends Component { didInsertElement() { schedule('afterRender', () => { - let parent = this.get('parent'); - parent.set('foo', 'wat'); + let parent = get(this, 'parent'); + set(parent, 'foo', 'wat'); }); } }; @@ -1365,7 +1365,7 @@ moduleFor( customHref = 'http://google.com'; attributeBindings = ['customHref:href']; willRender() { - this.set('customHref', 'http://willRender.com'); + set(this, 'customHref', 'http://willRender.com'); } }; diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-angle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-angle-test.js index d47b828a630..1dacd53064c 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-angle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-angle-test.js @@ -1,4 +1,5 @@ import Controller from '@ember/controller'; +import { get, set } from '@ember/object'; import { RSVP } from '@ember/-internals/runtime'; import Route from '@ember/routing/route'; import { @@ -133,7 +134,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, this.indexProperties, 'controller QP properties do not update' ); @@ -154,7 +158,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, this.indexProperties, 'controller QP properties do not update' ); @@ -172,7 +179,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, this.indexProperties, 'controller QP properties do not update' ); @@ -195,7 +205,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, { foo: '456', bar: 'abc' }, 'controller QP properties updated' ); @@ -220,7 +233,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, { foo: '456', bar: 'abc' }, 'controller QP properties updated' ); @@ -253,7 +269,10 @@ moduleFor( let aboutController = this.getController('about'); assert.deepEqual( - aboutController.getProperties('baz', 'bat'), + { + baz: get(aboutController, 'baz'), + bat: get(aboutController, 'bat'), + }, { baz: 'lol', bat: 'borf' }, 'about controller QP properties updated' ); @@ -322,7 +341,9 @@ moduleFor( let applicationController = this.getController('application'); assert.deepEqual( - applicationController.getProperties('baz'), + { + baz: get(applicationController, 'baz'), + }, { baz: 'lol' }, 'index controller QP properties updated' ); @@ -345,7 +366,7 @@ moduleFor( assert.equal(theLink.attr('href'), '/?foo=OMG'); - runTask(() => indexController.set('boundThing', 'ASL')); + runTask(() => set(indexController, 'boundThing', 'ASL')); assert.equal(theLink.attr('href'), '/?foo=ASL'); } @@ -367,14 +388,18 @@ moduleFor( assert.equal(theLink.attr('href'), '/?abool=OMG'); - runTask(() => indexController.set('boundThing', false)); + runTask(() => set(indexController, 'boundThing', false)); assert.equal(theLink.attr('href'), '/?abool=false'); await this.click('#the-link'); assert.deepEqual( - indexController.getProperties('foo', 'bar', 'abool'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + abool: get(indexController, 'abool'), + }, { foo: '123', bar: 'abc', abool: false }, 'bound bool QP properties update' ); @@ -397,12 +422,12 @@ moduleFor( assert.equal(theLink.attr('href'), '/?foo=lol'); - runTask(() => indexController.set('bar', 'BORF')); + runTask(() => set(indexController, 'bar', 'BORF')); await runLoopSettled(); assert.equal(theLink.attr('href'), '/?bar=BORF&foo=lol'); - runTask(() => indexController.set('foo', 'YEAH')); + runTask(() => set(indexController, 'foo', 'YEAH')); await runLoopSettled(); assert.equal(theLink.attr('href'), '/?bar=BORF&foo=lol'); @@ -449,14 +474,14 @@ moduleFor( runTask(() => this.click('#close-link')); assert.equal(router.currentRouteName, 'cars.index'); - assert.equal(router.get('url'), '/cars'); - assert.equal(carsController.get('page'), 1, 'The page query-param is 1'); + assert.equal(get(router, 'url'), '/cars'); + assert.equal(get(carsController, 'page'), 1, 'The page query-param is 1'); runTask(() => this.click('#page2-link')); assert.equal(router.currentRouteName, 'cars.index', 'The active route is still cars'); - assert.equal(router.get('url'), '/cars?page=2', 'The url has been updated'); - assert.equal(carsController.get('page'), 2, 'The query params have been updated'); + assert.equal(get(router, 'url'), '/cars?page=2', 'The url has been updated'); + assert.equal(get(carsController, 'page'), 2, 'The query params have been updated'); } async ['@test it applies activeClass when query params are not changed'](assert) { @@ -724,18 +749,18 @@ moduleFor( let parentController = this.getController('parent'); - assert.equal(parentController.get('page'), 2); + assert.equal(get(parentController, 'page'), 2); - runTask(() => parentController.set('page', 3)); + runTask(() => set(parentController, 'page', 3)); await runLoopSettled(); - assert.equal(router.get('location.path'), '/parent?page=3'); + assert.equal(get(router, 'location.path'), '/parent?page=3'); this.shouldBeActive(assert, '#app-link'); this.shouldBeActive(assert, '#parent-link'); await this.click('#app-link'); - assert.equal(router.get('location.path'), '/parent'); + assert.equal(get(router, 'location.path'), '/parent'); } async ['@test it defaults query params while in active transition regression test'](assert) { @@ -800,7 +825,7 @@ moduleFor( assert.equal(foosLink.attr('href'), '/foos'); assert.equal(bazLink.attr('href'), '/foos?baz=true'); assert.equal(barsLink.attr('href'), '/bars?quux=true'); - assert.equal(router.get('location.path'), '/'); + assert.equal(get(router, 'location.path'), '/'); this.shouldNotBeActive(assert, '#foos-link'); this.shouldNotBeActive(assert, '#baz-foos-link'); this.shouldNotBeActive(assert, '#bars-link'); @@ -813,7 +838,7 @@ moduleFor( runTask(() => foos.resolve()); - assert.equal(router.get('location.path'), '/foos'); + assert.equal(get(router, 'location.path'), '/foos'); this.shouldBeActive(assert, '#foos-link'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-curly-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-curly-test.js index 6c387dd9146..40a902af31a 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-curly-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/query-params-curly-test.js @@ -1,4 +1,5 @@ import Controller from '@ember/controller'; +import { get, set } from '@ember/object'; import { RSVP } from '@ember/-internals/runtime'; import Route from '@ember/routing/route'; import { @@ -142,7 +143,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, this.indexProperties, 'controller QP properties do not update' ); @@ -163,7 +167,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, this.indexProperties, 'controller QP properties do not update' ); @@ -184,7 +191,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, this.indexProperties, 'controller QP properties do not update' ); @@ -209,7 +219,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, { foo: '456', bar: 'abc' }, 'controller QP properties updated' ); @@ -236,7 +249,10 @@ moduleFor( let indexController = this.getController('index'); assert.deepEqual( - indexController.getProperties('foo', 'bar'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + }, { foo: '456', bar: 'abc' }, 'controller QP properties updated' ); @@ -271,7 +287,10 @@ moduleFor( let aboutController = this.getController('about'); assert.deepEqual( - aboutController.getProperties('baz', 'bat'), + { + baz: get(aboutController, 'baz'), + bat: get(aboutController, 'bat'), + }, { baz: 'lol', bat: 'borf' }, 'about controller QP properties updated' ); @@ -290,7 +309,7 @@ moduleFor( assert.equal(theLink.attr('href'), '/?foo=OMG'); - runTask(() => indexController.set('boundThing', 'ASL')); + runTask(() => set(indexController, 'boundThing', 'ASL')); assert.equal(theLink.attr('href'), '/?foo=ASL'); } @@ -314,14 +333,18 @@ moduleFor( assert.equal(theLink.attr('href'), '/?abool=OMG'); - runTask(() => indexController.set('boundThing', false)); + runTask(() => set(indexController, 'boundThing', false)); assert.equal(theLink.attr('href'), '/?abool=false'); await this.click('#the-link > a'); assert.deepEqual( - indexController.getProperties('foo', 'bar', 'abool'), + { + foo: get(indexController, 'foo'), + bar: get(indexController, 'bar'), + abool: get(indexController, 'abool'), + }, { foo: '123', bar: 'abc', abool: false }, 'bound bool QP properties update' ); @@ -344,12 +367,12 @@ moduleFor( assert.equal(theLink.attr('href'), '/?foo=lol'); - runTask(() => indexController.set('bar', 'BORF')); + runTask(() => set(indexController, 'bar', 'BORF')); await runLoopSettled(); assert.equal(theLink.attr('href'), '/?bar=BORF&foo=lol'); - runTask(() => indexController.set('foo', 'YEAH')); + runTask(() => set(indexController, 'foo', 'YEAH')); await runLoopSettled(); assert.equal(theLink.attr('href'), '/?bar=BORF&foo=lol'); @@ -396,14 +419,14 @@ moduleFor( runTask(() => this.click('#close-link > a')); assert.equal(router.currentRouteName, 'cars.index'); - assert.equal(router.get('url'), '/cars'); - assert.equal(carsController.get('page'), 1, 'The page query-param is 1'); + assert.equal(get(router, 'url'), '/cars'); + assert.equal(get(carsController, 'page'), 1, 'The page query-param is 1'); runTask(() => this.click('#page2-link > a')); assert.equal(router.currentRouteName, 'cars.index', 'The active route is still cars'); - assert.equal(router.get('url'), '/cars?page=2', 'The url has been updated'); - assert.equal(carsController.get('page'), 2, 'The query params have been updated'); + assert.equal(get(router, 'url'), '/cars?page=2', 'The url has been updated'); + assert.equal(get(carsController, 'page'), 2, 'The query params have been updated'); } async ['@test it applies activeClass when query params are not changed'](assert) { @@ -677,18 +700,18 @@ moduleFor( let parentController = this.getController('parent'); - assert.equal(parentController.get('page'), 2); + assert.equal(get(parentController, 'page'), 2); - runTask(() => parentController.set('page', 3)); + runTask(() => set(parentController, 'page', 3)); await runLoopSettled(); - assert.equal(router.get('location.path'), '/parent?page=3'); + assert.equal(get(router, 'location.path'), '/parent?page=3'); this.shouldBeActive(assert, '#app-link > a'); this.shouldBeActive(assert, '#parent-link > a'); await this.click('#app-link > a'); - assert.equal(router.get('location.path'), '/parent'); + assert.equal(get(router, 'location.path'), '/parent'); } async ['@test it defaults query params while in active transition regression test'](assert) { @@ -753,7 +776,7 @@ moduleFor( assert.equal(foosLink.attr('href'), '/foos'); assert.equal(bazLink.attr('href'), '/foos?baz=true'); assert.equal(barsLink.attr('href'), '/bars?quux=true'); - assert.equal(router.get('location.path'), '/'); + assert.equal(get(router, 'location.path'), '/'); this.shouldNotBeActive(assert, '#foos-link > a'); this.shouldNotBeActive(assert, '#baz-foos-link > a'); this.shouldNotBeActive(assert, '#bars-link > a'); @@ -766,7 +789,7 @@ moduleFor( runTask(() => foos.resolve()); - assert.equal(router.get('location.path'), '/foos'); + assert.equal(get(router, 'location.path'), '/foos'); this.shouldBeActive(assert, '#foos-link > a'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js index 1777c744fd8..58e64233407 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js @@ -6,6 +6,7 @@ import { } from 'internal-test-helpers'; import Controller, { inject as injectController } from '@ember/controller'; import { RSVP } from '@ember/-internals/runtime'; +import { set } from '@ember/object'; import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import { service } from '@ember/service'; @@ -167,7 +168,7 @@ moduleFor( 'The dynamic link is disabled when its disabled is true' ); - runTask(() => controller.set('dynamicDisabled', false)); + runTask(() => set(controller, 'dynamicDisabled', false)); assert.equal( this.$('#about-link-static.disabled').length, @@ -238,7 +239,7 @@ moduleFor( 'The default disabled class is not added on the dynamic link' ); - runTask(() => controller.set('dynamicDisabled', false)); + runTask(() => set(controller, 'dynamicDisabled', false)); assert.equal( this.$('#about-link-static.do-not-want').length, @@ -295,7 +296,7 @@ moduleFor( 'The default disabled class is not added' ); - runTask(() => controller.set('disabledClass', 'can-not-use')); + runTask(() => set(controller, 'disabledClass', 'can-not-use')); assert.equal( this.$('#about-link.can-not-use').length, @@ -349,7 +350,7 @@ moduleFor( assert.strictEqual(this.$('h3.about').length, 0, 'Transitioning did not occur'); - runTask(() => controller.set('dynamicDisabled', false)); + runTask(() => set(controller, 'dynamicDisabled', false)); await this.click('#about-link'); @@ -443,7 +444,7 @@ moduleFor( 'The other link was rendered without the default active class' ); - runTask(() => controller.set('activeClass', 'wow-active')); + runTask(() => set(controller, 'activeClass', 'wow-active')); assert.equal( this.$('#self-link.wow-active').length, @@ -1018,7 +1019,7 @@ moduleFor( 'The link is not active since current-when is false' ); - runTask(() => controller.set('isCurrent', true)); + runTask(() => set(controller, 'isCurrent', true)); assert.ok( this.$('#index-link').hasClass('active'), @@ -1253,7 +1254,7 @@ moduleFor( let link = this.$('#self-link'); assert.equal(link.attr('target'), '_blank', 'The self-link contains `target` attribute'); - runTask(() => controller.set('boundLinkTarget', '_self')); + runTask(() => set(controller, 'boundLinkTarget', '_self')); assert.equal(link.attr('target'), '_self', 'The self-link contains `target` attribute'); } @@ -1433,7 +1434,7 @@ moduleFor( assertEquality('/'); - runTask(() => controller.set('foo', 'about')); + runTask(() => set(controller, 'foo', 'about')); assertEquality('/about'); } @@ -1465,7 +1466,7 @@ moduleFor( await this.visit('/'); - runTask(() => controller.set('post', post)); + runTask(() => set(controller, 'post', post)); assert.equal( normalizeUrl(this.$('#post').attr('href')), @@ -1473,7 +1474,7 @@ moduleFor( 'precond - Link has rendered href attr properly' ); - runTask(() => controller.set('post', secondPost)); + runTask(() => set(controller, 'post', secondPost)); assert.equal( this.$('#post').attr('href'), @@ -1481,7 +1482,7 @@ moduleFor( 'href attr was updated after one of the params had been changed' ); - runTask(() => controller.set('post', null)); + runTask(() => set(controller, 'post', null)); assert.equal( this.$('#post').attr('href'), @@ -1575,7 +1576,7 @@ moduleFor( linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/bar', '/foo']); - runTask(() => controller.set('route1', 'rar')); + runTask(() => set(controller, 'route1', 'rar')); linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/rar', '/foo']); @@ -1891,28 +1892,28 @@ moduleFor( await expectWarning(() => this.click(contextLink[0]), warningMessage); // Set the destinationRoute (context is still null). - runTask(() => controller.set('destinationRoute', 'thing')); + runTask(() => set(controller, 'destinationRoute', 'thing')); assertLinkStatus(contextLink); // Set the routeContext to an id - runTask(() => controller.set('routeContext', '456')); + runTask(() => set(controller, 'routeContext', '456')); assertLinkStatus(contextLink, '/thing/456'); // Test that 0 isn't interpreted as falsy. - runTask(() => controller.set('routeContext', 0)); + runTask(() => set(controller, 'routeContext', 0)); assertLinkStatus(contextLink, '/thing/0'); // Set the routeContext to an object - runTask(() => controller.set('routeContext', { id: 123 })); + runTask(() => set(controller, 'routeContext', { id: 123 })); assertLinkStatus(contextLink, '/thing/123'); // Set the destinationRoute back to null. - runTask(() => controller.set('destinationRoute', null)); + runTask(() => set(controller, 'destinationRoute', null)); assertLinkStatus(contextLink); await expectWarning(() => this.click(staticLink[0]), warningMessage); - runTask(() => controller.set('secondRoute', 'about')); + runTask(() => set(controller, 'secondRoute', 'about')); assertLinkStatus(staticLink, '/about'); // Click the now-active link diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js index 6f7ee989b51..21aa359dadf 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js @@ -6,6 +6,7 @@ import { } from 'internal-test-helpers'; import Controller, { inject as injectController } from '@ember/controller'; import { RSVP } from '@ember/-internals/runtime'; +import { set } from '@ember/object'; import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import { service } from '@ember/service'; @@ -167,7 +168,7 @@ moduleFor( 'The dynamic link is disabled when its disabled is true' ); - runTask(() => controller.set('dynamicDisabled', false)); + runTask(() => set(controller, 'dynamicDisabled', false)); assert.equal( this.$('#about-link-static > a.disabled').length, @@ -241,7 +242,7 @@ moduleFor( 'The default disabled class is not added on the dynamic link' ); - runTask(() => controller.set('dynamicDisabled', false)); + runTask(() => set(controller, 'dynamicDisabled', false)); assert.equal( this.$('#about-link-static > a.do-not-want').length, @@ -298,7 +299,7 @@ moduleFor( 'The default disabled class is not added' ); - runTask(() => controller.set('disabledClass', 'can-not-use')); + runTask(() => set(controller, 'disabledClass', 'can-not-use')); assert.equal( this.$('#about-link > a.can-not-use').length, @@ -356,7 +357,7 @@ moduleFor( assert.strictEqual(this.$('h3.about').length, 0, 'Transitioning did not occur'); - runTask(() => controller.set('dynamicDisabled', false)); + runTask(() => set(controller, 'dynamicDisabled', false)); await this.click('#about-link > a'); @@ -450,7 +451,7 @@ moduleFor( 'The other link was rendered without the default active class' ); - runTask(() => controller.set('activeClass', 'wow-active')); + runTask(() => set(controller, 'activeClass', 'wow-active')); assert.equal( this.$('#self-link > a.wow-active').length, @@ -1088,7 +1089,7 @@ moduleFor( 'The link is not active since current-when is false' ); - runTask(() => controller.set('isCurrent', true)); + runTask(() => set(controller, 'isCurrent', true)); assert.ok( this.$('#index-link > a').hasClass('active'), @@ -1344,7 +1345,7 @@ moduleFor( assertEquality('/'); - runTask(() => controller.set('foo', 'about')); + runTask(() => set(controller, 'foo', 'about')); assertEquality('/about'); } @@ -1376,7 +1377,7 @@ moduleFor( await this.visit('/'); - runTask(() => controller.set('post', post)); + runTask(() => set(controller, 'post', post)); assert.equal( normalizeUrl(this.$('#post > a').attr('href')), @@ -1384,7 +1385,7 @@ moduleFor( 'precond - Link has rendered href attr properly' ); - runTask(() => controller.set('post', secondPost)); + runTask(() => set(controller, 'post', secondPost)); assert.equal( this.$('#post > a').attr('href'), @@ -1392,7 +1393,7 @@ moduleFor( 'href attr was updated after one of the params had been changed' ); - runTask(() => controller.set('post', null)); + runTask(() => set(controller, 'post', null)); assert.equal( this.$('#post > a').attr('href'), @@ -1486,7 +1487,7 @@ moduleFor( linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/bar', '/foo']); - runTask(() => controller.set('route1', 'rar')); + runTask(() => set(controller, 'route1', 'rar')); linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/rar', '/foo']); @@ -1816,28 +1817,28 @@ moduleFor( await expectWarning(() => this.click(contextLink[0]), warningMessage); // Set the destinationRoute (context is still null). - runTask(() => controller.set('destinationRoute', 'thing')); + runTask(() => set(controller, 'destinationRoute', 'thing')); assertLinkStatus(contextLink); // Set the routeContext to an id - runTask(() => controller.set('routeContext', '456')); + runTask(() => set(controller, 'routeContext', '456')); assertLinkStatus(contextLink, '/thing/456'); // Test that 0 isn't interpreted as falsy. - runTask(() => controller.set('routeContext', 0)); + runTask(() => set(controller, 'routeContext', 0)); assertLinkStatus(contextLink, '/thing/0'); // Set the routeContext to an object - runTask(() => controller.set('routeContext', { id: 123 })); + runTask(() => set(controller, 'routeContext', { id: 123 })); assertLinkStatus(contextLink, '/thing/123'); // Set the destinationRoute back to null. - runTask(() => controller.set('destinationRoute', null)); + runTask(() => set(controller, 'destinationRoute', null)); assertLinkStatus(contextLink); await expectWarning(() => this.click(staticLink[0]), warningMessage); - runTask(() => controller.set('secondRoute', 'about')); + runTask(() => set(controller, 'secondRoute', 'about')); assertLinkStatus(staticLink, '/about'); // Click the now-active link diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/template-only-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/template-only-components-test.js index 83f64de753b..e24c68f9c45 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/template-only-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/template-only-components-test.js @@ -2,7 +2,7 @@ import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers'; import { setComponentTemplate } from '@glimmer/manager'; import { templateOnlyComponent } from '@glimmer/runtime'; import { compile } from 'ember-template-compiler'; -import EmberObject from '@ember/object'; +import EmberObject, { get, set } from '@ember/object'; import { Component } from '../../utils/helpers'; import { backtrackingMessageFor } from '../../utils/debug-stack'; @@ -37,15 +37,18 @@ moduleFor( this.assertStableRerender(); - runTask(() => this.context.set('foo', 'FOO')); + runTask(() => set(this.context, 'foo', 'FOO')); this.assertInnerHTML('|FOO|bar|'); - runTask(() => this.context.set('bar', 'BAR')); + runTask(() => set(this.context, 'bar', 'BAR')); this.assertInnerHTML('|FOO|BAR|'); - runTask(() => this.context.setProperties({ foo: 'foo', bar: 'bar' })); + runTask(() => { + set(this.context, 'foo', 'foo'); + set(this.context, 'bar', 'bar'); + }); this.assertInnerHTML('|foo|bar|'); } @@ -62,15 +65,18 @@ moduleFor( this.assertStableRerender(); - runTask(() => this.context.set('foo', 'FOO')); + runTask(() => set(this.context, 'foo', 'FOO')); this.assertInnerHTML('|||'); - runTask(() => this.context.set('bar', null)); + runTask(() => set(this.context, 'bar', null)); this.assertInnerHTML('|||'); - runTask(() => this.context.setProperties({ foo: 'foo', bar: 'bar' })); + runTask(() => { + set(this.context, 'foo', 'foo'); + set(this.context, 'bar', 'bar'); + }); this.assertInnerHTML('|||'); } @@ -86,15 +92,15 @@ moduleFor( this.assertStableRerender(); - runTask(() => this.context.set('class', 'foo')); + runTask(() => set(this.context, 'class', 'foo')); this.assertInnerHTML('hello'); - runTask(() => this.context.set('class', null)); + runTask(() => set(this.context, 'class', null)); this.assertInnerHTML('hello'); - runTask(() => this.context.set('class', 'foo bar')); + runTask(() => set(this.context, 'class', 'foo bar')); this.assertInnerHTML('hello'); } @@ -110,15 +116,15 @@ moduleFor( this.assertStableRerender(); - runTask(() => this.context.set('isShowing', false)); + runTask(() => set(this.context, 'isShowing', false)); this.assertInnerHTML('outside outside'); - runTask(() => this.context.set('isShowing', null)); + runTask(() => set(this.context, 'isShowing', null)); this.assertInnerHTML('outside outside'); - runTask(() => this.context.set('isShowing', true)); + runTask(() => set(this.context, 'isShowing', true)); this.assertInnerHTML('outside before hello after outside'); } @@ -136,7 +142,7 @@ moduleFor( this.registerComponent('x-inner', { ComponentClass: class extends Component { didReceiveAttrs() { - this.get('wrapper').set('content', this.get('value')); + set(get(this, 'wrapper'), 'content', get(this, 'value')); } value = null; }, diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js index a37ce0a0cc2..8b2ef03c063 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js @@ -43,7 +43,7 @@ moduleFor( this.assertText('robert jackson | robert jackson'); - runTask(() => this.context.set('first', 'max')); + runTask(() => set(this.context, 'first', 'max')); this.assertText('max jackson | max jackson'); } @@ -78,7 +78,7 @@ moduleFor( this.assertText('robert jackson | robert jackson'); - runTask(() => this.context.set('first', 'max')); + runTask(() => set(this.context, 'first', 'max')); this.assertText('max jackson | max jackson'); } @@ -254,7 +254,7 @@ moduleFor( get countAlias() { return this.count; } - increment = () => this.set('count', this.count + 1); + increment = () => set(this, 'count', this.count + 1); } this.registerComponent('counter', { @@ -568,7 +568,7 @@ moduleFor( 'updating inner component causes inner component to rerender' ); - runTask(() => this.context.set('count', 1)); + runTask(() => set(this.context, 'count', 1)); this.assertText('2'); @@ -595,10 +595,10 @@ moduleFor( this.assertText('hello!'); - runTask(() => this.context.set('text', 'hello world!')); + runTask(() => set(this.context, 'text', 'hello world!')); this.assertText('hello world!'); - runTask(() => this.context.set('text', 'hello!')); + runTask(() => set(this.context, 'text', 'hello!')); this.assertText('hello!'); } @@ -625,10 +625,10 @@ moduleFor( this.assertText('hello!'); - runTask(() => foo.set('text', 'hello world!')); + runTask(() => set(foo, 'text', 'hello world!')); this.assertText('hello world!'); - runTask(() => foo.set('text', 'hello!')); + runTask(() => set(foo, 'text', 'hello!')); this.assertText('hello!'); } @@ -650,10 +650,10 @@ moduleFor( this.assertText('hello!'); - runTask(() => this.context.set('text', 'hello world!')); + runTask(() => set(this.context, 'text', 'hello world!')); this.assertText('hello world!'); - runTask(() => this.context.set('text', 'hello!')); + runTask(() => set(this.context, 'text', 'hello!')); this.assertText('hello!'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/utils-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/utils-test.js index e9cbd211101..1f849e8cd0a 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/utils-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/utils-test.js @@ -2,6 +2,7 @@ import { moduleFor, ApplicationTestCase, RenderingTestCase, runTask } from 'inte import { tracked } from '@glimmer/tracking'; import Controller from '@ember/controller'; +import { set } from '@ember/object'; import { getRootViews, getChildViews, @@ -32,7 +33,7 @@ moduleFor( isExpanded = true; click() { - this.toggleProperty('isExpanded'); + set(this, 'isExpanded', !this.isExpanded); return false; } }, @@ -44,7 +45,7 @@ moduleFor( @tracked isExpanded = true; toggle = () => { - this.toggleProperty('isExpanded'); + set(this, 'isExpanded', !this.isExpanded); }; } diff --git a/packages/@ember/-internals/glimmer/tests/integration/content-test.js b/packages/@ember/-internals/glimmer/tests/integration/content-test.js index 3ac98e4b61b..3eed756a7a0 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/content-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/content-test.js @@ -4,7 +4,7 @@ import { RenderingTestCase, moduleFor, applyMixins, classes, runTask } from 'int import { set, computed } from '@ember/object'; import { getDebugFunction, setDebugFunction } from '@ember/debug'; -import EmberObject from '@ember/object'; +import EmberObject, { get } from '@ember/object'; import { readOnly } from '@ember/object/computed'; import { constructStyleDeprecationMessage } from '@ember/-internals/views'; import { Component, SafeString, htmlSafe } from '../utils/helpers'; @@ -293,7 +293,7 @@ class DynamicContentTest extends RenderingTestCase { let Formatter = class extends EmberObject { @computed('message') get formattedMessage() { - return this.get('message').toUpperCase(); + return get(this, 'message').toUpperCase(); } }; @@ -320,7 +320,7 @@ class DynamicContentTest extends RenderingTestCase { let Formatter = class extends EmberObject { @computed('messenger.message') get formattedMessage() { - return this.get('messenger.message').toUpperCase(); + return get(this, 'messenger.message').toUpperCase(); } }; diff --git a/packages/@ember/-internals/glimmer/tests/integration/custom-component-manager-test.js b/packages/@ember/-internals/glimmer/tests/integration/custom-component-manager-test.js index 95ce65ba453..a49010ef009 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/custom-component-manager-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/custom-component-manager-test.js @@ -459,7 +459,7 @@ moduleFor( this.assertHTML(`

hello world

`); - runTask(() => this.context.set('show', false)); + runTask(() => set(this.context, 'show', false)); this.assertText(''); @@ -519,7 +519,7 @@ moduleFor( this.assertHTML(`

hello world

`); assert.verifySteps(['createComponent', 'getContext', 'didCreateComponent']); - runTask(() => this.context.set('name', 'max')); + runTask(() => set(this.context, 'name', 'max')); this.assertHTML(`

hello max

`); assert.verifySteps(['updateComponent', 'didUpdateComponent']); } @@ -733,7 +733,7 @@ moduleFor( this.assertHTML(`

Hello world!

`); assert.verifySteps(['createComponent', 'getContext', 'didCreateComponent']); - runTask(() => this.context.set('value', 'bar')); + runTask(() => set(this.context, 'value', 'bar')); assert.verifySteps(['updateComponent', 'didUpdateComponent']); } @@ -792,7 +792,7 @@ moduleFor( 'getContext', ]); - runTask(() => this.context.set('value', 'bar')); + runTask(() => set(this.context, 'value', 'bar')); assert.deepEqual(updated, [{ id: 'no-id' }, { id: 'static-id' }, { id: 'dynamic-id' }]); assert.verifySteps(['updateComponent', 'updateComponent', 'updateComponent']); } @@ -836,7 +836,7 @@ moduleFor( this.assertHTML(`

Hello world!

`); assert.verifySteps(['createComponent', 'getContext']); - runTask(() => this.context.set('value', 'bar')); + runTask(() => set(this.context, 'value', 'bar')); assert.verifySteps([]); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test.js b/packages/@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test.js index d5ca43618d0..6e177bc6272 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test.js @@ -164,7 +164,7 @@ class ModifierManagerTest extends RenderingTestCase { positional[0]; assert.equal(this.element.tagName, 'H1'); - this.set('savedElement', this.element); + set(this, 'savedElement', this.element); } didUpdate() { assert.equal(this.element, this.savedElement); @@ -594,7 +594,7 @@ moduleFor( this.registerModifier('foo-bar', ModifierClass); this.render('

hello world

'); - runTask(() => this.context.set('baz', 'Hello')); + runTask(() => set(this.context, 'baz', 'Hello')); this.assertHTML('

hello world

'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/mut-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/mut-test.js index 79f3183e294..177c66ddeaf 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/mut-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/mut-test.js @@ -455,7 +455,7 @@ moduleFor( } @computed('height') get style() { - let height = this.get('height'); + let height = get(this, 'height'); return htmlSafe(`height: ${height}px;`); } height = 20; @@ -524,17 +524,17 @@ moduleFor( } @computed('height', 'width') get style() { - let height = this.get('height'); - let width = this.get('width'); + let height = get(this, 'height'); + let width = get(this, 'width'); return htmlSafe(`height: ${height}px; width: ${width}px;`); } height = 20; @computed('height') get width() { - return this.get('height') * 2; + return get(this, 'height') * 2; } set width(width) { - this.set('height', width / 2); + set(this, 'height', width / 2); } }, template: '{{this.width}}x{{this.height}}', diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js index 22c52fea21f..ef623ba2cb6 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js @@ -1,4 +1,4 @@ -import EmberObject from '@ember/object'; +import EmberObject, { set } from '@ember/object'; import { tracked, nativeDescDecorator as descriptor } from '@ember/-internals/metal'; import Service, { service } from '@ember/service'; import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers'; @@ -323,7 +323,7 @@ moduleFor( this.assertText('bob-value'); - runTask(() => obj.set('value', 'sal')); + runTask(() => set(obj, 'value', 'sal')); this.assertText('sal-value'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js index d9abad7f5e7..1dfb377cc6f 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js @@ -1,12 +1,6 @@ -import { - RenderingTestCase, - moduleFor, - strip, - runTask, - runLoopSettled, -} from 'internal-test-helpers'; +import { RenderingTestCase, moduleFor, strip, runTask } from 'internal-test-helpers'; -import { set, get, setProperties } from '@ember/object'; +import { set, setProperties } from '@ember/object'; import { Component } from '../../utils/helpers'; @@ -368,76 +362,6 @@ moduleFor( this.assertText('abc abc'); } - async ['@test should be able to render an unbound helper invocation for helpers with dependent keys']() { - this.registerHelper('capitalizeName', { - destroy() { - this.removeObserver('value.firstName', this, this.recompute); - this._super(...arguments); - }, - - compute([value]) { - if (this.value) { - this.removeObserver('value.firstName', this, this.recompute); - } - this.set('value', value); - this.addObserver('value.firstName', this, this.recompute); - return value ? get(value, 'firstName').toUpperCase() : ''; - }, - }); - - this.registerHelper('concatNames', { - destroy() { - this.teardown(); - this._super(...arguments); - }, - teardown() { - this.removeObserver('value.firstName', this, this.recompute); - this.removeObserver('value.lastName', this, this.recompute); - }, - compute([value]) { - if (this.value) { - this.teardown(); - } - this.set('value', value); - this.addObserver('value.firstName', this, this.recompute); - this.addObserver('value.lastName', this, this.recompute); - return (value ? get(value, 'firstName') : '') + (value ? get(value, 'lastName') : ''); - }, - }); - - this.render( - `{{capitalizeName this.person}} {{unbound (capitalizeName this.person)}} {{concatNames this.person}} {{unbound (concatNames this.person)}}`, - { - person: { - firstName: 'shooby', - lastName: 'taylor', - }, - } - ); - - this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); - - runTask(() => this.rerender()); - await runLoopSettled(); - - this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); - - runTask(() => set(this.context, 'person.firstName', 'sally')); - await runLoopSettled(); - - this.assertText('SALLY SHOOBY sallytaylor shoobytaylor'); - - runTask(() => - set(this.context, 'person', { - firstName: 'shooby', - lastName: 'taylor', - }) - ); - await runLoopSettled(); - - this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); - } - ['@test should be able to render an unbound helper invocation in #each helper']() { this.registerHelper('capitalize', (params) => params[0].toUpperCase()); @@ -483,76 +407,6 @@ moduleFor( this.assertText('SHOOBY SHOOBYCINDY CINDY'); } - async ['@test should be able to render an unbound helper invocation with bound hash options']() { - this.registerHelper('capitalizeName', { - destroy() { - this.removeObserver('value.firstName', this, this.recompute); - this._super(...arguments); - }, - - compute([value]) { - if (this.value) { - this.removeObserver('value.firstName', this, this.recompute); - } - this.set('value', value); - this.addObserver('value.firstName', this, this.recompute); - return value ? get(value, 'firstName').toUpperCase() : ''; - }, - }); - - this.registerHelper('concatNames', { - destroy() { - this.teardown(); - this._super(...arguments); - }, - teardown() { - this.removeObserver('value.firstName', this, this.recompute); - this.removeObserver('value.lastName', this, this.recompute); - }, - compute([value]) { - if (this.value) { - this.teardown(); - } - this.set('value', value); - this.addObserver('value.firstName', this, this.recompute); - this.addObserver('value.lastName', this, this.recompute); - return (value ? get(value, 'firstName') : '') + (value ? get(value, 'lastName') : ''); - }, - }); - - this.render( - `{{capitalizeName this.person}} {{unbound (capitalizeName this.person)}} {{concatNames this.person}} {{unbound (concatNames this.person)}}`, - { - person: { - firstName: 'shooby', - lastName: 'taylor', - }, - } - ); - await runLoopSettled(); - - this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); - - runTask(() => this.rerender()); - await runLoopSettled(); - - this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); - - runTask(() => set(this.context, 'person.firstName', 'sally')); - await runLoopSettled(); - - this.assertText('SALLY SHOOBY sallytaylor shoobytaylor'); - - runTask(() => - set(this.context, 'person', { - firstName: 'shooby', - lastName: 'taylor', - }) - ); - - this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); - } - ['@test should be able to render bound form of a helper inside unbound form of same helper']() { this.render( strip` diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/yield-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/yield-test.js index f360b3c30bc..19dca23261e 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/yield-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/yield-test.js @@ -1,6 +1,6 @@ import { RenderingTestCase, moduleFor, runTask } from 'internal-test-helpers'; -import { set } from '@ember/object'; +import { get, set } from '@ember/object'; import { Component } from '../../utils/helpers'; @@ -294,9 +294,9 @@ moduleFor( let ChildCompComponent = class extends Component { didReceiveAttrs() { super.didReceiveAttrs(); - let parentView = this.get('parentView'); + let parentView = get(this, 'parentView'); - assert.ok(parentView.get('isParentComponent')); + assert.ok(get(parentView, 'isParentComponent')); } }; diff --git a/packages/@ember/-internals/glimmer/tests/integration/input-test.js b/packages/@ember/-internals/glimmer/tests/integration/input-test.js index fa26fc5080c..46ac96e5c07 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/input-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/input-test.js @@ -87,17 +87,17 @@ moduleFor( this.assert.equal(this.$inputElement().prop('disabled'), false); - runTask(() => this.context.set('model.value', true)); + runTask(() => set(this.context, 'model.value', true)); this.assert.equal(this.$inputElement().prop('disabled'), true); this.assertHTML(''); // Note the DOM output is - runTask(() => this.context.set('model.value', 'wat')); + runTask(() => set(this.context, 'model.value', 'wat')); this.assert.equal(this.$inputElement().prop('disabled'), true); this.assertHTML(''); // Note the DOM output is - runTask(() => this.context.set('model', { value: false })); + runTask(() => set(this.context, 'model', { value: false })); this.assert.equal(this.$inputElement().prop('disabled'), false); this.assertHTML(''); diff --git a/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js b/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js index 0799463916f..cd686408d7c 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/modifiers/on-test.js @@ -1,6 +1,7 @@ import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers'; import { getInternalModifierManager } from '@glimmer/manager'; import { on } from '@glimmer/runtime'; +import { set } from '@ember/object'; import { Component } from '../../utils/helpers'; @@ -90,7 +91,7 @@ moduleFor( assert.equal(first, 1, 'first has been called 1 time'); assert.equal(second, 0, 'second not called on initial render'); - runTask(() => this.context.set('callback', secondCallback)); + runTask(() => set(this.context, 'callback', secondCallback)); runTask(() => this.$('button').click()); assert.equal(first, 1, 'first has been called 1 time'); @@ -141,7 +142,7 @@ moduleFor( runTask(() => this.$('button').click()); assert.equal(count, 2, 'has been called 2 times'); - runTask(() => this.context.set('once', true)); + runTask(() => set(this.context, 'once', true)); runTask(() => this.$('button').click()); assert.equal(count, 3, 'has been called 3 time'); @@ -238,7 +239,7 @@ moduleFor( runTask(() => this.$('button').click()); assert.equal(count, 1, 'has been called 1 time'); - runTask(() => this.context.set('showButton', false)); + runTask(() => set(this.context, 'showButton', false)); this.assertCounts({ adds: 1, removes: 1 }); } @@ -295,7 +296,7 @@ moduleFor( this.$('button').click(); - runTask(() => this.context.set('showButton', false)); + runTask(() => set(this.context, 'showButton', false)); this.assertCounts({ adds: 0, removes: 0 }); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/mount-test.js b/packages/@ember/-internals/glimmer/tests/integration/mount-test.js index f48661b5db8..3ac46674904 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/mount-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/mount-test.js @@ -146,7 +146,7 @@ moduleFor( let ComponentWithBacktrackingSet = class extends Component { init() { super.init(...arguments); - this.set('person.name', 'Ben'); + set(this, 'person.name', 'Ben'); } }; diff --git a/packages/@ember/-internals/glimmer/tests/integration/render-settled-test.js b/packages/@ember/-internals/glimmer/tests/integration/render-settled-test.js index f17d201dc5b..afda64de828 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/render-settled-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/render-settled-test.js @@ -1,6 +1,7 @@ import { RenderingTestCase, moduleFor, strip } from 'internal-test-helpers'; import { renderSettled } from '@ember/-internals/glimmer'; +import { set } from '@ember/object'; import { run, schedule } from '@ember/runloop'; import { all } from 'rsvp'; @@ -35,7 +36,7 @@ moduleFor( this.render(strip`{{this.foo}}`, { foo: 'bar' }); this.assertText('bar'); - this.component.set('foo', 'baz'); + set(this.component, 'foo', 'baz'); this.assertText('bar'); return renderSettled().then(() => { @@ -53,14 +54,14 @@ moduleFor( return run(() => { schedule('actions', null, () => { - this.component.set('foo', 'set in actions'); + set(this.component, 'foo', 'set in actions'); promise = renderSettled().then(() => { this.assertText('set in afterRender'); }); schedule('afterRender', null, () => { - this.component.set('foo', 'set in afterRender'); + set(this.component, 'foo', 'set in afterRender'); }); }); diff --git a/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js b/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js index f18ce2a5a62..9d218e4b4ef 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js @@ -520,7 +520,7 @@ class EachTest extends AbstractEachTest { } _isEven() { - this.set('isEven', this.get('item.value') % 2 === 0); + set(this, 'isEven', get(this, 'item.value') % 2 === 0); } didUpdate() { diff --git a/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js b/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js index 2cd84ea1961..5859a47abcd 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js @@ -161,11 +161,11 @@ moduleFor( this.assertText('[foo-foo]'); - runTask(() => this.context.set('hash.foo', 'FOO')); + runTask(() => set(this.context, 'hash.foo', 'FOO')); this.assertText('[FOO-FOO]'); - runTask(() => this.context.set('hash.foo', 'foo')); + runTask(() => set(this.context, 'hash.foo', 'foo')); this.assertText('[foo-foo]'); } diff --git a/packages/@ember/-internals/metal/tests/accessors/get_test.js b/packages/@ember/-internals/metal/tests/accessors/get_test.js index 1012aa3f515..af7d78dd870 100644 --- a/packages/@ember/-internals/metal/tests/accessors/get_test.js +++ b/packages/@ember/-internals/metal/tests/accessors/get_test.js @@ -1,10 +1,8 @@ import { ENV } from '@ember/-internals/environment'; -import EmberObject, { observer } from '@ember/object'; +import EmberObject from '@ember/object'; import { get } from '../..'; -import Mixin from '@ember/object/mixin'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; import { run } from '@ember/runloop'; -import { destroy } from '@glimmer/destroyable'; function aget(x, y) { return x[y]; @@ -179,29 +177,5 @@ moduleFor( /The key provided to get must be a string or number, you passed false/ ); } - - // .......................................................... - // BUGS - // - - ['@test (regression) watched properties on unmodified inherited objects should still return their original value']( - assert - ) { - let MyMixin = Mixin.create({ - someProperty: 'foo', - propertyDidChange: observer('someProperty', () => {}), - }); - - let baseObject = MyMixin.apply({}); - let theRealObject = Object.create(baseObject); - - assert.equal( - get(theRealObject, 'someProperty'), - 'foo', - 'should return the set value, not false' - ); - - run(() => destroy(baseObject)); - } } ); diff --git a/packages/@ember/-internals/metal/tests/computed_test.js b/packages/@ember/-internals/metal/tests/computed_test.js index 7eaa4343478..0d9eada30b5 100644 --- a/packages/@ember/-internals/metal/tests/computed_test.js +++ b/packages/@ember/-internals/metal/tests/computed_test.js @@ -702,14 +702,14 @@ moduleFor( } set aInt(value) { assert.equal(value, 123, 'setter receives the new value'); - this.set('a', String(value)); // side effect + set(this, 'a', String(value)); // side effect } }.create(); - assert.ok(testObj.get('aInt') === 1, 'getter works'); - testObj.set('aInt', 123); - assert.ok(testObj.get('a') === '123', 'setter works'); - assert.ok(testObj.get('aInt') === 123, 'cp has been updated too'); + assert.ok(get(testObj, 'aInt') === 1, 'getter works'); + set(testObj, 'aInt', 123); + assert.ok(get(testObj, 'a') === '123', 'setter works'); + assert.ok(get(testObj, 'aInt') === 123, 'cp has been updated too'); } ['@test an omitted setter cannot be set later'](assert) { @@ -718,15 +718,15 @@ moduleFor( b = '2'; @computed('a') get aInt() { - return parseInt(this.get('a')); + return parseInt(get(this, 'a')); } }.create(); - assert.ok(testObj.get('aInt') === 1, 'getter works'); - assert.ok(testObj.get('a') === '1'); + assert.ok(get(testObj, 'aInt') === 1, 'getter works'); + assert.ok(get(testObj, 'a') === '1'); expectAssertion(() => { - testObj.set('aInt', '123'); + set(testObj, 'aInt', '123'); }, /Cannot override the computed property `aInt` on <\(unknown\):ember\d*>./); } @@ -744,8 +744,8 @@ moduleFor( }), }).create(); - testObj.set('sampleCP', 'abcd'); - assert.ok(testObj.get('sampleCP') === 'set-value', 'The return value of the CP was cached'); + set(testObj, 'sampleCP', 'abcd'); + assert.ok(get(testObj, 'sampleCP') === 'set-value', 'The return value of the CP was cached'); } } ); diff --git a/packages/@ember/-internals/metal/tests/observer_test.js b/packages/@ember/-internals/metal/tests/observer_test.js index 9a9db59312d..27975486287 100644 --- a/packages/@ember/-internals/metal/tests/observer_test.js +++ b/packages/@ember/-internals/metal/tests/observer_test.js @@ -10,8 +10,6 @@ import { get, set, } from '..'; -import { observer } from '@ember/object'; -import Mixin, { mixin } from '@ember/object/mixin'; import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; import { destroy } from '@glimmer/destroyable'; import { meta as metaFor } from '@ember/-internals/meta'; @@ -35,40 +33,6 @@ moduleFor( } } - ['@test observer should assert to invalid input']() { - expectAssertion(() => { - observer(() => {}); - }, 'observer called without valid path'); - - expectAssertion(() => { - observer(null); - }, 'observer must be provided a function or an observer definition'); - - expectAssertion(() => { - observer({}); - }, 'observer called without a function'); - - expectAssertion(() => { - observer({ - fn() {}, - }); - }, 'observer called without valid path'); - - expectAssertion(() => { - observer({ - fn() {}, - dependentKeys: [], - }); - }, 'observer called without valid path'); - - expectAssertion(() => { - observer({ - fn() {}, - dependentKeys: ['foo'], - }); - }, 'observer called without sync'); - } - async ['@test observer should fire when property is modified'](assert) { obj = {}; let count = 0; @@ -189,79 +153,6 @@ moduleFor( assert.equal(observerCount, 10, 'should continue to fire indefinitely'); } - async ['@test observers watching multiple properties via brace expansion should fire when the properties change']( - assert - ) { - obj = {}; - let count = 0; - - mixin(obj, { - observeFooAndBar: observer('{foo,bar}', function () { - count++; - }), - }); - - set(obj, 'foo', 'foo'); - await runLoopSettled(); - - assert.equal(count, 1, 'observer specified via brace expansion invoked on property change'); - - set(obj, 'bar', 'bar'); - await runLoopSettled(); - - assert.equal(count, 2, 'observer specified via brace expansion invoked on property change'); - - set(obj, 'baz', 'baz'); - await runLoopSettled(); - - assert.equal(count, 2, 'observer not invoked on unspecified property'); - } - - async ['@test observers watching multiple properties via brace expansion should fire when dependent properties change']( - assert - ) { - obj = { baz: 'Initial' }; - let count = 0; - - defineProperty( - obj, - 'foo', - computed('bar', function () { - return get(this, 'bar').toLowerCase(); - }) - ); - - defineProperty( - obj, - 'bar', - computed('baz', function () { - return get(this, 'baz').toUpperCase(); - }) - ); - - mixin(obj, { - fooAndBarWatcher: observer('{foo,bar}', function () { - count++; - }), - }); - - get(obj, 'foo'); - set(obj, 'baz', 'Baz'); - await runLoopSettled(); - - // fire once for foo, once for bar - assert.equal( - count, - 2, - 'observer specified via brace expansion invoked on dependent property change' - ); - - set(obj, 'quux', 'Quux'); - await runLoopSettled(); - - assert.equal(count, 2, 'observer not fired on unspecified property'); - } - async ['@test removing an chain observer on change should not fail'](assert) { let foo = { bar: 'bar' }; let obj1 = { foo: foo }; @@ -433,36 +324,6 @@ moduleFor( assert.equal(count, 1, "removed observer shouldn't fire"); } - async ['@test local observers can be removed'](assert) { - let barObserved = 0; - - let MyMixin = Mixin.create({ - foo1: observer('bar', function () { - barObserved++; - }), - - foo2: observer('bar', function () { - barObserved++; - }), - }); - - obj = {}; - MyMixin.apply(obj); - - set(obj, 'bar', 'HI!'); - await runLoopSettled(); - - assert.equal(barObserved, 2, 'precond - observers should be fired'); - - removeObserver(obj, 'bar', null, 'foo1'); - - barObserved = 0; - set(obj, 'bar', 'HI AGAIN!'); - await runLoopSettled(); - - assert.equal(barObserved, 1, 'removed observers should not be called'); - } - async ['@test removeObserver should respect targets with methods'](assert) { let observed = { foo: 'foo' }; diff --git a/packages/@ember/-internals/runtime/tests/mixins/observable_test.js b/packages/@ember/-internals/runtime/tests/mixins/observable_test.js deleted file mode 100644 index 22266dfc644..00000000000 --- a/packages/@ember/-internals/runtime/tests/mixins/observable_test.js +++ /dev/null @@ -1,125 +0,0 @@ -import { addObserver } from '@ember/-internals/metal'; -import EmberObject, { computed, get } from '@ember/object'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; - -moduleFor( - 'mixins/observable', - class extends AbstractTestCase { - ['@test should be able to use getProperties to get a POJO of provided keys'](assert) { - let obj = EmberObject.create({ - firstName: 'Steve', - lastName: 'Jobs', - companyName: 'Apple, Inc.', - }); - - let pojo = obj.getProperties('firstName', 'lastName'); - assert.equal('Steve', pojo.firstName); - assert.equal('Jobs', pojo.lastName); - } - - ['@test should be able to use getProperties with array parameter to get a POJO of provided keys']( - assert - ) { - let obj = EmberObject.create({ - firstName: 'Steve', - lastName: 'Jobs', - companyName: 'Apple, Inc.', - }); - - let pojo = obj.getProperties(['firstName', 'lastName']); - assert.equal('Steve', pojo.firstName); - assert.equal('Jobs', pojo.lastName); - } - - ['@test should be able to use setProperties to set multiple properties at once'](assert) { - let obj = EmberObject.create({ - firstName: 'Steve', - lastName: 'Jobs', - companyName: 'Apple, Inc.', - }); - - obj.setProperties({ firstName: 'Tim', lastName: 'Cook' }); - assert.equal('Tim', obj.get('firstName')); - assert.equal('Cook', obj.get('lastName')); - } - - async ['@test calling setProperties completes safely despite exceptions'](assert) { - let exc = new Error('Something unexpected happened!'); - let obj = class extends EmberObject { - @computed - get companyName() { - return 'Apple, Inc.'; - } - set companyName(value) { - throw exc; - } - }.create({ - firstName: 'Steve', - lastName: 'Jobs', - }); - - let firstNameChangedCount = 0; - - addObserver(obj, 'firstName', () => firstNameChangedCount++); - - try { - obj.setProperties({ - firstName: 'Tim', - lastName: 'Cook', - companyName: 'Fruit Co., Inc.', - }); - } catch (err) { - if (err !== exc) { - throw err; - } - } - - await runLoopSettled(); - - assert.equal(firstNameChangedCount, 1, 'firstName should have fired once'); - - obj.destroy(); - } - - ['@test should be able to retrieve cached values of computed properties without invoking the computed property']( - assert - ) { - let obj = class extends EmberObject { - @computed - get foo() { - return 'foo'; - } - }.create({ - bar: 'bar', - }); - - assert.equal( - obj.cacheFor('foo'), - undefined, - 'should return undefined if no value has been cached' - ); - get(obj, 'foo'); - - assert.equal(get(obj, 'foo'), 'foo', 'precond - should cache the value'); - assert.equal( - obj.cacheFor('foo'), - 'foo', - 'should return the cached value after it is invoked' - ); - - assert.equal( - obj.cacheFor('bar'), - undefined, - 'returns undefined if the value is not a computed property' - ); - } - - ['@test incrementProperty should work even if value is number in string'](assert) { - let obj = EmberObject.create({ - age: '24', - }); - obj.incrementProperty('age'); - assert.equal(25, obj.get('age')); - } - } -); diff --git a/packages/@ember/-internals/runtime/tests/system/core_object_test.js b/packages/@ember/-internals/runtime/tests/system/core_object_test.js index 1649c657a4d..68508e072af 100644 --- a/packages/@ember/-internals/runtime/tests/system/core_object_test.js +++ b/packages/@ember/-internals/runtime/tests/system/core_object_test.js @@ -1,13 +1,7 @@ import { getOwner, setOwner } from '@ember/-internals/owner'; -import { get, set, observer } from '@ember/object'; +import { get, set } from '@ember/object'; import CoreObject from '@ember/object/core'; -import { - moduleFor, - AbstractTestCase, - buildOwner, - runDestroy, - runLoopSettled, -} from 'internal-test-helpers'; +import { moduleFor, AbstractTestCase, buildOwner, runDestroy } from 'internal-test-helpers'; import { track } from '@glimmer/validator'; import { destroy } from '@glimmer/destroyable'; import { run } from '@ember/runloop'; @@ -97,32 +91,6 @@ moduleFor( TestObj.create(options); } - async ['@test observed properties are enumerable when set GH#14594'](assert) { - let callCount = 0; - let Test = CoreObject.extend({ - myProp: null, - anotherProp: undefined, - didChangeMyProp: observer('myProp', function () { - callCount++; - }), - }); - - let test = Test.create(); - set(test, 'id', '3'); - set(test, 'myProp', { id: 1 }); - - assert.deepEqual(Object.keys(test).sort(), ['id', 'myProp']); - - set(test, 'anotherProp', 'nice'); - - assert.deepEqual(Object.keys(test).sort(), ['anotherProp', 'id', 'myProp']); - await runLoopSettled(); - - assert.equal(callCount, 1); - - test.destroy(); - } - ['@test native getters/setters do not cause rendering invalidation during init'](assert) { let objectMeta = Object.create(null); diff --git a/packages/@ember/-internals/runtime/tests/system/namespace/base_test.js b/packages/@ember/-internals/runtime/tests/system/namespace/base_test.js index 2f6cc68012a..5febf108068 100644 --- a/packages/@ember/-internals/runtime/tests/system/namespace/base_test.js +++ b/packages/@ember/-internals/runtime/tests/system/namespace/base_test.js @@ -3,6 +3,7 @@ import { run } from '@ember/runloop'; import { get, setNamespaceSearchDisabled } from '@ember/-internals/metal'; import { guidFor, getName } from '@ember/-internals/utils'; import EmberObject from '@ember/object'; +import CoreObject from '@ember/object/core'; import Namespace from '@ember/application/namespace'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; @@ -30,8 +31,8 @@ moduleFor( context.lookup = originalLookup; } - ['@test Namespace should be a subclass of EmberObject'](assert) { - assert.ok(EmberObject.detect(Namespace)); + ['@test Namespace should be a subclass of CoreObject'](assert) { + assert.ok(CoreObject.detect(Namespace)); } ['@test Namespace should be duck typed'](assert) { diff --git a/packages/@ember/-internals/views/lib/component_lookup.ts b/packages/@ember/-internals/views/lib/component_lookup.ts index dd284ef67cf..af2cef048fb 100644 --- a/packages/@ember/-internals/views/lib/component_lookup.ts +++ b/packages/@ember/-internals/views/lib/component_lookup.ts @@ -1,7 +1,7 @@ import type { InternalOwner, RegisterOptions } from '@ember/-internals/owner'; -import EmberObject from '@ember/object'; +import CoreObject from '@ember/object/core'; -export default class ComponentLookup extends EmberObject { +export default class ComponentLookup extends CoreObject { componentFor(name: string, owner: InternalOwner) { let fullName = `component:${name}` as const; return owner.factoryFor(fullName); diff --git a/packages/@ember/-internals/views/lib/system/event_dispatcher.ts b/packages/@ember/-internals/views/lib/system/event_dispatcher.ts index f2f1c19b4f9..e53a6d97d86 100644 --- a/packages/@ember/-internals/views/lib/system/event_dispatcher.ts +++ b/packages/@ember/-internals/views/lib/system/event_dispatcher.ts @@ -1,7 +1,7 @@ import { getOwner } from '@ember/-internals/owner'; import { assert } from '@ember/debug'; import { get, set } from '@ember/-internals/metal'; -import EmberObject from '@ember/object'; +import CoreObject from '@ember/object/core'; import { getElementView } from './utils'; import ActionManager from './action_manager'; import type { BootEnvironment } from '@ember/-internals/glimmer/lib/views/outlet'; @@ -24,9 +24,9 @@ const ROOT_ELEMENT_SELECTOR = `.${ROOT_ELEMENT_CLASS}`; @class EventDispatcher @namespace Ember @private - @extends EmberObject + @extends CoreObject */ -export default class EventDispatcher extends EmberObject { +export default class EventDispatcher extends CoreObject { /** The set of events names (and associated handler function names) to be setup and dispatched by the `EventDispatcher`. Modifications to this list can be done diff --git a/packages/@ember/-internals/views/lib/views/core_view.ts b/packages/@ember/-internals/views/lib/views/core_view.ts index 899101871a9..3564b84cade 100644 --- a/packages/@ember/-internals/views/lib/views/core_view.ts +++ b/packages/@ember/-internals/views/lib/views/core_view.ts @@ -1,4 +1,5 @@ import type { Renderer, View } from '@ember/-internals/glimmer/lib/renderer'; +import { getFactoryFor } from '@ember/-internals/container'; import { inject } from '@ember/-internals/metal'; import { FrameworkObject } from '@ember/object/-internals'; import type { ViewState } from './states'; @@ -49,6 +50,11 @@ class CoreView extends FrameworkObject { this._currentState = this._states.preRender; } + get _debugContainerKey() { + let factory = getFactoryFor(this); + return factory !== undefined && factory.fullName; + } + @inject('renderer', '-dom') declare renderer: Renderer; diff --git a/packages/@ember/application/namespace.ts b/packages/@ember/application/namespace.ts index f561d4281bb..bcbbc94b11d 100644 --- a/packages/@ember/application/namespace.ts +++ b/packages/@ember/application/namespace.ts @@ -15,7 +15,7 @@ import { import { get } from '@ember/object'; import { getName, guidFor, setName } from '@ember/-internals/utils'; import { assert } from '@ember/debug'; -import EmberObject from '@ember/object'; +import CoreObject from '@ember/object/core'; /** A Namespace is an object usually used to contain other objects or methods @@ -34,7 +34,7 @@ import EmberObject from '@ember/object'; @extends EmberObject @public */ -class Namespace extends EmberObject { +class Namespace extends CoreObject { static NAMESPACES = NAMESPACES; static NAMESPACES_BY_ID = NAMESPACES_BY_ID; static processAll = processAllNamespaces; diff --git a/packages/@ember/application/tests/reset_test.js b/packages/@ember/application/tests/reset_test.js index 1d2c571bfcc..07f57dee7c9 100644 --- a/packages/@ember/application/tests/reset_test.js +++ b/packages/@ember/application/tests/reset_test.js @@ -1,5 +1,6 @@ import { run } from '@ember/runloop'; import Controller from '@ember/controller'; +import { get } from '@ember/object'; import Router from '@ember/routing/router'; import { EventDispatcher } from '@ember/-internals/views'; import { moduleFor, AutobootApplicationTestCase } from 'internal-test-helpers'; @@ -125,7 +126,7 @@ moduleFor( .then(() => { initialApplicationController = this.applicationInstance.lookup('controller:application'); initialRouter = this.applicationInstance.lookup('router:main'); - let location = initialRouter.get('location'); + let location = get(initialRouter, 'location'); assert.equal(location.getURL(), '/one'); assert.equal(initialRouter.currentPath, 'one'); @@ -147,7 +148,7 @@ moduleFor( .then(() => { let applicationController = this.applicationInstance.lookup('controller:application'); let router = this.applicationInstance.lookup('router:main'); - let location = router.get('location'); + let location = get(router, 'location'); assert.notEqual(initialRouter, router, 'a different router instance was created'); assert.notEqual( diff --git a/packages/@ember/application/tests/visit_test.js b/packages/@ember/application/tests/visit_test.js index 3d3b16e778c..ca55a272b62 100644 --- a/packages/@ember/application/tests/visit_test.js +++ b/packages/@ember/application/tests/visit_test.js @@ -7,6 +7,7 @@ import { } from 'internal-test-helpers'; import { service } from '@ember/service'; import EmberObject from '@ember/object'; +import { get, set } from '@ember/object'; import { RSVP, onerrorDefault } from '@ember/-internals/runtime'; import { later } from '@ember/runloop'; import { action } from '@ember/object'; @@ -650,7 +651,7 @@ moduleFor( value = 0; increment() { - this.incrementProperty('value'); + set(this, 'value', this.value + 1); } }; @@ -687,8 +688,8 @@ moduleFor( } click() { - this.get('isolatedCounter').increment(); - this.get('sharedCounter').increment(); + get(this, 'isolatedCounter').increment(); + get(this, 'sharedCounter').increment(); } } ) @@ -706,7 +707,7 @@ moduleFor( @action incrementCounter() { - this.get('counter').increment(); + get(this, 'counter').increment(); } init() { diff --git a/packages/@ember/controller/tests/controller_test.js b/packages/@ember/controller/tests/controller_test.js index e7d4a6f0b51..f5553f8ace6 100644 --- a/packages/@ember/controller/tests/controller_test.js +++ b/packages/@ember/controller/tests/controller_test.js @@ -37,33 +37,6 @@ moduleFor( runTask(() => this.$('button').click()); this.assertText('2'); } - - async '@test model can be observed with sync observers'(assert) { - let observerRunCount = 0; - - this.add( - 'controller:index', - class extends Controller { - constructor() { - super(...arguments); - this.model = 0; - - this.addObserver('model', this, () => observerRunCount++, true); - } - - @action - update() { - this.model++; - } - } - ); - - this.addTemplate('index', ''); - - await this.visit('/'); - runTask(() => this.$('button').click()); - assert.equal(observerRunCount, 1, 'observer ran exactly once'); - } } ); @@ -80,8 +53,8 @@ moduleFor( }.create(); }); - assert.notEqual(controller.get('model'), 'foo-bar', 'model is set properly'); - assert.equal(controller.get('content'), 'foo-bar', 'content is not set properly'); + assert.notEqual(get(controller, 'model'), 'foo-bar', 'model is set properly'); + assert.equal(get(controller, 'content'), 'foo-bar', 'content is not set properly'); } ['@test specifying `content` (without `model` specified) does not result in deprecation']( @@ -151,7 +124,7 @@ moduleFor( assert.equal( postsController, - postController.get('postsController'), + get(postController, 'postsController'), 'controller.posts is injected' ); @@ -174,7 +147,7 @@ moduleFor( let appController = owner.lookup('controller:application'); let authService = owner.lookup('service:auth'); - assert.equal(authService, appController.get('authService'), 'service.auth is injected'); + assert.equal(authService, get(appController, 'authService'), 'service.auth is injected'); runDestroy(owner); } diff --git a/packages/@ember/controller/type-tests/index.test.ts b/packages/@ember/controller/type-tests/index.test.ts index 35d37da6dbe..bece187b92b 100644 --- a/packages/@ember/controller/type-tests/index.test.ts +++ b/packages/@ember/controller/type-tests/index.test.ts @@ -15,10 +15,6 @@ let controller = new Controller(owner); expectTypeOf(controller).toEqualTypeOf>(); -// Has observable methods -expectTypeOf(controller.get).toBeFunction(); -expectTypeOf(controller.set).toBeFunction(); - expectTypeOf(controller.target).toEqualTypeOf(); expectTypeOf(controller.model).toEqualTypeOf(); diff --git a/packages/@ember/object/index.ts b/packages/@ember/object/index.ts index f46fb565fe1..db705577b1a 100644 --- a/packages/@ember/object/index.ts +++ b/packages/@ember/object/index.ts @@ -1,26 +1,7 @@ import { assert } from '@ember/debug'; -import { ENV } from '@ember/-internals/environment'; import type { ElementDescriptor, ExtendedMethodDecorator } from '@ember/-internals/metal'; -import { - isElementDescriptor, - expandProperties, - setClassicDecorator, - hasListeners, - beginPropertyChanges, - notifyPropertyChange, - endPropertyChanges, - addObserver, - removeObserver, - get, - set, - getProperties, - setProperties, -} from '@ember/-internals/metal'; -import { getFactoryFor } from '@ember/-internals/container'; -import { setObservers } from '@ember/-internals/utils'; -import type { AnyFn } from '@ember/-internals/utility-types'; +import { isElementDescriptor, setClassicDecorator } from '@ember/-internals/metal'; import CoreObject from '@ember/object/core'; -import { peekMeta } from '@ember/-internals/meta'; export { notifyPropertyChange, @@ -33,10 +14,6 @@ export { trySet, } from '@ember/-internals/metal'; -type ObserverMethod = - | (keyof Target & string) - | ((this: Target, sender: Sender, key: string, value: any, rev: number) => void); - /** @module @ember/object */ @@ -48,436 +25,7 @@ type ObserverMethod = @extends CoreObject @public */ -class EmberObject extends CoreObject { - /** - Retrieves the value of a property from the object. - - This method is usually similar to using `object[keyName]` or `object.keyName`, - however it supports both computed properties and the unknownProperty - handler. - - Because `get` unifies the syntax for accessing all these kinds - of properties, it can make many refactorings easier, such as replacing a - simple property with a computed property, or vice versa. - - ### Computed Properties - - Computed properties are methods defined with the `property` modifier - declared at the end, such as: - - ```javascript - import { computed } from '@ember/object'; - - fullName: computed('firstName', 'lastName', function() { - return this.get('firstName') + ' ' + this.get('lastName'); - }) - ``` - - When you call `get` on a computed property, the function will be - called and the return value will be returned instead of the function - itself. - - ### Unknown Properties - - Likewise, if you try to call `get` on a property whose value is - `undefined`, the `unknownProperty()` method will be called on the object. - If this method returns any value other than `undefined`, it will be returned - instead. This allows you to implement "virtual" properties that are - not defined upfront. - - @method get - @param {String} keyName The property to retrieve - @return {Object} The property value or undefined. - @public - */ - get(key: K): this[K]; - get(key: string): unknown; - get(keyName: string) { - return get(this, keyName); - } - /** - To get the values of multiple properties at once, call `getProperties` - with a list of strings or an array: - - ```javascript - record.getProperties('firstName', 'lastName', 'zipCode'); - // { firstName: 'John', lastName: 'Doe', zipCode: '10011' } - ``` - - is equivalent to: - - ```javascript - record.getProperties(['firstName', 'lastName', 'zipCode']); - // { firstName: 'John', lastName: 'Doe', zipCode: '10011' } - ``` - - @method getProperties - @param {String...|Array} list of keys to get - @return {Object} - @public - */ - getProperties>(list: L): { [Key in L[number]]: this[Key] }; - getProperties>(...list: L): { [Key in L[number]]: this[Key] }; - getProperties(list: L): { [Key in L[number]]: unknown }; - getProperties(...list: L): { [Key in L[number]]: unknown }; - getProperties(...args: string[]) { - return getProperties(this, ...args); - } - // NOT TYPE SAFE! - /** - Sets the provided key or path to the value. - - ```javascript - record.set("key", value); - ``` - - This method is generally very similar to calling `object["key"] = value` or - `object.key = value`, except that it provides support for computed - properties, the `setUnknownProperty()` method and property observers. - - ### Computed Properties - - If you try to set a value on a key that has a computed property handler - defined (see the `get()` method for an example), then `set()` will call - that method, passing both the value and key instead of simply changing - the value itself. This is useful for those times when you need to - implement a property that is composed of one or more member - properties. - - ### Unknown Properties - - If you try to set a value on a key that is undefined in the target - object, then the `setUnknownProperty()` handler will be called instead. This - gives you an opportunity to implement complex "virtual" properties that - are not predefined on the object. If `setUnknownProperty()` returns - undefined, then `set()` will simply set the value on the object. - - ### Property Observers - - In addition to changing the property, `set()` will also register a property - change with the object. Unless you have placed this call inside of a - `beginPropertyChanges()` and `endPropertyChanges(),` any "local" observers - (i.e. observer methods declared on the same object), will be called - immediately. Any "remote" observers (i.e. observer methods declared on - another object) will be placed in a queue and called at a later time in a - coalesced manner. - - @method set - @param {String} keyName The property to set - @param {Object} value The value to set or `null`. - @return {Object} The passed value - @public - */ - set(key: K, value: T): T; - set(key: string, value: T): T; - set(keyName: string, value: unknown) { - return set(this, keyName, value); - } - // NOT TYPE SAFE! - /** - Sets a list of properties at once. These properties are set inside - a single `beginPropertyChanges` and `endPropertyChanges` batch, so - observers will be buffered. - - ```javascript - record.setProperties({ firstName: 'Charles', lastName: 'Jolley' }); - ``` - - @method setProperties - @param {Object} hash the hash of keys and values to set - @return {Object} The passed in hash - @public - */ - setProperties(hash: P): P; - setProperties>(hash: T): T; - setProperties(hash: object) { - return setProperties(this, hash); - } - - /** - Begins a grouping of property changes. - - You can use this method to group property changes so that notifications - will not be sent until the changes are finished. If you plan to make a - large number of changes to an object at one time, you should call this - method at the beginning of the changes to begin deferring change - notifications. When you are done making changes, call - `endPropertyChanges()` to deliver the deferred change notifications and end - deferring. - - @method beginPropertyChanges - @return {Observable} - @private - */ - beginPropertyChanges() { - beginPropertyChanges(); - return this; - } - - /** - Ends a grouping of property changes. - - You can use this method to group property changes so that notifications - will not be sent until the changes are finished. If you plan to make a - large number of changes to an object at one time, you should call - `beginPropertyChanges()` at the beginning of the changes to defer change - notifications. When you are done making changes, call this method to - deliver the deferred change notifications and end deferring. - - @method endPropertyChanges - @return {Observable} - @private - */ - endPropertyChanges() { - endPropertyChanges(); - return this; - } - /** - Convenience method to call `propertyWillChange` and `propertyDidChange` in - succession. - - Notify the observer system that a property has just changed. - - Sometimes you need to change a value directly or indirectly without - actually calling `get()` or `set()` on it. In this case, you can use this - method instead. Calling this method will notify all observers that the - property has potentially changed value. - - @method notifyPropertyChange - @param {String} keyName The property key to be notified about. - @return {Observable} - @public - */ - notifyPropertyChange(keyName: string) { - notifyPropertyChange(this, keyName); - return this; - } - - /** - Adds an observer on a property. - - This is the core method used to register an observer for a property. - - Once you call this method, any time the key's value is set, your observer - will be notified. Note that the observers are triggered any time the - value is set, regardless of whether it has actually changed. Your - observer should be prepared to handle that. - - There are two common invocation patterns for `.addObserver()`: - - - Passing two arguments: - - the name of the property to observe (as a string) - - the function to invoke (an actual function) - - Passing three arguments: - - the name of the property to observe (as a string) - - the target object (will be used to look up and invoke a - function on) - - the name of the function to invoke on the target object - (as a string). - - ```app/components/my-component.js - import Component from '@ember/component'; - - export default Component.extend({ - init() { - this._super(...arguments); - - // the following are equivalent: - - // using three arguments - this.addObserver('foo', this, 'fooDidChange'); - - // using two arguments - this.addObserver('foo', (...args) => { - this.fooDidChange(...args); - }); - }, - - fooDidChange() { - // your custom logic code - } - }); - ``` - - ### Observer Methods - - Observer methods have the following signature: - - ```app/components/my-component.js - import Component from '@ember/component'; - - export default Component.extend({ - init() { - this._super(...arguments); - this.addObserver('foo', this, 'fooDidChange'); - }, - - fooDidChange(sender, key, value, rev) { - // your code - } - }); - ``` - - The `sender` is the object that changed. The `key` is the property that - changes. The `value` property is currently reserved and unused. The `rev` - is the last property revision of the object when it changed, which you can - use to detect if the key value has really changed or not. - - Usually you will not need the value or revision parameters at - the end. In this case, it is common to write observer methods that take - only a sender and key value as parameters or, if you aren't interested in - any of these values, to write an observer that has no parameters at all. - - @method addObserver - @param {String} key The key to observe - @param {Object} target The target object to invoke - @param {String|Function} method The method to invoke - @param {Boolean} sync Whether the observer is sync or not - @return {Observable} - @public - */ - addObserver( - key: keyof this & string, - target: Target, - method: ObserverMethod - ): this; - addObserver(key: keyof this & string, method: ObserverMethod): this; - addObserver( - key: string, - target: Target, - method?: ObserverMethod, - sync?: boolean - ) { - addObserver(this, key, target, method, sync); - return this; - } - - /** - Remove an observer you have previously registered on this object. Pass - the same key, target, and method you passed to `addObserver()` and your - target will no longer receive notifications. - - @method removeObserver - @param {String} key The key to observe - @param {Object} target The target object to invoke - @param {String|Function} method The method to invoke - @param {Boolean} sync Whether the observer is async or not - @return {Observable} - @public - */ - removeObserver( - key: keyof this & string, - target: Target, - method: ObserverMethod - ): this; - removeObserver(key: keyof this & string, method: ObserverMethod): this; - removeObserver( - key: string, - target: Target, - method?: string | Function, - sync?: boolean - ) { - removeObserver(this, key, target, method, sync); - return this; - } - - /** - Returns `true` if the object currently has observers registered for a - particular key. You can use this method to potentially defer performing - an expensive action until someone begins observing a particular property - on the object. - - @method hasObserverFor - @param {String} key Key to check - @return {Boolean} - @private - */ - hasObserverFor(key: string) { - return hasListeners(this, `${key}:change`); - } - - // NOT TYPE SAFE! - /** - Set the value of a property to the current value plus some amount. - - ```javascript - person.incrementProperty('age'); - team.incrementProperty('score', 2); - ``` - - @method incrementProperty - @param {String} keyName The name of the property to increment - @param {Number} increment The amount to increment by. Defaults to 1 - @return {Number} The new property value - @public - */ - incrementProperty(keyName: keyof this & string, increment = 1): number { - assert( - 'Must pass a numeric value to incrementProperty', - !isNaN(parseFloat(String(increment))) && isFinite(increment) - ); - return set(this, keyName, (parseFloat(get(this, keyName) as string) || 0) + increment); - } - // NOT TYPE SAFE! - /** - Set the value of a property to the current value minus some amount. - - ```javascript - player.decrementProperty('lives'); - orc.decrementProperty('health', 5); - ``` - - @method decrementProperty - @param {String} keyName The name of the property to decrement - @param {Number} decrement The amount to decrement by. Defaults to 1 - @return {Number} The new property value - @public - */ - decrementProperty(keyName: keyof this & string, decrement = 1): number { - assert( - 'Must pass a numeric value to decrementProperty', - (typeof decrement === 'number' || !isNaN(parseFloat(decrement))) && isFinite(decrement) - ); - return set(this, keyName, ((get(this, keyName) as number) || 0) - decrement); - } - // NOT TYPE SAFE! - /** - Set the value of a boolean property to the opposite of its - current value. - - ```javascript - starship.toggleProperty('warpDriveEngaged'); - ``` - - @method toggleProperty - @param {String} keyName The name of the property to toggle - @return {Boolean} The new property value - @public - */ - toggleProperty(keyName: keyof this & string): boolean { - return set(this, keyName, !get(this, keyName)); - } - /** - Returns the cached value of a computed property, if it exists. - This allows you to inspect the value of a computed property - without accidentally invoking it if it is intended to be - generated lazily. - - @method cacheFor - @param {String} keyName - @return {Object} The cached value of the computed property, if any - @public - */ - cacheFor(keyName: keyof this & string): unknown { - let meta = peekMeta(this); - return meta !== null ? meta.valueFor(keyName) : undefined; - } - - get _debugContainerKey() { - let factory = getFactoryFor(this); - return factory !== undefined && factory.fullName; - } -} +class EmberObject extends CoreObject {} export default EmberObject; @@ -659,86 +207,3 @@ export function action( // SAFETY: TS types are weird with decorators. This should work. setClassicDecorator(action as ExtendedMethodDecorator); - -// .......................................................... -// OBSERVER HELPER -// - -type ObserverDefinition = { - dependentKeys: string[]; - fn: T; - sync: boolean; -}; - -/** - Specify a method that observes property changes. - - ```javascript - import EmberObject from '@ember/object'; - import { observer } from '@ember/object'; - - export default EmberObject.extend({ - valueObserver: observer('value', function() { - // Executes whenever the "value" property changes - }) - }); - ``` - - Also available as `Function.prototype.observes` if prototype extensions are - enabled. - - @method observer - @for @ember/object - @param {String} propertyNames* - @param {Function} func - @return func - @public - @static -*/ -export function observer( - ...args: - | [propertyName: string, ...additionalPropertyNames: string[], func: T] - | [ObserverDefinition] -): T { - let funcOrDef = args.pop(); - - assert( - 'observer must be provided a function or an observer definition', - typeof funcOrDef === 'function' || (typeof funcOrDef === 'object' && funcOrDef !== null) - ); - - let func: T; - let dependentKeys: string[]; - let sync: boolean; - - if (typeof funcOrDef === 'function') { - func = funcOrDef; - dependentKeys = args as string[]; - sync = !ENV._DEFAULT_ASYNC_OBSERVERS; - } else { - func = funcOrDef.fn; - dependentKeys = funcOrDef.dependentKeys; - sync = funcOrDef.sync; - } - - assert('observer called without a function', typeof func === 'function'); - assert( - 'observer called without valid path', - Array.isArray(dependentKeys) && - dependentKeys.length > 0 && - dependentKeys.every((p) => typeof p === 'string' && Boolean(p.length)) - ); - assert('observer called without sync', typeof sync === 'boolean'); - - let paths: string[] = []; - - for (let dependentKey of dependentKeys) { - expandProperties(dependentKey, (path: string) => paths.push(path)); - } - - setObservers(func as Function, { - paths, - sync, - }); - return func; -} diff --git a/packages/@ember/object/tests/computed/dependent-key-compat-test.js b/packages/@ember/object/tests/computed/dependent-key-compat-test.js index 72dc33d5eb7..7409ed780d5 100644 --- a/packages/@ember/object/tests/computed/dependent-key-compat-test.js +++ b/packages/@ember/object/tests/computed/dependent-key-compat-test.js @@ -1,7 +1,7 @@ -import EmberObject, { computed, observer } from '@ember/object'; +import EmberObject, { computed } from '@ember/object'; import { tracked } from '@ember/-internals/metal'; import { dependentKeyCompat } from '@ember/object/compat'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; moduleFor( 'dependentKeyCompat', @@ -58,74 +58,76 @@ moduleFor( assert.equal(tom.fullName, 'Thomas Dale'); } - async '@test it works with async observers'(assert) { - let count = 0; + // TODO: Determine if there's anything useful to test here with observer helper gone + // async '@test it works with async observers'(assert) { + // let count = 0; - let Person = EmberObject.extend({ - firstName: tracked({ value: 'Tom' }), - lastName: tracked({ value: 'Dale' }), + // let Person = EmberObject.extend({ + // firstName: tracked({ value: 'Tom' }), + // lastName: tracked({ value: 'Dale' }), - givenName: dependentKeyCompat({ - get() { - return this.firstName; - }, - }), + // givenName: dependentKeyCompat({ + // get() { + // return this.firstName; + // }, + // }), - givenNameObserver: observer({ - dependentKeys: ['givenName'], - fn() { - count++; - }, - sync: false, - }), - }); + // givenNameObserver: observer({ + // dependentKeys: ['givenName'], + // fn() { + // count++; + // }, + // sync: false, + // }), + // }); - let tom = Person.create(); + // let tom = Person.create(); - assert.equal(count, 0); + // assert.equal(count, 0); - // check the alias, and bootstrap it - assert.equal(tom.givenName, 'Tom', 'alias works'); + // // check the alias, and bootstrap it + // assert.equal(tom.givenName, 'Tom', 'alias works'); - tom.firstName = 'Thomas'; - await runLoopSettled(); + // tom.firstName = 'Thomas'; + // await runLoopSettled(); - assert.equal(count, 1); + // assert.equal(count, 1); - tom.destroy(); - } + // tom.destroy(); + // } - '@test it does not work with sync observers'(assert) { - let count = 0; + // TODO: Determine if there's anything useful to test here with observer helper gone + // '@test it does not work with sync observers'(assert) { + // let count = 0; - let Person = EmberObject.extend({ - firstName: tracked({ value: 'Tom' }), - lastName: tracked({ value: 'Dale' }), + // let Person = EmberObject.extend({ + // firstName: tracked({ value: 'Tom' }), + // lastName: tracked({ value: 'Dale' }), - givenName: dependentKeyCompat({ - get() { - return this.firstName; - }, - }), + // givenName: dependentKeyCompat({ + // get() { + // return this.firstName; + // }, + // }), - givenNameObserver: observer({ - dependentKeys: ['givenName'], - fn() { - count++; - }, - sync: true, - }), - }); + // givenNameObserver: observer({ + // dependentKeys: ['givenName'], + // fn() { + // count++; + // }, + // sync: true, + // }), + // }); - let tom = Person.create(); + // let tom = Person.create(); - assert.equal(count, 0); + // assert.equal(count, 0); - tom.firstName = 'Thomas'; + // tom.firstName = 'Thomas'; - assert.equal(count, 0); + // assert.equal(count, 0); - tom.destroy(); - } + // tom.destroy(); + // } } ); diff --git a/packages/@ember/object/tests/computed_test.js b/packages/@ember/object/tests/computed_test.js index e2d52f15f4a..57e54ca0813 100644 --- a/packages/@ember/object/tests/computed_test.js +++ b/packages/@ember/object/tests/computed_test.js @@ -1,16 +1,12 @@ import { notifyPropertyChange } from '@ember/-internals/metal'; -import { alias, oneWay as reads } from '@ember/object/computed'; -import EmberObject, { defineProperty, get, set, computed, observer } from '@ember/object'; +import { alias } from '@ember/object/computed'; +import EmberObject, { get, set, computed } from '@ember/object'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; -function K() { - return this; -} - function testGet(assert, expect, x, y) { assert.equal(get(x, y), expect); assert.equal(get(x, y), expect); - assert.equal(x.get(y), expect); + assert.equal(get(x, y), expect); } moduleFor( @@ -174,133 +170,119 @@ moduleFor( }, "metaForProperty() could not find a computed property with key 'staticProperty'."); } - ['@test overriding a computed property with null removes it from eachComputedProperty iteration']( - assert - ) { - let MyClass = EmberObject.extend({ - foo: computed(function () {}), - - fooDidChange: observer('foo', function () {}), - - bar: computed(function () {}), - }); - - let SubClass = MyClass.extend({ - foo: null, - }); + // TODO: Determine if there's anything worth testing here now that observer helper is gone + // ['@test overriding a computed property with null removes it from eachComputedProperty iteration']( + // assert + // ) { + // let MyClass = EmberObject.extend({ + // foo: computed(function () {}), - let list = []; + // fooDidChange: observer('foo', function () {}), - SubClass.eachComputedProperty((name) => list.push(name)); + // bar: computed(function () {}), + // }); - assert.deepEqual( - list.sort(), - ['bar'], - 'overridding with null removes from eachComputedProperty listing' - ); - } + // let SubClass = MyClass.extend({ + // foo: null, + // }); - ['@test can iterate over a list of computed properties for a class'](assert) { - let MyClass = EmberObject.extend({ - foo: computed(function () {}), + // let list = []; - fooDidChange: observer('foo', function () {}), + // SubClass.eachComputedProperty((name) => list.push(name)); - bar: computed(function () {}), + // assert.deepEqual( + // list.sort(), + // ['bar'], + // 'overridding with null removes from eachComputedProperty listing' + // ); + // } - qux: alias('foo'), - }); + // TODO: Determine if there's anything worth testing here now that observer helper is gone + // ['@test can iterate over a list of computed properties for a class'](assert) { + // let MyClass = EmberObject.extend({ + // foo: computed(function () {}), - let SubClass = MyClass.extend({ - baz: computed(function () {}), - }); + // fooDidChange: observer('foo', function () {}), - SubClass.reopen({ - bat: computed(function () {}).meta({ iAmBat: true }), - }); + // bar: computed(function () {}), - let list = []; + // qux: alias('foo'), + // }); - MyClass.eachComputedProperty(function (name) { - list.push(name); - }); + // let SubClass = MyClass.extend({ + // baz: computed(function () {}), + // }); - assert.deepEqual( - list.sort(), - ['bar', 'foo', 'qux'], - 'watched and unwatched computed properties are iterated' - ); + // let list = []; - list = []; + // MyClass.eachComputedProperty(function (name) { + // list.push(name); + // }); - SubClass.eachComputedProperty(function (name, meta) { - list.push(name); + // assert.deepEqual( + // list.sort(), + // ['bar', 'foo', 'qux'], + // 'watched and unwatched computed properties are iterated' + // ); - if (name === 'bat') { - assert.deepEqual(meta, { iAmBat: true }); - } else { - assert.deepEqual(meta, {}); - } - }); + // list = []; - assert.deepEqual( - list.sort(), - ['bar', 'bat', 'baz', 'foo', 'qux'], - 'all inherited properties are included' - ); - } + // SubClass.eachComputedProperty(function (name, meta) { + // list.push(name); + // assert.deepEqual(meta, {}); + // }); - ['@test list of properties updates when an additional property is added (such cache busting)']( - assert - ) { - let MyClass = EmberObject.extend({ - foo: computed(K), + // assert.deepEqual( + // list.sort(), + // ['bar', 'baz', 'foo', 'qux'], + // 'all inherited properties are included' + // ); + // } - fooDidChange: observer('foo', function () {}), + // TODO: Determine if there's anything worth testing here now that observer helper is gone + // ['@test list of properties updates when an additional property is added (such cache busting)']( + // assert + // ) { + // let MyClass = EmberObject.extend({ + // foo: computed(K), - bar: computed(K), - }); + // fooDidChange: observer('foo', function () {}), - let list = []; + // bar: computed(K), + // }); - MyClass.eachComputedProperty(function (name) { - list.push(name); - }); + // let list = []; - assert.deepEqual(list.sort(), ['bar', 'foo'].sort(), 'expected two computed properties'); + // MyClass.eachComputedProperty(function (name) { + // list.push(name); + // }); - MyClass.reopen({ - baz: computed(K), - }); + // assert.deepEqual(list.sort(), ['bar', 'foo'].sort(), 'expected two computed properties'); - MyClass.create().destroy(); // force apply mixins + // MyClass.create().destroy(); // force apply mixins - list = []; + // list = []; - MyClass.eachComputedProperty(function (name) { - list.push(name); - }); + // MyClass.eachComputedProperty(function (name) { + // list.push(name); + // }); - assert.deepEqual( - list.sort(), - ['bar', 'foo', 'baz'].sort(), - 'expected three computed properties' - ); + // assert.deepEqual(list.sort(), ['bar', 'foo'].sort(), 'expected two computed properties'); - defineProperty(MyClass.prototype, 'qux', computed(K)); + // defineProperty(MyClass.prototype, 'qux', computed(K)); - list = []; + // list = []; - MyClass.eachComputedProperty(function (name) { - list.push(name); - }); + // MyClass.eachComputedProperty(function (name) { + // list.push(name); + // }); - assert.deepEqual( - list.sort(), - ['bar', 'foo', 'baz', 'qux'].sort(), - 'expected four computed properties' - ); - } + // assert.deepEqual( + // list.sort(), + // ['bar', 'foo', 'qux'].sort(), + // 'expected three computed properties' + // ); + // } ['@test Calling _super in call outside the immediate function of a CP getter works'](assert) { function macro(callback) { @@ -350,24 +332,6 @@ moduleFor( assert.ok(get(SubClass.create(), 'foo'), 'FOO', 'super value is fetched'); } - ['@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 () {}), - }); - - let obj1 = Obj.create({ name: '1' }); - let obj2 = Obj.create({ name: '2' }); - - assert.equal(obj1.get('name'), '1'); - assert.equal(obj2.get('name'), '2'); - - obj1.destroy(); - obj2.destroy(); - } - ['@test native getters and setters work'](assert) { let MyClass = class extends EmberObject { bar = 123; diff --git a/packages/@ember/object/tests/create_test.js b/packages/@ember/object/tests/create_test.js index 0c42957e53b..48c7677c649 100644 --- a/packages/@ember/object/tests/create_test.js +++ b/packages/@ember/object/tests/create_test.js @@ -4,7 +4,7 @@ import { addObserver } from '@ember/object/observers'; import Mixin from '@ember/object/mixin'; import Service, { service } from '@ember/service'; import { DEBUG } from '@glimmer/env'; -import EmberObject, { computed, observer } from '@ember/object'; +import EmberObject, { computed, get } from '@ember/object'; import { alias } from '@ember/object/computed'; import { buildOwner, moduleFor, runDestroy, AbstractTestCase } from 'internal-test-helpers'; import { destroy } from '@glimmer/destroyable'; @@ -16,7 +16,7 @@ moduleFor( expectNoDeprecation(); let o = EmberObject.create({ ohai: 'there' }); - assert.equal(o.get('ohai'), 'there'); + assert.equal(get(o, 'ohai'), 'there'); } ['@test explicit injection does not raise deprecation'](assert) { @@ -52,31 +52,32 @@ moduleFor( }); let o = MyClass.create({ foo: 'bar' }); - assert.equal(o.get('foo'), 'bar'); + assert.equal(get(o, 'foo'), 'bar'); } - ['@test sets up mandatory setters for simple properties watched with observers'](assert) { - if (DEBUG) { - let MyClass = EmberObject.extend({ - foo: null, - bar: null, - fooDidChange: observer('foo', function () {}), - }); + // TODO: Determine if there's anything useful to test here with observer helper gone + // ['@test sets up mandatory setters for simple properties watched with observers'](assert) { + // if (DEBUG) { + // let MyClass = EmberObject.extend({ + // foo: null, + // bar: null, + // fooDidChange: observer('foo', function () {}), + // }); - let o = MyClass.create({ foo: 'bar', bar: 'baz' }); - assert.equal(o.get('foo'), 'bar'); + // let o = MyClass.create({ foo: 'bar', bar: 'baz' }); + // assert.equal(o.get('foo'), 'bar'); - let descriptor = Object.getOwnPropertyDescriptor(o, 'foo'); - assert.ok(descriptor.set, 'Mandatory setter was setup'); + // let descriptor = Object.getOwnPropertyDescriptor(o, 'foo'); + // assert.ok(descriptor.set, 'Mandatory setter was setup'); - descriptor = Object.getOwnPropertyDescriptor(o, 'bar'); - assert.ok(!descriptor.set, 'Mandatory setter was not setup'); + // descriptor = Object.getOwnPropertyDescriptor(o, 'bar'); + // assert.ok(!descriptor.set, 'Mandatory setter was not setup'); - o.destroy(); - } else { - assert.expect(0); - } - } + // o.destroy(); + // } else { + // assert.expect(0); + // } + // } ['@test sets up mandatory setters for simple properties watched with computeds'](assert) { if (DEBUG) { @@ -90,7 +91,7 @@ moduleFor( }; let o = MyClass.create({ foo: 'bar', bar: 'baz' }); - assert.equal(o.get('fooAlias'), 'bar'); + assert.equal(get(o, 'fooAlias'), 'bar'); let descriptor = Object.getOwnPropertyDescriptor(o, 'foo'); assert.ok(descriptor.set, 'Mandatory setter was setup'); @@ -114,7 +115,7 @@ moduleFor( }; let o = MyClass.create({ foo: 'bar', bar: 'baz' }); - assert.equal(o.get('fooAlias'), 'bar'); + assert.equal(get(o, 'fooAlias'), 'bar'); let descriptor = Object.getOwnPropertyDescriptor(o, 'foo'); assert.ok(descriptor.set, 'Mandatory setter was setup'); @@ -128,27 +129,28 @@ moduleFor( } } - ['@test does not sets up separate mandatory setters on getters'](assert) { - if (DEBUG) { - let MyClass = EmberObject.extend({ - get foo() { - return 'bar'; - }, - fooDidChange: observer('foo', function () {}), - }); - - let o = MyClass.create({}); - assert.equal(o.get('foo'), 'bar'); - - let descriptor = Object.getOwnPropertyDescriptor(o, 'foo'); - assert.ok(!descriptor, 'Mandatory setter was not setup'); - - // cleanup - o.destroy(); - } else { - assert.expect(0); - } - } + // TODO: Determine if there's anything useful to test here with observer helper gone + // ['@test does not sets up separate mandatory setters on getters'](assert) { + // if (DEBUG) { + // let MyClass = EmberObject.extend({ + // get foo() { + // return 'bar'; + // }, + // fooDidChange: observer('foo', function () {}), + // }); + + // let o = MyClass.create({}); + // assert.equal(o.get('foo'), 'bar'); + + // let descriptor = Object.getOwnPropertyDescriptor(o, 'foo'); + // assert.ok(!descriptor, 'Mandatory setter was not setup'); + + // // cleanup + // o.destroy(); + // } else { + // assert.expect(0); + // } + // } ['@test does not sets up separate mandatory setters on arrays'](assert) { if (DEBUG) { diff --git a/packages/@ember/object/tests/destroy_test.js b/packages/@ember/object/tests/destroy_test.js index eea3ccdd957..5923402ee18 100644 --- a/packages/@ember/object/tests/destroy_test.js +++ b/packages/@ember/object/tests/destroy_test.js @@ -1,9 +1,7 @@ import { run } from '@ember/runloop'; -import { beginPropertyChanges, endPropertyChanges } from '@ember/-internals/metal'; import { peekMeta } from '@ember/-internals/meta'; -import EmberObject, { get, set, observer } from '@ember/object'; -import { DEBUG } from '@glimmer/env'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import EmberObject, { get } from '@ember/object'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; moduleFor( '@ember/-internals/runtime/system/object/destroy_test', @@ -24,124 +22,127 @@ moduleFor( assert.ok(get(obj, 'isDestroyed'), 'object is destroyed after run loop finishes'); } + // TODO: Determine if there's anything useful to test here with observer helper gone // MANDATORY_SETTER moves value to meta.values // a destroyed object removes meta but leaves the accessor // that looks it up - ['@test should raise an exception when modifying watched properties on a destroyed object']( - assert - ) { - if (DEBUG) { - let obj = EmberObject.extend({ - fooDidChange: observer('foo', function () {}), - }).create({ - foo: 'bar', - }); - - run(() => obj.destroy()); - - assert.throws(() => set(obj, 'foo', 'baz'), Error, 'raises an exception'); - } else { - assert.expect(0); - } - } - - async ['@test observers should not fire after an object has been destroyed'](assert) { - let count = 0; - let obj = EmberObject.extend({ - fooDidChange: observer('foo', function () { - count++; - }), - }).create(); - - obj.set('foo', 'bar'); - await runLoopSettled(); - - assert.equal(count, 1, 'observer was fired once'); - - beginPropertyChanges(); - obj.set('foo', 'quux'); - obj.destroy(); - endPropertyChanges(); - await runLoopSettled(); - - assert.equal(count, 1, 'observer was not called after object was destroyed'); - } - - async ['@test destroyed objects should not see each others changes during teardown but a long lived object should']( - assert - ) { - let shouldChange = 0; - let shouldNotChange = 0; - - let objs = {}; - - let A = EmberObject.extend({ - objs: objs, - isAlive: true, - willDestroy() { - this.set('isAlive', false); - }, - bDidChange: observer('objs.b.isAlive', function () { - shouldNotChange++; - }), - cDidChange: observer('objs.c.isAlive', function () { - shouldNotChange++; - }), - }); - - let B = EmberObject.extend({ - objs: objs, - isAlive: true, - willDestroy() { - this.set('isAlive', false); - }, - aDidChange: observer('objs.a.isAlive', function () { - shouldNotChange++; - }), - cDidChange: observer('objs.c.isAlive', function () { - shouldNotChange++; - }), - }); - - let C = EmberObject.extend({ - objs: objs, - isAlive: true, - willDestroy() { - this.set('isAlive', false); - }, - aDidChange: observer('objs.a.isAlive', function () { - shouldNotChange++; - }), - bDidChange: observer('objs.b.isAlive', function () { - shouldNotChange++; - }), - }); - - let LongLivedObject = EmberObject.extend({ - objs: objs, - isAliveDidChange: observer('objs.a.isAlive', function () { - shouldChange++; - }), - }); - - objs.a = A.create(); - - objs.b = B.create(); - - objs.c = C.create(); - - let longLived = LongLivedObject.create(); - - for (let obj in objs) { - objs[obj].destroy(); - } - - await runLoopSettled(); - - assert.equal(shouldNotChange, 0, 'destroyed graph objs should not see change in willDestroy'); - assert.equal(shouldChange, 1, 'long lived should see change in willDestroy'); - - longLived.destroy(); - } + // ['@test should raise an exception when modifying watched properties on a destroyed object']( + // assert + // ) { + // if (DEBUG) { + // let obj = EmberObject.extend({ + // fooDidChange: observer('foo', function () {}), + // }).create({ + // foo: 'bar', + // }); + + // run(() => obj.destroy()); + + // assert.throws(() => set(obj, 'foo', 'baz'), Error, 'raises an exception'); + // } else { + // assert.expect(0); + // } + // } + + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observers should not fire after an object has been destroyed'](assert) { + // let count = 0; + // let obj = EmberObject.extend({ + // fooDidChange: observer('foo', function () { + // count++; + // }), + // }).create(); + + // obj.set('foo', 'bar'); + // await runLoopSettled(); + + // assert.equal(count, 1, 'observer was fired once'); + + // beginPropertyChanges(); + // obj.set('foo', 'quux'); + // obj.destroy(); + // endPropertyChanges(); + // await runLoopSettled(); + + // assert.equal(count, 1, 'observer was not called after object was destroyed'); + // } + + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test destroyed objects should not see each others changes during teardown but a long lived object should']( + // assert + // ) { + // let shouldChange = 0; + // let shouldNotChange = 0; + + // let objs = {}; + + // let A = EmberObject.extend({ + // objs: objs, + // isAlive: true, + // willDestroy() { + // this.set('isAlive', false); + // }, + // bDidChange: observer('objs.b.isAlive', function () { + // shouldNotChange++; + // }), + // cDidChange: observer('objs.c.isAlive', function () { + // shouldNotChange++; + // }), + // }); + + // let B = EmberObject.extend({ + // objs: objs, + // isAlive: true, + // willDestroy() { + // this.set('isAlive', false); + // }, + // aDidChange: observer('objs.a.isAlive', function () { + // shouldNotChange++; + // }), + // cDidChange: observer('objs.c.isAlive', function () { + // shouldNotChange++; + // }), + // }); + + // let C = EmberObject.extend({ + // objs: objs, + // isAlive: true, + // willDestroy() { + // this.set('isAlive', false); + // }, + // aDidChange: observer('objs.a.isAlive', function () { + // shouldNotChange++; + // }), + // bDidChange: observer('objs.b.isAlive', function () { + // shouldNotChange++; + // }), + // }); + + // let LongLivedObject = EmberObject.extend({ + // objs: objs, + // isAliveDidChange: observer('objs.a.isAlive', function () { + // shouldChange++; + // }), + // }); + + // objs.a = A.create(); + + // objs.b = B.create(); + + // objs.c = C.create(); + + // let longLived = LongLivedObject.create(); + + // for (let obj in objs) { + // objs[obj].destroy(); + // } + + // await runLoopSettled(); + + // assert.equal(shouldNotChange, 0, 'destroyed graph objs should not see change in willDestroy'); + // assert.equal(shouldChange, 1, 'long lived should see change in willDestroy'); + + // longLived.destroy(); + // } } ); diff --git a/packages/@ember/object/tests/es-compatibility-test.js b/packages/@ember/object/tests/es-compatibility-test.js index 164ab8e1e1f..aebba0f6c1c 100644 --- a/packages/@ember/object/tests/es-compatibility-test.js +++ b/packages/@ember/object/tests/es-compatibility-test.js @@ -1,12 +1,5 @@ -import EmberObject, { computed, observer } from '@ember/object'; -import { - defineProperty, - addObserver, - removeObserver, - addListener, - removeListener, - sendEvent, -} from '@ember/-internals/metal'; +import EmberObject, { computed, set } from '@ember/object'; +import { defineProperty, addObserver, addListener, sendEvent } from '@ember/-internals/metal'; import Mixin from '@ember/object/mixin'; import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; @@ -275,83 +268,83 @@ moduleFor( SubEmberObject.metaForProperty('foo'); } - // TODO: Revisit this - '@test observes / removeObserver on / removeListener interop'(assert) { - let fooDidChangeBase = 0; - let fooDidChangeA = 0; - let fooDidChangeB = 0; - let someEventBase = 0; - let someEventA = 0; - let someEventB = 0; - class A extends EmberObject.extend({ - fooDidChange: observer('foo', function () { - fooDidChangeBase++; - }), - - onSomeEvent() { - someEventBase++; - }, - }) { - init() { - super.init(); - this.foo = 'bar'; - } - - fooDidChange() { - super.fooDidChange(); - fooDidChangeA++; - } - - onSomeEvent() { - super.onSomeEvent(); - someEventA++; - } - } - - class B extends A { - fooDidChange() { - super.fooDidChange(); - fooDidChangeB++; - } - - onSomeEvent() { - super.onSomeEvent(); - someEventB++; - } - } - - removeObserver(B.prototype, 'foo', null, 'fooDidChange'); - removeListener(B.prototype, 'someEvent', null, 'onSomeEvent'); - - assert.equal(fooDidChangeBase, 0); - assert.equal(fooDidChangeA, 0); - assert.equal(fooDidChangeB, 0); - - assert.equal(someEventBase, 0); - assert.equal(someEventA, 0); - assert.equal(someEventB, 0); - - let a = A.create(); - a.set('foo', 'something'); - - // TODO: Generator transpilation code doesn't play nice with class definitions/hoisting - return runLoopSettled().then(async () => { - assert.equal(fooDidChangeBase, 1); - assert.equal(fooDidChangeA, 1); - assert.equal(fooDidChangeB, 0); - - let b = B.create(); - b.set('foo', 'something'); - await runLoopSettled(); - - assert.equal(fooDidChangeBase, 1); - assert.equal(fooDidChangeA, 1); - assert.equal(fooDidChangeB, 0); - - a.destroy(); - b.destroy(); - }); - } + // TODO: Determine if there's anything useful to test here with observer helper gone + // '@test observes / removeObserver on / removeListener interop'(assert) { + // let fooDidChangeBase = 0; + // let fooDidChangeA = 0; + // let fooDidChangeB = 0; + // let someEventBase = 0; + // let someEventA = 0; + // let someEventB = 0; + // class A extends EmberObject.extend({ + // fooDidChange: observer('foo', function () { + // fooDidChangeBase++; + // }), + + // onSomeEvent() { + // someEventBase++; + // }, + // }) { + // init() { + // super.init(); + // this.foo = 'bar'; + // } + + // fooDidChange() { + // super.fooDidChange(); + // fooDidChangeA++; + // } + + // onSomeEvent() { + // super.onSomeEvent(); + // someEventA++; + // } + // } + + // class B extends A { + // fooDidChange() { + // super.fooDidChange(); + // fooDidChangeB++; + // } + + // onSomeEvent() { + // super.onSomeEvent(); + // someEventB++; + // } + // } + + // removeObserver(B.prototype, 'foo', null, 'fooDidChange'); + // removeListener(B.prototype, 'someEvent', null, 'onSomeEvent'); + + // assert.equal(fooDidChangeBase, 0); + // assert.equal(fooDidChangeA, 0); + // assert.equal(fooDidChangeB, 0); + + // assert.equal(someEventBase, 0); + // assert.equal(someEventA, 0); + // assert.equal(someEventB, 0); + + // let a = A.create(); + // set(a, 'foo', 'something'); + + // // TODO: Generator transpilation code doesn't play nice with class definitions/hoisting + // return runLoopSettled().then(async () => { + // assert.equal(fooDidChangeBase, 1); + // assert.equal(fooDidChangeA, 1); + // assert.equal(fooDidChangeB, 0); + + // let b = B.create(); + // set(b, 'foo', 'something'); + // await runLoopSettled(); + + // assert.equal(fooDidChangeBase, 1); + // assert.equal(fooDidChangeA, 1); + // assert.equal(fooDidChangeB, 0); + + // a.destroy(); + // b.destroy(); + // }); + // } '@test super and _super interop between old and new methods'(assert) { let calls = []; @@ -498,7 +491,8 @@ moduleFor( assert.equal(d.full, 'Robert Jackson'); - d.setProperties({ first: 'Kris', last: 'Selden' }); + set(d, 'first', 'Kris'); + set(d, 'last', 'Selden'); // TODO: Generator transpilation code doesn't play nice with class definitions/hoisting return runLoopSettled().then(() => { diff --git a/packages/@ember/object/tests/extend_test.js b/packages/@ember/object/tests/extend_test.js index a99259276a7..764b3a23cbe 100644 --- a/packages/@ember/object/tests/extend_test.js +++ b/packages/@ember/object/tests/extend_test.js @@ -1,6 +1,6 @@ -import { computed, get } from '@ember/object'; -import EmberObject, { observer } from '@ember/object'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { get } from '@ember/object'; +import EmberObject from '@ember/object'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; moduleFor( 'EmberObject.extend', @@ -79,14 +79,14 @@ moduleFor( let some = SomeClass.create(); let another = AnotherClass.create(); let yetAnother = YetAnotherClass.create(); - assert.deepEqual(some.get('things'), ['foo'], 'base class should have just its value'); + assert.deepEqual(get(some, 'things'), ['foo'], 'base class should have just its value'); assert.deepEqual( - another.get('things'), + get(another, 'things'), ['foo', 'bar'], "subclass should have base class' and its own" ); assert.deepEqual( - yetAnother.get('things'), + get(yetAnother, 'things'), ['foo', 'baz'], "subclass should have base class' and its own" ); @@ -122,36 +122,37 @@ moduleFor( ); } - async ['@test Overriding a computed property with an observer'](assert) { - let Parent = EmberObject.extend({ - foo: computed(function () { - return 'FOO'; - }), - }); + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test Overriding a computed property with an observer'](assert) { + // let Parent = EmberObject.extend({ + // foo: computed(function () { + // return 'FOO'; + // }), + // }); - let seen = []; + // let seen = []; - let Child = Parent.extend({ - foo: observer('bar', function () { - seen.push(this.get('bar')); - }), - }); + // let Child = Parent.extend({ + // foo: observer('bar', function () { + // seen.push(this.get('bar')); + // }), + // }); - let child = Child.create({ bar: 0 }); + // let child = Child.create({ bar: 0 }); - assert.deepEqual(seen, []); + // assert.deepEqual(seen, []); - child.set('bar', 1); - await runLoopSettled(); + // child.set('bar', 1); + // await runLoopSettled(); - assert.deepEqual(seen, [1]); + // assert.deepEqual(seen, [1]); - child.set('bar', 2); - await runLoopSettled(); + // child.set('bar', 2); + // await runLoopSettled(); - assert.deepEqual(seen, [1, 2]); + // assert.deepEqual(seen, [1, 2]); - child.destroy(); - } + // child.destroy(); + // } } ); diff --git a/packages/@ember/object/tests/mixin/observer_test.js b/packages/@ember/object/tests/mixin/observer_test.js index b7e70e9a381..1ff86de1adb 100644 --- a/packages/@ember/object/tests/mixin/observer_test.js +++ b/packages/@ember/object/tests/mixin/observer_test.js @@ -1,5 +1,3 @@ -import { set, get, observer } from '@ember/object'; -import Mixin, { mixin } from '@ember/object/mixin'; import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; import { destroy } from '@glimmer/destroyable'; @@ -16,225 +14,191 @@ moduleFor( } } - async ['@test global observer helper'](assert) { - let MyMixin = Mixin.create({ - count: 0, + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test replacing observer should remove old observer'](assert) { + // let MyMixin = Mixin.create({ + // count: 0, - foo: observer('bar', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); + // foo: observer('bar', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); - obj = mixin({}, MyMixin); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // let Mixin2 = Mixin.create({ + // foo: observer('baz', function () { + // set(this, 'count', get(this, 'count') + 10); + // }), + // }); - set(obj, 'bar', 'BAZ'); - await runLoopSettled(); + // obj = mixin({}, MyMixin, Mixin2); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - } - - async ['@test global observer helper takes multiple params'](assert) { - let MyMixin = Mixin.create({ - count: 0, - - foo: observer('bar', 'baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); - - obj = mixin({}, MyMixin); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - - set(obj, 'bar', 'BAZ'); - await runLoopSettled(); - - set(obj, 'baz', 'BAZ'); - await runLoopSettled(); - - assert.equal(get(obj, 'count'), 2, 'should invoke observer after change'); - - destroy(obj); - await runLoopSettled(); - } - - async ['@test replacing observer should remove old observer'](assert) { - let MyMixin = Mixin.create({ - count: 0, - - foo: observer('bar', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); + // set(obj, 'bar', 'BAZ'); + // await runLoopSettled(); - let Mixin2 = Mixin.create({ - foo: observer('baz', function () { - set(this, 'count', get(this, 'count') + 10); - }), - }); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); - obj = mixin({}, MyMixin, Mixin2); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // set(obj, 'baz', 'BAZ'); + // await runLoopSettled(); - set(obj, 'bar', 'BAZ'); - await runLoopSettled(); + // assert.equal(get(obj, 'count'), 10, 'should invoke observer after change'); + // } - assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observing chain with property before'](assert) { + // let obj2 = { baz: 'baz' }; - set(obj, 'baz', 'BAZ'); - await runLoopSettled(); + // let MyMixin = Mixin.create({ + // count: 0, + // bar: obj2, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); - assert.equal(get(obj, 'count'), 10, 'should invoke observer after change'); - } + // obj = mixin({}, MyMixin); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - async ['@test observing chain with property before'](assert) { - let obj2 = { baz: 'baz' }; + // set(obj2, 'baz', 'BAZ'); + // await runLoopSettled(); - let MyMixin = Mixin.create({ - count: 0, - bar: obj2, - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // } - obj = mixin({}, MyMixin); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observing chain with property after'](assert) { + // let obj2 = { baz: 'baz' }; - set(obj2, 'baz', 'BAZ'); - await runLoopSettled(); + // let MyMixin = Mixin.create({ + // count: 0, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // bar: obj2, + // }); - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - } + // obj = mixin({}, MyMixin); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - async ['@test observing chain with property after'](assert) { - let obj2 = { baz: 'baz' }; + // set(obj2, 'baz', 'BAZ'); + // await runLoopSettled(); - let MyMixin = Mixin.create({ - count: 0, - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - bar: obj2, - }); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // } - obj = mixin({}, MyMixin); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observing chain with property in mixin applied later'](assert) { + // let obj2 = { baz: 'baz' }; - set(obj2, 'baz', 'BAZ'); - await runLoopSettled(); + // let MyMixin = Mixin.create({ + // count: 0, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - } + // let MyMixin2 = Mixin.create({ bar: obj2 }); - async ['@test observing chain with property in mixin applied later'](assert) { - let obj2 = { baz: 'baz' }; + // obj = mixin({}, MyMixin); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - let MyMixin = Mixin.create({ - count: 0, - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); + // MyMixin2.apply(obj); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - let MyMixin2 = Mixin.create({ bar: obj2 }); + // set(obj2, 'baz', 'BAZ'); + // await runLoopSettled(); - obj = mixin({}, MyMixin); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // } - MyMixin2.apply(obj); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observing chain with existing property'](assert) { + // let obj2 = { baz: 'baz' }; - set(obj2, 'baz', 'BAZ'); - await runLoopSettled(); + // let MyMixin = Mixin.create({ + // count: 0, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - } + // obj = mixin({ bar: obj2 }, MyMixin); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - async ['@test observing chain with existing property'](assert) { - let obj2 = { baz: 'baz' }; + // set(obj2, 'baz', 'BAZ'); + // await runLoopSettled(); - let MyMixin = Mixin.create({ - count: 0, - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // } - obj = mixin({ bar: obj2 }, MyMixin); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observing chain with property in mixin before'](assert) { + // let obj2 = { baz: 'baz' }; + // let MyMixin2 = Mixin.create({ bar: obj2 }); - set(obj2, 'baz', 'BAZ'); - await runLoopSettled(); + // let MyMixin = Mixin.create({ + // count: 0, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - } + // obj = mixin({}, MyMixin2, MyMixin); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - async ['@test observing chain with property in mixin before'](assert) { - let obj2 = { baz: 'baz' }; - let MyMixin2 = Mixin.create({ bar: obj2 }); + // set(obj2, 'baz', 'BAZ'); + // await runLoopSettled(); - let MyMixin = Mixin.create({ - count: 0, - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // } - obj = mixin({}, MyMixin2, MyMixin); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observing chain with property in mixin after'](assert) { + // let obj2 = { baz: 'baz' }; + // let MyMixin2 = Mixin.create({ bar: obj2 }); - set(obj2, 'baz', 'BAZ'); - await runLoopSettled(); + // let MyMixin = Mixin.create({ + // count: 0, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - } + // obj = mixin({}, MyMixin, MyMixin2); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - async ['@test observing chain with property in mixin after'](assert) { - let obj2 = { baz: 'baz' }; - let MyMixin2 = Mixin.create({ bar: obj2 }); + // set(obj2, 'baz', 'BAZ'); + // await runLoopSettled(); - let MyMixin = Mixin.create({ - count: 0, - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // } - obj = mixin({}, MyMixin, MyMixin2); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observing chain with overridden property'](assert) { + // let obj2 = { baz: 'baz' }; + // let obj3 = { baz: 'foo' }; - set(obj2, 'baz', 'BAZ'); - await runLoopSettled(); + // let MyMixin2 = Mixin.create({ bar: obj3 }); - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - } - - async ['@test observing chain with overridden property'](assert) { - let obj2 = { baz: 'baz' }; - let obj3 = { baz: 'foo' }; - - let MyMixin2 = Mixin.create({ bar: obj3 }); + // let MyMixin = Mixin.create({ + // count: 0, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); - let MyMixin = Mixin.create({ - count: 0, - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); + // obj = mixin({ bar: obj2 }, MyMixin, MyMixin2); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - obj = mixin({ bar: obj2 }, MyMixin, MyMixin2); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // set(obj2, 'baz', 'BAZ'); + // await runLoopSettled(); - set(obj2, 'baz', 'BAZ'); - await runLoopSettled(); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); + // set(obj3, 'baz', 'BEAR'); + // await runLoopSettled(); - set(obj3, 'baz', 'BEAR'); - await runLoopSettled(); - - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - } + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // } } ); diff --git a/packages/@ember/object/tests/observer_test.js b/packages/@ember/object/tests/observer_test.js index 3e181e2e007..154db02d65e 100644 --- a/packages/@ember/object/tests/observer_test.js +++ b/packages/@ember/object/tests/observer_test.js @@ -1,320 +1,242 @@ -import { run } from '@ember/runloop'; -import { alias } from '@ember/-internals/metal'; -import EmberObject, { get, set, observer } from '@ember/object'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; moduleFor( 'EmberObject observer', class extends AbstractTestCase { - async ['@test observer on class'](assert) { - let MyClass = EmberObject.extend({ - count: 0, - - foo: observer('bar', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); - - let obj = MyClass.create(); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - - set(obj, 'bar', 'BAZ'); - await runLoopSettled(); - - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - - obj.destroy(); - } - - async ['@test setting `undefined` value on observed property behaves correctly'](assert) { - let MyClass = EmberObject.extend({ - mood: 'good', - foo: observer('mood', function () {}), - }); - - let obj = MyClass.create(); - assert.equal(get(obj, 'mood'), 'good'); - - set(obj, 'mood', 'bad'); - await runLoopSettled(); - - assert.equal(get(obj, 'mood'), 'bad'); - - set(obj, 'mood', undefined); - await runLoopSettled(); - - assert.equal(get(obj, 'mood'), undefined); - - set(obj, 'mood', 'awesome'); - await runLoopSettled(); - - assert.equal(get(obj, 'mood'), 'awesome'); - - obj.destroy(); - } - - async ['@test observer on subclass'](assert) { - let MyClass = EmberObject.extend({ - count: 0, - - foo: observer('bar', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); - - let Subclass = MyClass.extend({ - foo: observer('baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); - - let obj = Subclass.create(); - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - - set(obj, 'bar', 'BAZ'); - await runLoopSettled(); - - assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); - - set(obj, 'baz', 'BAZ'); - await runLoopSettled(); - - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - - obj.destroy(); - } - - async ['@test observer on instance'](assert) { - let obj = EmberObject.extend({ - foo: observer('bar', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }).create({ - count: 0, - }); - - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - - set(obj, 'bar', 'BAZ'); - await runLoopSettled(); - - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - - obj.destroy(); - await runLoopSettled(); - } - - async ['@test observer on instance overriding class'](assert) { - let MyClass = EmberObject.extend({ - count: 0, - - foo: observer('bar', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); - - let obj = MyClass.extend({ - foo: observer('baz', function () { - // <-- change property we observe - set(this, 'count', get(this, 'count') + 1); - }), - }).create(); - - assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); - - set(obj, 'bar', 'BAZ'); - await runLoopSettled(); - - assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); - - set(obj, 'baz', 'BAZ'); - await runLoopSettled(); - - assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); - - obj.destroy(); - } - - async ['@test observer should not fire after being destroyed'](assert) { - let obj = EmberObject.extend({ - count: 0, - foo: observer('bar', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }).create(); - - assert.equal(get(obj, 'count'), 0, 'precond - should not invoke observer immediately'); - - run(() => obj.destroy()); - - expectAssertion(function () { - set(obj, 'bar', 'BAZ'); - }, `calling set on destroyed object: ${obj}.bar = BAZ`); - - assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); - - obj.destroy(); - } - + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observer on class'](assert) { + // let MyClass = EmberObject.extend({ + // count: 0, + // foo: observer('bar', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); + // let obj = MyClass.create(); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // set(obj, 'bar', 'BAZ'); + // await runLoopSettled(); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // obj.destroy(); + // } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test setting `undefined` value on observed property behaves correctly'](assert) { + // let MyClass = EmberObject.extend({ + // mood: 'good', + // foo: observer('mood', function () {}), + // }); + // let obj = MyClass.create(); + // assert.equal(get(obj, 'mood'), 'good'); + // set(obj, 'mood', 'bad'); + // await runLoopSettled(); + // assert.equal(get(obj, 'mood'), 'bad'); + // set(obj, 'mood', undefined); + // await runLoopSettled(); + // assert.equal(get(obj, 'mood'), undefined); + // set(obj, 'mood', 'awesome'); + // await runLoopSettled(); + // assert.equal(get(obj, 'mood'), 'awesome'); + // obj.destroy(); + // } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observer on subclass'](assert) { + // let MyClass = EmberObject.extend({ + // count: 0, + // foo: observer('bar', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); + // let Subclass = MyClass.extend({ + // foo: observer('baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); + // let obj = Subclass.create(); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // set(obj, 'bar', 'BAZ'); + // await runLoopSettled(); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); + // set(obj, 'baz', 'BAZ'); + // await runLoopSettled(); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // obj.destroy(); + // } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observer on instance'](assert) { + // let obj = EmberObject.extend({ + // foo: observer('bar', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }).create({ + // count: 0, + // }); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // set(obj, 'bar', 'BAZ'); + // await runLoopSettled(); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // obj.destroy(); + // await runLoopSettled(); + // } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observer on instance overriding class'](assert) { + // let MyClass = EmberObject.extend({ + // count: 0, + // foo: observer('bar', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); + // let obj = MyClass.extend({ + // foo: observer('baz', function () { + // // <-- change property we observe + // set(this, 'count', get(this, 'count') + 1); + // }), + // }).create(); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); + // set(obj, 'bar', 'BAZ'); + // await runLoopSettled(); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); + // set(obj, 'baz', 'BAZ'); + // await runLoopSettled(); + // assert.equal(get(obj, 'count'), 1, 'should invoke observer after change'); + // obj.destroy(); + // } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test observer should not fire after being destroyed'](assert) { + // let obj = EmberObject.extend({ + // count: 0, + // foo: observer('bar', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }).create(); + // assert.equal(get(obj, 'count'), 0, 'precond - should not invoke observer immediately'); + // run(() => obj.destroy()); + // expectAssertion(function () { + // set(obj, 'bar', 'BAZ'); + // }, `calling set on destroyed object: ${obj}.bar = BAZ`); + // assert.equal(get(obj, 'count'), 0, 'should not invoke observer after change'); + // obj.destroy(); + // } // .......................................................... // COMPLEX PROPERTIES // - - async ['@test chain observer on class'](assert) { - let MyClass = EmberObject.extend({ - count: 0, - - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); - - let obj1 = MyClass.create({ - bar: { baz: 'biff' }, - }); - - let obj2 = MyClass.create({ - bar: { baz: 'biff2' }, - }); - - assert.equal(get(obj1, 'count'), 0, 'should not invoke yet'); - assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); - - set(get(obj1, 'bar'), 'baz', 'BIFF1'); - await runLoopSettled(); - - assert.equal(get(obj1, 'count'), 1, 'should invoke observer on obj1'); - assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); - - set(get(obj2, 'bar'), 'baz', 'BIFF2'); - await runLoopSettled(); - - assert.equal(get(obj1, 'count'), 1, 'should not invoke again'); - assert.equal(get(obj2, 'count'), 1, 'should invoke observer on obj2'); - - obj1.destroy(); - obj2.destroy(); - } - - async ['@test clobbering a chain observer on subclass'](assert) { - let MyClass = EmberObject.extend({ - count: 0, - - foo: observer('bar.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }); - - let obj1 = MyClass.extend().create({ - bar: { baz: 'biff' }, - }); - - let obj2 = MyClass.extend({ - foo: observer('bar2.baz', function () { - set(this, 'count', get(this, 'count') + 1); - }), - }).create({ - bar: { baz: 'biff2' }, - bar2: { baz: 'biff3' }, - }); - - assert.equal(get(obj1, 'count'), 0, 'should not invoke yet'); - assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); - - set(get(obj1, 'bar'), 'baz', 'BIFF1'); - await runLoopSettled(); - - assert.equal(get(obj1, 'count'), 1, 'should invoke observer on obj1'); - assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); - - set(get(obj2, 'bar'), 'baz', 'BIFF2'); - await runLoopSettled(); - - assert.equal(get(obj1, 'count'), 1, 'should not invoke again'); - assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); - - set(get(obj2, 'bar2'), 'baz', 'BIFF3'); - await runLoopSettled(); - - assert.equal(get(obj1, 'count'), 1, 'should not invoke again'); - assert.equal(get(obj2, 'count'), 1, 'should invoke observer on obj2'); - - obj1.destroy(); - obj2.destroy(); - } - - async ['@test chain observer on class that has a reference to an uninitialized object will finish chains that reference it']( - assert - ) { - let changed = false; - - let ChildClass = EmberObject.extend({ - parent: null, - parentOneTwoDidChange: observer('parent.one.two', function () { - changed = true; - }), - }); - - let ParentClass = EmberObject.extend({ - one: { - two: 'old', - }, - init() { - this.child = ChildClass.create({ - parent: this, - }); - }, - }); - - let parent = ParentClass.create(); - - assert.equal(changed, false, 'precond'); - - set(parent, 'one.two', 'new'); - await runLoopSettled(); - - assert.equal(changed, true, 'child should have been notified of change to path'); - - set(parent, 'one', { two: 'newer' }); - await runLoopSettled(); - - assert.equal(changed, true, 'child should have been notified of change to path'); - - parent.child.destroy(); - parent.destroy(); - } - - async ['@test cannot re-enter observer while it is flushing'](assert) { - let changed = false; - - let Class = EmberObject.extend({ - bar: 0, - - get foo() { - // side effects during creation, setting a value and running through - // sync observers for a second time. - return this.incrementProperty('bar'); - }, - - // Ensures we get `foo` eagerly when attempting to observe it - fooAlias: alias('foo'), - - parentOneTwoDidChange: observer({ - dependentKeys: ['fooAlias'], - fn() { - changed = true; - }, - sync: true, - }), - }); - - let obj = Class.create(); - - obj.notifyPropertyChange('foo'); - - assert.equal(changed, true, 'observer fired successfully'); - - obj.destroy(); - } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test chain observer on class'](assert) { + // let MyClass = EmberObject.extend({ + // count: 0, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); + // let obj1 = MyClass.create({ + // bar: { baz: 'biff' }, + // }); + // let obj2 = MyClass.create({ + // bar: { baz: 'biff2' }, + // }); + // assert.equal(get(obj1, 'count'), 0, 'should not invoke yet'); + // assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); + // set(get(obj1, 'bar'), 'baz', 'BIFF1'); + // await runLoopSettled(); + // assert.equal(get(obj1, 'count'), 1, 'should invoke observer on obj1'); + // assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); + // set(get(obj2, 'bar'), 'baz', 'BIFF2'); + // await runLoopSettled(); + // assert.equal(get(obj1, 'count'), 1, 'should not invoke again'); + // assert.equal(get(obj2, 'count'), 1, 'should invoke observer on obj2'); + // obj1.destroy(); + // obj2.destroy(); + // } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test clobbering a chain observer on subclass'](assert) { + // let MyClass = EmberObject.extend({ + // count: 0, + // foo: observer('bar.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }); + // let obj1 = MyClass.extend().create({ + // bar: { baz: 'biff' }, + // }); + // let obj2 = MyClass.extend({ + // foo: observer('bar2.baz', function () { + // set(this, 'count', get(this, 'count') + 1); + // }), + // }).create({ + // bar: { baz: 'biff2' }, + // bar2: { baz: 'biff3' }, + // }); + // assert.equal(get(obj1, 'count'), 0, 'should not invoke yet'); + // assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); + // set(get(obj1, 'bar'), 'baz', 'BIFF1'); + // await runLoopSettled(); + // assert.equal(get(obj1, 'count'), 1, 'should invoke observer on obj1'); + // assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); + // set(get(obj2, 'bar'), 'baz', 'BIFF2'); + // await runLoopSettled(); + // assert.equal(get(obj1, 'count'), 1, 'should not invoke again'); + // assert.equal(get(obj2, 'count'), 0, 'should not invoke yet'); + // set(get(obj2, 'bar2'), 'baz', 'BIFF3'); + // await runLoopSettled(); + // assert.equal(get(obj1, 'count'), 1, 'should not invoke again'); + // assert.equal(get(obj2, 'count'), 1, 'should invoke observer on obj2'); + // obj1.destroy(); + // obj2.destroy(); + // } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test chain observer on class that has a reference to an uninitialized object will finish chains that reference it']( + // assert + // ) { + // let changed = false; + // let ChildClass = EmberObject.extend({ + // parent: null, + // parentOneTwoDidChange: observer('parent.one.two', function () { + // changed = true; + // }), + // }); + // let ParentClass = EmberObject.extend({ + // one: { + // two: 'old', + // }, + // init() { + // this.child = ChildClass.create({ + // parent: this, + // }); + // }, + // }); + // let parent = ParentClass.create(); + // assert.equal(changed, false, 'precond'); + // set(parent, 'one.two', 'new'); + // await runLoopSettled(); + // assert.equal(changed, true, 'child should have been notified of change to path'); + // set(parent, 'one', { two: 'newer' }); + // await runLoopSettled(); + // assert.equal(changed, true, 'child should have been notified of change to path'); + // parent.child.destroy(); + // parent.destroy(); + // } + // TODO: Determine if there's anything useful to test here with observer helper gone + // async ['@test cannot re-enter observer while it is flushing'](assert) { + // let changed = false; + // let Class = EmberObject.extend({ + // bar: 0, + // get foo() { + // // side effects during creation, setting a value and running through + // // sync observers for a second time. + // return this.incrementProperty('bar'); + // }, + // // Ensures we get `foo` eagerly when attempting to observe it + // fooAlias: alias('foo'), + // parentOneTwoDidChange: observer({ + // dependentKeys: ['fooAlias'], + // fn() { + // changed = true; + // }, + // sync: true, + // }), + // }); + // let obj = Class.create(); + // obj.notifyPropertyChange('foo'); + // assert.equal(changed, true, 'observer fired successfully'); + // obj.destroy(); + // } } ); diff --git a/packages/@ember/object/tests/reopen_test.js b/packages/@ember/object/tests/reopen_test.js index a68e236fb42..2844c347d3f 100644 --- a/packages/@ember/object/tests/reopen_test.js +++ b/packages/@ember/object/tests/reopen_test.js @@ -42,7 +42,7 @@ moduleFor( trololol: true, }); - assert.equal(Subclass.create().get('trololol'), true, 'reopen works'); + assert.equal(get(Subclass.create(), 'trololol'), true, 'reopen works'); } } ); diff --git a/packages/@ember/object/type-tests/ember-object.test.ts b/packages/@ember/object/type-tests/ember-object.test.ts index 57aef38d3bb..b93cbcc6efb 100644 --- a/packages/@ember/object/type-tests/ember-object.test.ts +++ b/packages/@ember/object/type-tests/ember-object.test.ts @@ -37,50 +37,6 @@ const p = new Person(owner); expectTypeOf(p.firstName).toEqualTypeOf(); -// get not preferred for TS only returns unknown -expectTypeOf(p.get('firstName')).toBeString(); -// Also returns unknown for invalid properties -expectTypeOf(p.get('invalid')).toEqualTypeOf(); - -expectTypeOf(p.incrementProperty('age')).toEqualTypeOf(); -expectTypeOf(p.incrementProperty('age', 2)).toEqualTypeOf(); -// @ts-expect-error must increment by a value -p.incrementProperty('age', 'foo'); - -expectTypeOf(p.decrementProperty('age')).toEqualTypeOf(); -expectTypeOf(p.decrementProperty('age', 2)).toEqualTypeOf(); -// @ts-expect-error must decrement by a value -p.decrementProperty('age', 'foo'); - -expectTypeOf(p.toggleProperty('age')).toEqualTypeOf(); - -expectTypeOf(p.cacheFor('age')).toEqualTypeOf(); - -// get is not preferred for TS and only returns unknown -const getPropertiesResult = p.getProperties('firstName', 'lastName', 'invalid'); -expectTypeOf(getPropertiesResult).toEqualTypeOf<{ - firstName: unknown; - lastName: unknown; - invalid: unknown; -}>(); -// @ts-expect-error doesn't have unknown properties -getPropertiesResult.unknown; - -expectTypeOf(p.set('firstName', 'Joe')).toBeString(); -expectTypeOf(p.set('invalid', 1)).toEqualTypeOf(); - -const setPropertiesResult = p.setProperties({ firstName: 'Joe', invalid: 1 }); -expectTypeOf(setPropertiesResult).toEqualTypeOf<{ - firstName: string; - invalid: number; -}>(); -expectTypeOf(setPropertiesResult.firstName).toEqualTypeOf(); -expectTypeOf(setPropertiesResult.invalid).toEqualTypeOf(); -// @ts-expect-error doesn't have unknown properties -setPropertiesResult.unknown; - -expectTypeOf(p.notifyPropertyChange('firstName')).toEqualTypeOf(p); - const p2 = Person.create({ firstName: 'string' }); expectTypeOf(p2.firstName).toEqualTypeOf(); @@ -89,40 +45,3 @@ expectTypeOf(p2b.firstName).toEqualTypeOf(); const p2c = Person.create({}, {}, { firstName: 'string' }); expectTypeOf(p2c.firstName).toEqualTypeOf(); - -// NOTE: This is marked as @internal and will not be publicly available -Person.extend({ fullName: 6 }); - -// NOTE: This is marked as @internal and will not be publicly available -Person.reopen({ fullName: 6 }); - -// NOTE: This is marked as @internal and will not be publicly available -Person.reopenClass({ fullName: 6 }); - -class MyComponent extends EmberObject { - foo = 'bar'; - - constructor(owner: Owner) { - super(owner); - - this.addObserver('foo', this, 'fooDidChange'); - - this.addObserver('foo', this, this.fooDidChange); - this.removeObserver('foo', this, 'fooDidChange'); - - this.removeObserver('foo', this, this.fooDidChange); - const lambda = () => { - this.fooDidChange(this, 'foo'); - }; - this.addObserver('foo', lambda); - this.removeObserver('foo', lambda); - } - - fooDidChange(_sender: this, _key: string) { - // your code - } -} - -const myComponent = MyComponent.create(); -myComponent.addObserver('foo', null, () => {}); -myComponent.set('foo', 'baz'); diff --git a/packages/@ember/object/type-tests/observer.test.ts b/packages/@ember/object/type-tests/observer.test.ts deleted file mode 100644 index d185987376a..00000000000 --- a/packages/@ember/object/type-tests/observer.test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { observer } from '@ember/object'; - -import { expectTypeOf } from 'expect-type'; - -const definition = { - dependentKeys: ['value1', 'value2', 'value3'], - - fn: () => {}, - sync: true, -}; - -class Foo { - valueObserver = observer('value', function () { - // Executes whenever the "value" property changes - }); - - definitionObserver = observer(definition); - - // @ts-expect-error Requires at least one key - noKeysObserver = observer(() => {}); - - // @ts-expect-error Doesn't allow keys and definition - extraKeysObserver = observer('extraKey', definition); -} - -const foo = new Foo(); - -expectTypeOf(foo.valueObserver).toEqualTypeOf<() => void>(); -expectTypeOf(foo.definitionObserver).toEqualTypeOf<() => void>(); diff --git a/packages/@ember/routing/router.ts b/packages/@ember/routing/router.ts index 0f32b9a0969..c02d73d6333 100644 --- a/packages/@ember/routing/router.ts +++ b/packages/@ember/routing/router.ts @@ -1,7 +1,7 @@ import { privatize as P } from '@ember/-internals/container'; import type { BootEnvironment, OutletState, OutletView } from '@ember/-internals/glimmer'; -import { sendEvent } from '@ember/-internals/metal'; import { computed, get, set } from '@ember/object'; +import { notifyPropertyChange, sendEvent } from '@ember/-internals/metal'; import type { default as Owner, FactoryManager } from '@ember/owner'; import { getOwner } from '@ember/owner'; import { default as BucketCache } from './lib/cache'; @@ -60,8 +60,8 @@ function defaultDidTransition(this: EmberRouter, infos: InternalRouteInfo this._cancelSlowTransitionTimer(); - this.notifyPropertyChange('url'); - this.set('currentState', this.targetState); + notifyPropertyChange(this, 'url'); + set(this, 'currentState', this.targetState); if (DEBUG) { // @ts-expect-error namespace isn't public @@ -417,12 +417,12 @@ class EmberRouter extends EmberObject { // to make router.currentRoute.name consistent with router.currentRouteName // see https://github.com/emberjs/ember.js/issues/19449 if (transition.isIntermediate) { - router.set('currentRoute', transition.to); + set(router, 'currentRoute', transition.to); } } routeDidChange(transition: Transition) { - router.set('currentRoute', transition.to); + set(router, 'currentRoute', transition.to); once(() => { sendEvent(router, 'routeDidChange', [transition]); @@ -1332,7 +1332,7 @@ class EmberRouter extends EmberObject { this._routerMicrolib, this._routerMicrolib.activeTransition[STATE_SYMBOL]! ); - this.set('targetState', targetState); + set(this, 'targetState', targetState); transition.trigger(true, 'loading', transition, originRoute); } @@ -1771,9 +1771,9 @@ function didBeginTransition(transition: Transition, router: EmberRouter) { let routerState = new RouterState(router, router._routerMicrolib, transition[STATE_SYMBOL]!); if (!router.currentState) { - router.set('currentState', routerState); + set(router, 'currentState', routerState); } - router.set('targetState', routerState); + set(router, 'targetState', routerState); transition.promise = transition.catch((error: any) => { if (router._isErrorHandled(error)) { diff --git a/packages/@ember/routing/tests/location/history_location_test.js b/packages/@ember/routing/tests/location/history_location_test.js index 6bf7a81b356..9681293fc9c 100644 --- a/packages/@ember/routing/tests/location/history_location_test.js +++ b/packages/@ember/routing/tests/location/history_location_test.js @@ -1,5 +1,5 @@ import { run } from '@ember/runloop'; -import { set } from '@ember/object'; +import { get, set } from '@ember/object'; import HistoryLocation from '@ember/routing/history-location'; import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; @@ -109,7 +109,7 @@ moduleFor( createLocation(); location.initState(); - assert.strictEqual(location.get('baseURL'), '/foo/'); + assert.strictEqual(get(location, 'baseURL'), '/foo/'); } finally { document.head.removeChild(base); } @@ -127,7 +127,7 @@ moduleFor( createLocation(); location.initState(); - assert.strictEqual(location.get('baseURL'), ''); + assert.strictEqual(get(location, 'baseURL'), ''); } finally { document.head.removeChild(base); } diff --git a/packages/@ember/routing/tests/system/route_test.js b/packages/@ember/routing/tests/system/route_test.js index d0f4cc31175..25a1310755f 100644 --- a/packages/@ember/routing/tests/system/route_test.js +++ b/packages/@ember/routing/tests/system/route_test.js @@ -1,5 +1,6 @@ import { setOwner } from '@ember/-internals/owner'; import { runDestroy, buildOwner, moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { get } from '@ember/object'; import Service, { service } from '@ember/service'; import EmberRoute from '@ember/routing/route'; import { getDebugFunction, setDebugFunction } from '@ember/debug'; @@ -245,7 +246,7 @@ moduleFor( lookupHash['controller:test'] = {}; routeOne.controllerName = 'test'; - let qp = routeOne.get('_qp'); + let qp = get(routeOne, '_qp'); assert.deepEqual(qp.map, {}, 'map should be empty'); assert.deepEqual(qp.propertyNames, [], 'property names should be empty'); @@ -282,7 +283,7 @@ moduleFor( let appRoute = owner.lookup('route:application'); let authService = owner.lookup('service:auth'); - assert.equal(authService, appRoute.get('authService'), 'service.auth is injected'); + assert.equal(authService, get(appRoute, 'authService'), 'service.auth is injected'); runDestroy(owner); } diff --git a/packages/@ember/routing/tests/system/router_test.js b/packages/@ember/routing/tests/system/router_test.js index 17e8bef12fb..9ba920e8389 100644 --- a/packages/@ember/routing/tests/system/router_test.js +++ b/packages/@ember/routing/tests/system/router_test.js @@ -1,3 +1,4 @@ +import { get } from '@ember/object'; import HashLocation from '@ember/routing/hash-location'; import HistoryLocation from '@ember/routing/history-location'; import NoneLocation from '@ember/routing/none-location'; @@ -76,7 +77,7 @@ moduleFor( ['@test should destroy its location upon destroying the routers owner.'](assert) { let router = createRouter(); - let location = router.get('location'); + let location = get(router, 'location'); runDestroy(owner); @@ -90,9 +91,9 @@ moduleFor( }, }); - let location = router.get('location'); + let location = get(router, 'location'); - assert.equal(location.get('rootURL'), '/rootdir/'); + assert.equal(get(location, 'rootURL'), '/rootdir/'); } ['@test Router._routePath should consume identical prefixes'](assert) { diff --git a/packages/ember/barrel.ts b/packages/ember/barrel.ts index e4ee87a0676..9798a701b18 100644 --- a/packages/ember/barrel.ts +++ b/packages/ember/barrel.ts @@ -23,7 +23,6 @@ import EmberObject, { computed as emberComputed, defineProperty as emberDefineProperty, notifyPropertyChange as emberNotifyPropertyChange, - observer as emberObserver, get as emberGet, getProperties as emberGetProperties, set as emberSet, @@ -275,7 +274,6 @@ namespace Ember { export const get = emberGet; export const getProperties = emberGetProperties; export const notifyPropertyChange = emberNotifyPropertyChange; - export const observer = emberObserver; export const set = emberSet; export const trySet = emberTrySet; export const setProperties = emberSetProperties; diff --git a/packages/ember/tests/application_lifecycle_test.js b/packages/ember/tests/application_lifecycle_test.js index 58ff4e92610..704feee8c85 100644 --- a/packages/ember/tests/application_lifecycle_test.js +++ b/packages/ember/tests/application_lifecycle_test.js @@ -5,6 +5,7 @@ import { defineComponent, } from 'internal-test-helpers'; import Application from '@ember/application'; +import { get, set } from '@ember/object'; import Route from '@ember/routing/route'; import Router from '@ember/routing/router'; import { Component } from '@ember/-internals/glimmer'; @@ -37,10 +38,10 @@ moduleFor( let SettingRoute = class extends Route { setupController() { - this.controller.set('selectedMenuItem', menuItem); + set(this.controller, 'selectedMenuItem', menuItem); } deactivate() { - this.controller.set('selectedMenuItem', null); + set(this.controller, 'selectedMenuItem', null); } }; this.add('route:index', SettingRoute); @@ -64,28 +65,28 @@ moduleFor( assert ) { let { indexController, applicationController } = this; - assert.equal(indexController.get('selectedMenuItem'), this.menuItem); - assert.equal(applicationController.get('selectedMenuItem'), this.menuItem); + assert.equal(get(indexController, 'selectedMenuItem'), this.menuItem); + assert.equal(get(applicationController, 'selectedMenuItem'), this.menuItem); this.application.reset(); - assert.equal(indexController.get('selectedMenuItem'), null); - assert.equal(applicationController.get('selectedMenuItem'), null); + assert.equal(get(indexController, 'selectedMenuItem'), null); + assert.equal(get(applicationController, 'selectedMenuItem'), null); } [`@test Destroying the application resets the router before the appInstance is destroyed`]( assert ) { let { indexController, applicationController } = this; - assert.equal(indexController.get('selectedMenuItem'), this.menuItem); - assert.equal(applicationController.get('selectedMenuItem'), this.menuItem); + assert.equal(get(indexController, 'selectedMenuItem'), this.menuItem); + assert.equal(get(applicationController, 'selectedMenuItem'), this.menuItem); runTask(() => { this.application.destroy(); }); - assert.equal(indexController.get('selectedMenuItem'), null); - assert.equal(applicationController.get('selectedMenuItem'), null); + assert.equal(get(indexController, 'selectedMenuItem'), null); + assert.equal(get(applicationController, 'selectedMenuItem'), null); } } ); diff --git a/packages/ember/tests/component_context_test.js b/packages/ember/tests/component_context_test.js index 1341470f942..c2320f70e2d 100644 --- a/packages/ember/tests/component_context_test.js +++ b/packages/ember/tests/component_context_test.js @@ -1,4 +1,5 @@ import Controller from '@ember/controller'; +import { get } from '@ember/object'; import { Component } from '@ember/-internals/glimmer'; import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers'; @@ -141,7 +142,7 @@ moduleFor( this.addComponent('my-component', { ComponentClass: class extends Component { didInsertElement() { - this.element.innerHTML = this.get('data'); + this.element.innerHTML = get(this, 'data'); } }, }); @@ -172,7 +173,7 @@ moduleFor( this.addComponent('my-component', { ComponentClass: class extends Component { didInsertElement() { - this.element.innerHTML = this.get('attrs.attrs.value'); + this.element.innerHTML = get(this, 'attrs.attrs.value'); } }, }); diff --git a/packages/ember/tests/homepage_example_test.js b/packages/ember/tests/homepage_example_test.js index 27518b4db32..cb9a8d1208f 100644 --- a/packages/ember/tests/homepage_example_test.js +++ b/packages/ember/tests/homepage_example_test.js @@ -18,7 +18,7 @@ moduleFor( lastName = null; @computed('firstName', 'lastName') get fullName() { - return `${this.get('firstName')} ${this.get('lastName')}`; + return `${this.firstName} ${this.lastName}`; } }; diff --git a/packages/ember/tests/reexports_test.js b/packages/ember/tests/reexports_test.js index 81f013259fa..a54b961a708 100644 --- a/packages/ember/tests/reexports_test.js +++ b/packages/ember/tests/reexports_test.js @@ -187,7 +187,6 @@ let allExports = [ ['get', '@ember/object', 'get', test21], ['getProperties', '@ember/object', 'getProperties', test21], ['notifyPropertyChange', '@ember/object', 'notifyPropertyChange', test21], - ['observer', '@ember/object', 'observer', test21], ['set', '@ember/object', 'set', test21], ['setProperties', '@ember/object', 'setProperties', test21], ['trySet', '@ember/object', 'trySet', test21], diff --git a/packages/ember/tests/routing/decoupled_basic_test.js b/packages/ember/tests/routing/decoupled_basic_test.js index 06dcaa0f9b2..28fd5782e96 100644 --- a/packages/ember/tests/routing/decoupled_basic_test.js +++ b/packages/ember/tests/routing/decoupled_basic_test.js @@ -5,7 +5,7 @@ import { compile } from 'ember-template-compiler'; import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import HistoryLocation from '@ember/routing/history-location'; -import EmberObject, { set } from '@ember/object'; +import EmberObject, { get, set } from '@ember/object'; import { moduleFor, ApplicationTestCase, @@ -298,7 +298,7 @@ moduleFor( let urlSetCount = 0; let router = this.applicationInstance.lookup('router:main'); - router.get('location').setURL = function (path) { + get(router, 'location').setURL = function (path) { urlSetCount++; set(this, 'path', path); }; @@ -311,7 +311,7 @@ moduleFor( }); assert.equal(urlSetCount, 1); - assert.equal(router.get('location').getURL(), '/bar'); + assert.equal(get(router, 'location').getURL(), '/bar'); }); } @@ -365,7 +365,7 @@ moduleFor( assert.equal(setCount, 1, 'should not call setURL'); assert.equal(replaceCount, 1, 'should call replaceURL once'); - assert.equal(router.get('location').getURL(), '/foo'); + assert.equal(get(router, 'location').getURL(), '/foo'); }); } @@ -392,7 +392,7 @@ moduleFor( assert.equal(setCount, 1); run(() => router.replaceWith('foo')); assert.equal(setCount, 2, 'should call setURL once'); - assert.equal(router.get('location').getURL(), '/foo'); + assert.equal(get(router, 'location').getURL(), '/foo'); }); } @@ -477,7 +477,7 @@ moduleFor( let router = this.applicationInstance.lookup('router:main'); this.handleURLAborts(assert, '/foo/bar/baz'); assert.equal(router.currentPath, 'home'); - assert.equal(router.get('location').getURL(), '/home'); + assert.equal(get(router, 'location').getURL(), '/home'); }); } @@ -575,10 +575,8 @@ moduleFor( return this.visit('/').then(() => { this.handleURLAborts(assert, '/foo/bar/1/baz'); assert.equal(this.appRouter.currentPath, 'foo.bar.baz'); - assert.equal( - this.applicationInstance.lookup('router:main').get('location').getURL(), - '/foo/bar/2/baz' - ); + let router = this.applicationInstance.lookup('router:main'); + assert.equal(get(router, 'location').getURL(), '/foo/bar/2/baz'); }); } @@ -614,7 +612,7 @@ moduleFor( assert.equal(router.currentPath, 'foo.bar.baz'); run(() => router.send('goToQux')); assert.equal(router.currentPath, 'foo.qux'); - assert.equal(router.get('location').getURL(), '/foo/qux'); + assert.equal(get(router, 'location').getURL(), '/foo/qux'); }); } @@ -624,7 +622,7 @@ moduleFor( let setHistory; setHistory = function (obj, path) { - obj.set('history', { state: { path: path } }); + set(obj, 'history', { state: { path: path } }); }; let location = HistoryLocation.create({ @@ -632,7 +630,7 @@ moduleFor( let path = rootURL + '/posts'; setHistory(this, path); - this.set('location', { + set(this, 'location', { pathname: path, href: 'http://localhost/' + path, }); @@ -687,7 +685,7 @@ moduleFor( pushState() {}, }; initState() { - assert.equal(this.get('rootURL'), rootURL); + assert.equal(get(this, 'rootURL'), rootURL); } } ); @@ -1031,7 +1029,7 @@ moduleFor( return this.visit('/').then(() => { let router = this.applicationInstance.lookup('router:main'); - assert.equal(router.get('location.path'), '/about/TreeklesMcGeekles'); + assert.equal(get(router, 'location.path'), '/about/TreeklesMcGeekles'); }); } diff --git a/packages/ember/tests/routing/model_loading_test.js b/packages/ember/tests/routing/model_loading_test.js index 8a73e9e4652..b4c0779f8a1 100644 --- a/packages/ember/tests/routing/model_loading_test.js +++ b/packages/ember/tests/routing/model_loading_test.js @@ -92,7 +92,7 @@ moduleFor( 'route:home', class extends Route { setupController(controller) { - controller.set('hours', [ + set(controller, 'hours', [ 'Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm', @@ -227,7 +227,7 @@ moduleFor( 'route:home', class extends Route { setupController(/* controller */) { - this.controllerFor('home').set('hours', [ + set(this.controllerFor('home'), 'hours', [ 'Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm', @@ -306,7 +306,7 @@ moduleFor( setupController(controller, model) { assert.equal(this.controllerFor('home'), controller); - this.controllerFor('home').set('hours', model); + set(this.controllerFor('home'), 'hours', model); } } ); diff --git a/packages/ember/tests/routing/query_params_test.js b/packages/ember/tests/routing/query_params_test.js index 5c97de7313d..05456403123 100644 --- a/packages/ember/tests/routing/query_params_test.js +++ b/packages/ember/tests/routing/query_params_test.js @@ -1,6 +1,6 @@ import Controller from '@ember/controller'; import { dasherize } from '@ember/-internals/string'; -import EmberObject, { action, get, computed } from '@ember/object'; +import EmberObject, { action, get, computed, set } from '@ember/object'; import { RSVP } from '@ember/-internals/runtime'; import { run } from '@ember/runloop'; import { peekMeta } from '@ember/-internals/meta'; @@ -133,7 +133,7 @@ moduleFor( 'redirected to the sibling route, instead of child route' ); assert.equal( - this.getController('parent').get('foo'), + get(this.getController('parent'), 'foo'), 'lol', 'controller has value from the active transition' ); @@ -179,12 +179,12 @@ moduleFor( 'redirected to the sibling route, instead of child route' ); assert.equal( - this.getController('parent').get('string'), + get(this.getController('parent'), 'string'), 'hello', 'controller has value from the active transition' ); assert.deepEqual( - this.getController('parent').get('array'), + get(this.getController('parent'), 'array'), ['one', 2], 'controller has value from the active transition' ); @@ -236,7 +236,7 @@ moduleFor( this.assertCurrentPath('/?other_foo=WOO', "QP updated correctly without 'as'"); await this.transitionTo('/?other_foo=NAW'); - assert.equal(controller.get('foo'), 'NAW', 'QP managed correctly on URL transition'); + assert.equal(get(controller, 'foo'), 'NAW', 'QP managed correctly on URL transition'); await this.setAndFlush(controller, 'bar', 'NERK'); this.assertCurrentPath('/?other_bar=NERK&other_foo=NAW', "QP mapped correctly with 'as'"); @@ -388,7 +388,7 @@ moduleFor( class extends Route { setupController(controller) { assert.equal( - controller.get('foo'), + get(controller, 'foo'), 'YEAH', "controller's foo QP property set before setupController called" ); @@ -409,7 +409,7 @@ moduleFor( class extends Route { setupController(controller) { assert.equal( - controller.get('faz'), + get(controller, 'faz'), 'YEAH', "controller's foo QP property set before setupController called" ); @@ -752,7 +752,7 @@ moduleFor( router: service(), increment: action(function () { - this.incrementProperty('foo'); + set(this, 'foo', this.foo + 1); this.router.refresh(); }), }); @@ -858,7 +858,7 @@ moduleFor( await this.transitionTo('/'); let indexController = this.getController('index'); - assert.equal(indexController.get('omg'), 'lol'); + assert.equal(get(indexController, 'omg'), 'lol'); } async ['@test can opt into a replace query by specifying replace:true in the Route config hash']( @@ -1037,7 +1037,7 @@ moduleFor( class extends Route { setupController(controller) { assert.ok(true, 'setupController called'); - controller.set('omg', 'OVERRIDE'); + set(controller, 'omg', 'OVERRIDE'); } @action queryParamsDidChange() { @@ -1066,7 +1066,7 @@ moduleFor( class extends Route { setupController(controller) { assert.ok(true, 'setupController called'); - controller.set('omg', ['OVERRIDE']); + set(controller, 'omg', ['OVERRIDE']); } @action queryParamsDidChange() { @@ -1088,10 +1088,10 @@ moduleFor( return this.visit('/?omg=borf').then(() => { let indexController = this.getController('index'); - assert.equal(indexController.get('omg'), 'borf'); + assert.equal(get(indexController, 'omg'), 'borf'); this.transitionTo('/'); - assert.equal(indexController.get('omg'), 'lol'); + assert.equal(get(indexController, 'omg'), 'lol'); }); } @@ -1217,10 +1217,10 @@ moduleFor( return this.visit('/?foo=true').then(() => { let controller = this.getController('index'); - assert.equal(controller.get('foo'), true); + assert.equal(get(controller, 'foo'), true); this.transitionTo('/?foo=false'); - assert.equal(controller.get('foo'), false); + assert.equal(get(controller, 'foo'), false); }); } @@ -1237,7 +1237,7 @@ moduleFor( return this.visit('/?foo=').then(() => { let controller = this.getController('index'); - assert.equal(controller.get('foo'), ''); + assert.equal(get(controller, 'foo'), ''); }); } @@ -1283,7 +1283,7 @@ moduleFor( return this.visit('/?foo[]=1&foo[]=2&foo[]=3').then(() => { let controller = this.getController('index'); - assert.deepEqual(controller.get('foo'), ['1', '2', '3']); + assert.deepEqual(get(controller, 'foo'), ['1', '2', '3']); }); } @@ -1413,7 +1413,7 @@ moduleFor( await this.visitAndAssert('/home'); let controller = this.getController('home'); - assert.deepEqual(controller.get('foo'), [1, 2]); + assert.deepEqual(get(controller, 'foo'), [1, 2]); this.assertCurrentPath('/home'); await this.setAndFlush(controller, 'foo', [1, 3]); @@ -1421,7 +1421,7 @@ moduleFor( await this.transitionTo('/home'); - assert.deepEqual(controller.get('foo'), [1, 2]); + assert.deepEqual(get(controller, 'foo'), [1, 2]); this.assertCurrentPath('/home'); await this.setAndFlush(controller, 'foo', null); diff --git a/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js b/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js index 5b9670d4dff..eb8d4768947 100644 --- a/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js +++ b/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js @@ -1,6 +1,6 @@ import Controller from '@ember/controller'; import Route from '@ember/routing/route'; -import { computed } from '@ember/object'; +import { computed, get, set } from '@ember/object'; import { QueryParamTestCase, moduleFor, runLoopSettled } from 'internal-test-helpers'; class ModelDependentQPTestCase extends QueryParamTestCase { @@ -45,9 +45,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.$link2.click(); await runLoopSettled(); - assert.equal(this.controller.get('q'), 'wat'); - assert.equal(this.controller.get('z'), 0); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); + assert.equal(get(this.controller, 'q'), 'wat'); + assert.equal(get(this.controller, 'z'), 0); + assert.deepEqual(get(this.controller, 'model'), { id: 'a-2' }); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1?q=lol`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2`); assert.equal(this.$link3.getAttribute('href'), `${urlPrefix}/a-3`); @@ -63,9 +63,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { await this.transitionTo(`${urlPrefix}/a-1?q=lol`); - assert.deepEqual(this.controller.get('model'), { id: 'a-1' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(get(this.controller, 'model'), { id: 'a-1' }); + assert.equal(get(this.controller, 'q'), 'lol'); + assert.equal(get(this.controller, 'z'), 0); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1?q=lol`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2`); assert.equal(this.$link3.getAttribute('href'), `${urlPrefix}/a-3`); @@ -75,12 +75,12 @@ class ModelDependentQPTestCase extends QueryParamTestCase { await this.transitionTo(`${urlPrefix}/a-2?q=lol`); assert.deepEqual( - this.controller.get('model'), + get(this.controller, 'model'), { id: 'a-2' }, "controller's model changed to a-2" ); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.equal(get(this.controller, 'q'), 'lol'); + assert.equal(get(this.controller, 'z'), 0); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1?q=lol`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2?q=lol`); assert.equal(this.$link3.getAttribute('href'), `${urlPrefix}/a-3`); @@ -89,8 +89,8 @@ class ModelDependentQPTestCase extends QueryParamTestCase { await this.transitionTo(`${urlPrefix}/a-3?q=lol&z=123`); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 123); + assert.equal(get(this.controller, 'q'), 'lol'); + assert.equal(get(this.controller, 'z'), 123); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1?q=lol`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2?q=lol`); assert.equal(this.$link3.getAttribute('href'), `${urlPrefix}/a-3?q=lol&z=123`); @@ -114,9 +114,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.expectedModelHookParams = { id: 'a-1', q: 'wat', z: 0 }; await this.transitionTo(articleLookup, 'a-1'); - assert.deepEqual(this.controller.get('model'), { id: 'a-1' }); - assert.equal(this.controller.get('q'), 'wat'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(get(this.controller, 'model'), { id: 'a-1' }); + assert.equal(get(this.controller, 'q'), 'wat'); + assert.equal(get(this.controller, 'z'), 0); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2`); assert.equal(this.$link3.getAttribute('href'), `${urlPrefix}/a-3`); @@ -124,9 +124,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 }; await this.transitionTo(articleLookup, 'a-2', { queryParams: { q: 'lol' } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(get(this.controller, 'model'), { id: 'a-2' }); + assert.equal(get(this.controller, 'q'), 'lol'); + assert.equal(get(this.controller, 'z'), 0); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2?q=lol`); assert.equal(this.$link3.getAttribute('href'), `${urlPrefix}/a-3`); @@ -134,9 +134,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.expectedModelHookParams = { id: 'a-3', q: 'hay', z: 0 }; await this.transitionTo(articleLookup, 'a-3', { queryParams: { q: 'hay' } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-3' }); - assert.equal(this.controller.get('q'), 'hay'); - assert.equal(this.controller.get('z'), 0); + assert.deepEqual(get(this.controller, 'model'), { id: 'a-3' }); + assert.equal(get(this.controller, 'q'), 'hay'); + assert.equal(get(this.controller, 'z'), 0); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2?q=lol`); assert.equal(this.$link3.getAttribute('href'), `${urlPrefix}/a-3?q=hay`); @@ -144,9 +144,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 1 }; await this.transitionTo(articleLookup, 'a-2', { queryParams: { z: 1 } }); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 1); + assert.deepEqual(get(this.controller, 'model'), { id: 'a-2' }); + assert.equal(get(this.controller, 'q'), 'lol'); + assert.equal(get(this.controller, 'z'), 1); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2?q=lol&z=1`); assert.equal(this.$link3.getAttribute('href'), `${urlPrefix}/a-3?q=hay`); @@ -178,9 +178,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.$link2.click(); await runLoopSettled(); - assert.equal(this.controller.get('q'), 'lol'); - assert.equal(this.controller.get('z'), 0); - assert.deepEqual(this.controller.get('model'), { id: 'a-2' }); + assert.equal(get(this.controller, 'q'), 'lol'); + assert.equal(get(this.controller, 'z'), 0); + assert.deepEqual(get(this.controller, 'model'), { id: 'a-2' }); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1?q=lol`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2?q=lol`); @@ -189,9 +189,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.expectedModelHookParams = { id: 'a-3', q: 'haha', z: 123 }; await this.transitionTo(`${urlPrefix}/a-3?q=haha&z=123`); - assert.deepEqual(this.controller.get('model'), { id: 'a-3' }); - assert.equal(this.controller.get('q'), 'haha'); - assert.equal(this.controller.get('z'), 123); + assert.deepEqual(get(this.controller, 'model'), { id: 'a-3' }); + assert.equal(get(this.controller, 'q'), 'haha'); + assert.equal(get(this.controller, 'z'), 123); assert.equal(this.$link1.getAttribute('href'), `${urlPrefix}/a-1?q=haha`); assert.equal(this.$link2.getAttribute('href'), `${urlPrefix}/a-2?q=haha`); @@ -213,7 +213,7 @@ class ModelDependentQPTestCase extends QueryParamTestCase { await this.transitionTo(commentsLookupKey, 'a-1'); let commentsCtrl = this.getController(commentsLookupKey); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(get(commentsCtrl, 'page'), 1); this.assertCurrentPath(`${urlPrefix}/a-1/comments`); await this.setAndFlush(commentsCtrl, 'page', 2); @@ -223,11 +223,11 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.assertCurrentPath(`${urlPrefix}/a-1/comments?page=3`); await this.transitionTo(commentsLookupKey, 'a-2'); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(get(commentsCtrl, 'page'), 1); this.assertCurrentPath(`${urlPrefix}/a-2/comments`); await this.transitionTo(commentsLookupKey, 'a-1'); - assert.equal(commentsCtrl.get('page'), 3); + assert.equal(get(commentsCtrl, 'page'), 3); this.assertCurrentPath(`${urlPrefix}/a-1/comments?page=3`); } @@ -240,9 +240,9 @@ class ModelDependentQPTestCase extends QueryParamTestCase { this.reopenRoute(articleLookup, { resetController(controller, isExiting) { - this.controllerFor(commentsLookup).set('page', 1); + set(this.controllerFor(commentsLookup), 'page', 1); if (isExiting) { - controller.set('q', 'imdone'); + set(controller, 'q', 'imdone'); } }, }); @@ -259,19 +259,19 @@ class ModelDependentQPTestCase extends QueryParamTestCase { await this.transitionTo(commentsLookup, 'a-1'); let commentsCtrl = this.getController(commentsLookup); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(get(commentsCtrl, 'page'), 1); this.assertCurrentPath(`${urlPrefix}/a-1/comments`); await this.setAndFlush(commentsCtrl, 'page', 2); this.assertCurrentPath(`${urlPrefix}/a-1/comments?page=2`); await this.transitionTo(commentsLookup, 'a-2'); - assert.equal(commentsCtrl.get('page'), 1); - assert.equal(this.controller.get('q'), 'wat'); + assert.equal(get(commentsCtrl, 'page'), 1); + assert.equal(get(this.controller, 'q'), 'wat'); await this.transitionTo(commentsLookup, 'a-1'); this.assertCurrentPath(`${urlPrefix}/a-1/comments`); - assert.equal(commentsCtrl.get('page'), 1); + assert.equal(get(commentsCtrl, 'page'), 1); await this.transitionTo('about'); assert.equal( @@ -653,8 +653,8 @@ moduleFor( await this.boot(); this.links['s-1-a-1'].click(); await runLoopSettled(); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-1' }); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-1' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-1' }); this.assertCurrentPath('/site/s-1/a/a-1'); await this.setAndFlush(this.article_controller, 'q', 'lol'); @@ -684,11 +684,11 @@ moduleFor( this.links['s-1-a-2'].click(); await runLoopSettled(); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'wat'); - assert.equal(this.article_controller.get('z'), 0); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); + assert.equal(get(this.site_controller, 'country'), 'us'); + assert.equal(get(this.article_controller, 'q'), 'wat'); + assert.equal(get(this.article_controller, 'z'), 0); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-1' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-2' }); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?country=us&q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?country=us'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?country=us'); @@ -702,11 +702,11 @@ moduleFor( this.links['s-2-a-2'].click(); await runLoopSettled(); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'wat'); - assert.equal(this.article_controller.get('z'), 0); - assert.deepEqual(this.site_controller.get('model'), { id: 's-2' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); + assert.equal(get(this.site_controller, 'country'), 'au'); + assert.equal(get(this.article_controller, 'q'), 'wat'); + assert.equal(get(this.article_controller, 'z'), 0); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-2' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-2' }); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?country=us&q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?country=us'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?country=us'); @@ -731,18 +731,18 @@ moduleFor( await this.transitionTo('/site/s-1/a/a-1?q=lol'); assert.deepEqual( - this.site_controller.get('model'), + get(this.site_controller, 'model'), { id: 's-1' }, "site controller's model is s-1" ); assert.deepEqual( - this.article_controller.get('model'), + get(this.article_controller, 'model'), { id: 'a-1' }, "article controller's model is a-1" ); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 0); + assert.equal(get(this.site_controller, 'country'), 'au'); + assert.equal(get(this.article_controller, 'q'), 'lol'); + assert.equal(get(this.article_controller, 'z'), 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -762,18 +762,18 @@ moduleFor( await this.transitionTo('/site/s-2/a/a-1?country=us&q=lol'); assert.deepEqual( - this.site_controller.get('model'), + get(this.site_controller, 'model'), { id: 's-2' }, "site controller's model is s-2" ); assert.deepEqual( - this.article_controller.get('model'), + get(this.article_controller, 'model'), { id: 'a-1' }, "article controller's model is a-1" ); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 0); + assert.equal(get(this.site_controller, 'country'), 'us'); + assert.equal(get(this.article_controller, 'q'), 'lol'); + assert.equal(get(this.article_controller, 'z'), 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -793,18 +793,18 @@ moduleFor( await this.transitionTo('/site/s-2/a/a-2?country=us&q=lol'); assert.deepEqual( - this.site_controller.get('model'), + get(this.site_controller, 'model'), { id: 's-2' }, "site controller's model is s-2" ); assert.deepEqual( - this.article_controller.get('model'), + get(this.article_controller, 'model'), { id: 'a-2' }, "article controller's model is a-2" ); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 0); + assert.equal(get(this.site_controller, 'country'), 'us'); + assert.equal(get(this.article_controller, 'q'), 'lol'); + assert.equal(get(this.article_controller, 'z'), 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -824,18 +824,18 @@ moduleFor( await this.transitionTo('/site/s-2/a/a-3?country=us&q=lol&z=123'); assert.deepEqual( - this.site_controller.get('model'), + get(this.site_controller, 'model'), { id: 's-2' }, "site controller's model is s-2" ); assert.deepEqual( - this.article_controller.get('model'), + get(this.article_controller, 'model'), { id: 'a-3' }, "article controller's model is a-3" ); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 123); + assert.equal(get(this.site_controller, 'country'), 'us'); + assert.equal(get(this.article_controller, 'q'), 'lol'); + assert.equal(get(this.article_controller, 'z'), 123); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=lol&z=123'); @@ -858,18 +858,18 @@ moduleFor( await this.transitionTo('/site/s-3/a/a-3?country=nz&q=lol&z=123'); assert.deepEqual( - this.site_controller.get('model'), + get(this.site_controller, 'model'), { id: 's-3' }, "site controller's model is s-3" ); assert.deepEqual( - this.article_controller.get('model'), + get(this.article_controller, 'model'), { id: 'a-3' }, "article controller's model is a-3" ); - assert.equal(this.site_controller.get('country'), 'nz'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 123); + assert.equal(get(this.site_controller, 'country'), 'nz'); + assert.equal(get(this.article_controller, 'q'), 'lol'); + assert.equal(get(this.article_controller, 'z'), 123); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=lol&z=123'); @@ -901,11 +901,11 @@ moduleFor( }; await this.transitionTo('site.article', 's-1', 'a-1'); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-1' }); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'wat'); - assert.equal(this.article_controller.get('z'), 0); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-1' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-1' }); + assert.equal(get(this.site_controller, 'country'), 'au'); + assert.equal(get(this.article_controller, 'q'), 'wat'); + assert.equal(get(this.article_controller, 'z'), 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -926,11 +926,11 @@ moduleFor( queryParams: { q: 'lol' }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 0); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-1' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-2' }); + assert.equal(get(this.site_controller, 'country'), 'au'); + assert.equal(get(this.article_controller, 'q'), 'lol'); + assert.equal(get(this.article_controller, 'z'), 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3'); @@ -951,11 +951,11 @@ moduleFor( queryParams: { q: 'hay' }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-3' }); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'hay'); - assert.equal(this.article_controller.get('z'), 0); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-1' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-3' }); + assert.equal(get(this.site_controller, 'country'), 'au'); + assert.equal(get(this.article_controller, 'q'), 'hay'); + assert.equal(get(this.article_controller, 'z'), 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay'); @@ -976,11 +976,11 @@ moduleFor( queryParams: { z: 1 }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-1' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); - assert.equal(this.site_controller.get('country'), 'au'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 1); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-1' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-2' }); + assert.equal(get(this.site_controller, 'country'), 'au'); + assert.equal(get(this.article_controller, 'q'), 'lol'); + assert.equal(get(this.article_controller, 'z'), 1); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay'); @@ -1001,11 +1001,11 @@ moduleFor( queryParams: { country: 'us' }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-2' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-2' }); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'lol'); - assert.equal(this.article_controller.get('z'), 1); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-2' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-2' }); + assert.equal(get(this.site_controller, 'country'), 'us'); + assert.equal(get(this.article_controller, 'q'), 'lol'); + assert.equal(get(this.article_controller, 'z'), 1); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay'); @@ -1029,11 +1029,11 @@ moduleFor( queryParams: { q: 'yeah' }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-2' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-1' }); - assert.equal(this.site_controller.get('country'), 'us'); - assert.equal(this.article_controller.get('q'), 'yeah'); - assert.equal(this.article_controller.get('z'), 0); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-2' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-1' }); + assert.equal(get(this.site_controller, 'country'), 'us'); + assert.equal(get(this.article_controller, 'q'), 'yeah'); + assert.equal(get(this.article_controller, 'z'), 0); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=yeah'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay'); @@ -1057,11 +1057,11 @@ moduleFor( queryParams: { country: 'nz', z: 3 }, }); - assert.deepEqual(this.site_controller.get('model'), { id: 's-3' }); - assert.deepEqual(this.article_controller.get('model'), { id: 'a-3' }); - assert.equal(this.site_controller.get('country'), 'nz'); - assert.equal(this.article_controller.get('q'), 'hay'); - assert.equal(this.article_controller.get('z'), 3); + assert.deepEqual(get(this.site_controller, 'model'), { id: 's-3' }); + assert.deepEqual(get(this.article_controller, 'model'), { id: 'a-3' }); + assert.equal(get(this.site_controller, 'country'), 'nz'); + assert.equal(get(this.article_controller, 'q'), 'hay'); + assert.equal(get(this.article_controller, 'z'), 3); assert.equal(this.links['s-1-a-1'].getAttribute('href'), '/site/s-1/a/a-1?q=yeah'); assert.equal(this.links['s-1-a-2'].getAttribute('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(this.links['s-1-a-3'].getAttribute('href'), '/site/s-1/a/a-3?q=hay&z=3'); diff --git a/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js b/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js index ff94b12941b..dd678d61856 100644 --- a/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js +++ b/packages/ember/tests/routing/query_params_test/overlapping_query_params_test.js @@ -1,6 +1,8 @@ import Controller from '@ember/controller'; +import { get } from '@ember/object'; import Mixin from '@ember/object/mixin'; import { QueryParamTestCase, moduleFor, runLoopSettled } from 'internal-test-helpers'; +import { set } from '@ember/object'; moduleFor( 'Query Params - overlapping query param property names', @@ -37,14 +39,14 @@ moduleFor( await this.setAndFlush(parentChildController, 'page', 1); this.assertCurrentPath('/parent/child'); - parentController.set('page', 2); - parentChildController.set('page', 2); + set(parentController, 'page', 2); + set(parentChildController, 'page', 2); await runLoopSettled(); this.assertCurrentPath('/parent/child?childPage=2&parentPage=2'); - parentController.set('page', 1); - parentChildController.set('page', 1); + set(parentController, 'page', 1); + set(parentChildController, 'page', 1); await runLoopSettled(); this.assertCurrentPath('/parent/child'); @@ -172,13 +174,13 @@ moduleFor( await this.setAndFlush(parentChildController, 'page', 2); this.assertCurrentPath('/parent/child?page=2'); - assert.equal(parentController.get('page'), 1); - assert.equal(parentChildController.get('page'), 2); + assert.equal(get(parentController, 'page'), 1); + assert.equal(get(parentChildController, 'page'), 2); await this.setAndFlush(parentController, 'page', 2); this.assertCurrentPath('/parent/child?page=2&yespage=2'); - assert.equal(parentController.get('page'), 2); - assert.equal(parentChildController.get('page'), 2); + assert.equal(get(parentController, 'page'), 2); + assert.equal(get(parentChildController, 'page'), 2); } } ); diff --git a/packages/ember/tests/routing/query_params_test/query_param_async_get_handler_test.js b/packages/ember/tests/routing/query_params_test/query_param_async_get_handler_test.js index 6794e81fba3..d9fea62707f 100644 --- a/packages/ember/tests/routing/query_params_test/query_param_async_get_handler_test.js +++ b/packages/ember/tests/routing/query_params_test/query_param_async_get_handler_test.js @@ -122,7 +122,7 @@ moduleFor( queryParams: { foo: 'boo' }, }).then(() => { assert.equal( - postController.get('foo'), + get(postController, 'foo'), 'boo', 'simple QP is correctly set on controller' ); @@ -134,7 +134,7 @@ moduleFor( queryParams: { foo: 'bar' }, }).then(() => { assert.equal( - postController.get('foo'), + get(postController, 'foo'), 'bar', 'simple QP is correctly set with default value' ); @@ -160,7 +160,7 @@ moduleFor( queryParams: { comments: [1, 2] }, }).then(() => { assert.deepEqual( - postController.get('comments'), + get(postController, 'comments'), [1, 2], 'array QP is correctly set with default value' ); @@ -170,7 +170,7 @@ moduleFor( .then(() => { return this.transitionTo('post', 1338).then(() => { assert.deepEqual( - postController.get('comments'), + get(postController, 'comments'), [], 'array QP is correctly set on controller' ); @@ -203,12 +203,12 @@ moduleFor( queryParams: { note: 6, foo: 'boo' }, }).then(() => { assert.equal( - postController.get('foo'), + get(postController, 'foo'), 'boo', 'simple QP is correctly set on controller' ); assert.equal( - postIndexController.get('comment'), + get(postIndexController, 'comment'), 6, 'mapped QP is correctly set on controller' ); @@ -220,12 +220,12 @@ moduleFor( queryParams: { foo: 'bar' }, }).then(() => { assert.equal( - postController.get('foo'), + get(postController, 'foo'), 'bar', 'simple QP is correctly set with default value' ); assert.equal( - postIndexController.get('comment'), + get(postIndexController, 'comment'), 6, 'mapped QP retains value scoped to model' ); @@ -256,12 +256,12 @@ moduleFor( return this.transitionTo('/post/1337?foo=boo¬e=6').then(() => { assert.equal( - postController.get('foo'), + get(postController, 'foo'), 'boo', 'simple QP is correctly deserialized on controller' ); assert.equal( - postIndexController.get('comment'), + get(postIndexController, 'comment'), 6, 'mapped QP is correctly deserialized on controller' ); @@ -271,12 +271,12 @@ moduleFor( .then(() => { return this.transitionTo('/post/1337?note=6').then(() => { assert.equal( - postController.get('foo'), + get(postController, 'foo'), 'bar', 'simple QP is correctly deserialized with default value' ); assert.equal( - postIndexController.get('comment'), + get(postIndexController, 'comment'), 6, 'mapped QP retains value scoped to model' ); diff --git a/packages/ember/tests/routing/router_service_test/basic_test.js b/packages/ember/tests/routing/router_service_test/basic_test.js index aa5cc812eea..50cb46db8db 100644 --- a/packages/ember/tests/routing/router_service_test/basic_test.js +++ b/packages/ember/tests/routing/router_service_test/basic_test.js @@ -1,6 +1,6 @@ import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; -import { set } from '@ember/object'; +import { get, set } from '@ember/object'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; import { service } from '@ember/service'; @@ -19,7 +19,7 @@ moduleFor( assert.deepEqual(queryParams, {}); assert.deepEqual(paramNames, []); - assert.equal(this.routerService.get('currentRouteName'), 'parent.index'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.index'); }); } @@ -35,7 +35,7 @@ moduleFor( assert.deepEqual(queryParams, {}); assert.deepEqual(paramNames, []); - assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.child'); }); } @@ -57,7 +57,7 @@ moduleFor( assert.equal(name, 'parent.sister'); assert.equal(localName, 'sister'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.sister'); }); } @@ -93,7 +93,7 @@ moduleFor( assert.equal(name, 'parent.child'); assert.equal(localName, 'child'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.child'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.child'); return this.visit('/sister'); }) @@ -103,7 +103,7 @@ moduleFor( assert.equal(name, 'parent.sister'); assert.equal(localName, 'sister'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.sister'); return this.visit('/brother'); }) @@ -113,7 +113,7 @@ moduleFor( assert.equal(name, 'parent.brother'); assert.equal(localName, 'brother'); - assert.equal(this.routerService.get('currentRouteName'), 'parent.brother'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.brother'); }); } @@ -121,7 +121,7 @@ moduleFor( assert.expect(1); return this.visit('/').then(() => { - assert.equal(this.routerService.get('rootURL'), '/'); + assert.equal(get(this.routerService, 'rootURL'), '/'); }); } @@ -139,7 +139,7 @@ moduleFor( ); return this.visit('/').then(() => { - assert.equal(this.routerService.get('rootURL'), '/homepage'); + assert.equal(get(this.routerService, 'rootURL'), '/homepage'); }); } @@ -147,7 +147,7 @@ moduleFor( assert.expect(2); return this.visit('/').then(() => { - let location = this.routerService.get('location'); + let location = get(this.routerService, 'location'); assert.ok(location); assert.ok(location instanceof NoneLocation); }); diff --git a/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js b/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js index cdafbfb8646..d8db82921f6 100644 --- a/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js +++ b/packages/ember/tests/routing/router_service_test/currenturl_lifecycle_test.js @@ -19,20 +19,20 @@ let InstrumentedRoute = class extends Route { let service = get(this, 'routerService'); service.on('routeWillChange', (transition) => { results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} routeWillChange: ${transition.from && transition.from.name} - ${ transition.to.name }`, - service.get('currentURL'), + get(service, 'currentURL'), ]); }); service.on('routeDidChange', (transition) => { results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} routeDidChange: ${transition.from && transition.from.name} - ${ transition.to.name }`, - service.get('currentURL'), + get(service, 'currentURL'), ]); }); } @@ -40,36 +40,36 @@ let InstrumentedRoute = class extends Route { activate() { let service = get(this, 'routerService'); results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} activate`, - service.get('currentURL'), + get(service, 'currentURL'), ]); } redirect() { let service = get(this, 'routerService'); results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} redirect`, - service.get('currentURL'), + get(service, 'currentURL'), ]); } beforeModel() { let service = get(this, 'routerService'); results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} beforeModel`, - service.get('currentURL'), + get(service, 'currentURL'), ]); } model() { let service = get(this, 'routerService'); results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} model`, - service.get('currentURL'), + get(service, 'currentURL'), ]); return new RSVP.Promise((resolve) => { setTimeout(resolve, 200); @@ -79,9 +79,9 @@ let InstrumentedRoute = class extends Route { afterModel() { let service = get(this, 'routerService'); results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} afterModel`, - service.get('currentURL'), + get(service, 'currentURL'), ]); } @@ -89,11 +89,11 @@ let InstrumentedRoute = class extends Route { willTransition(transition) { let service = get(this, 'routerService'); results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} willTransition: ${transition.from && transition.from.name} - ${ transition.to.name }`, - service.get('currentURL'), + get(service, 'currentURL'), ]); return true; } @@ -102,9 +102,9 @@ let InstrumentedRoute = class extends Route { didTransition() { let service = get(this, 'routerService'); results.push([ - `${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`, + `${get(service, 'currentRouteName')} - ${get(service, 'currentRoute.name')}`, `${this.routeName} didTransition`, - service.get('currentURL'), + get(service, 'currentURL'), ]); return true; } @@ -145,7 +145,7 @@ moduleFor( assert.expect(1); return this.visit('/').then(() => { - assert.equal(this.routerService.get('currentURL'), '/'); + assert.equal(get(this.routerService, 'currentURL'), '/'); }); } @@ -153,7 +153,7 @@ moduleFor( assert.expect(1); return this.visit('/child').then(() => { - assert.equal(this.routerService.get('currentURL'), '/child'); + assert.equal(get(this.routerService, 'currentURL'), '/child'); }); } @@ -165,7 +165,7 @@ moduleFor( return this.routerService.transitionTo('parent.sister'); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/sister'); + assert.equal(get(this.routerService, 'currentURL'), '/sister'); }); } @@ -174,17 +174,17 @@ moduleFor( return this.visit('/child') .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child'); + assert.equal(get(this.routerService, 'currentURL'), '/child'); return this.visit('/sister'); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/sister'); + assert.equal(get(this.routerService, 'currentURL'), '/sister'); return this.visit('/brother'); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/brother'); + assert.equal(get(this.routerService, 'currentURL'), '/brother'); }); } diff --git a/packages/ember/tests/routing/router_service_test/non_application_test_test.js b/packages/ember/tests/routing/router_service_test/non_application_test_test.js index 3849bc2eac1..5df2c1653dc 100644 --- a/packages/ember/tests/routing/router_service_test/non_application_test_test.js +++ b/packages/ember/tests/routing/router_service_test/non_application_test_test.js @@ -51,11 +51,11 @@ moduleFor( ['@test RouterService properties can be accessed with default'](assert) { assert.expect(5); - assert.equal(this.routerService.get('currentRouteName'), null); - assert.equal(this.routerService.get('currentURL'), null); - assert.equal(this.routerService.get('location'), 'none'); - assert.equal(this.routerService.get('rootURL'), '/'); - assert.equal(this.routerService.get('currentRoute'), null); + assert.equal(get(this.routerService, 'currentRouteName'), null); + assert.equal(get(this.routerService, 'currentURL'), null); + assert.equal(get(this.routerService, 'location'), 'none'); + assert.equal(get(this.routerService, 'rootURL'), '/'); + assert.equal(get(this.routerService, 'currentRoute'), null); } ['@test RouterService properties of router can be accessed with default when router is present']( @@ -64,11 +64,11 @@ moduleFor( assert.expect(5); let router = this.owner.lookup('router:main'); router.setupRouter(); - assert.equal(this.routerService.get('currentRouteName'), null); - assert.equal(this.routerService.get('currentURL'), null); - assert.ok(this.routerService.get('location') instanceof NoneLocation); - assert.equal(this.routerService.get('rootURL'), '/'); - assert.equal(this.routerService.get('currentRoute'), null); + assert.equal(get(this.routerService, 'currentRouteName'), null); + assert.equal(get(this.routerService, 'currentURL'), null); + assert.ok(get(this.routerService, 'location') instanceof NoneLocation); + assert.equal(get(this.routerService, 'rootURL'), '/'); + assert.equal(get(this.routerService, 'currentRoute'), null); } ['@test RouterService#urlFor returns url'](assert) { @@ -113,7 +113,7 @@ moduleFor( componentInstance.transitionToSister(); }); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.sister'); assert.ok(this.routerService.isActive('parent.sister')); } diff --git a/packages/ember/tests/routing/router_service_test/replaceWith_test.js b/packages/ember/tests/routing/router_service_test/replaceWith_test.js index a97aacd0c90..6c176c7ac9a 100644 --- a/packages/ember/tests/routing/router_service_test/replaceWith_test.js +++ b/packages/ember/tests/routing/router_service_test/replaceWith_test.js @@ -2,6 +2,7 @@ import NoneLocation from '@ember/routing/none-location'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; import { InternalTransition as Transition } from 'router_js'; import Controller from '@ember/controller'; +import { set } from '@ember/object'; moduleFor( 'Router Service - replaceWith', @@ -17,12 +18,12 @@ moduleFor( class extends NoneLocation { setURL(path) { testCase.state.push(path); - this.set('path', path); + set(this, 'path', path); } replaceURL(path) { testCase.state.splice(testCase.state.length - 1, 1, path); - this.set('path', path); + set(this, 'path', path); } } ); diff --git a/packages/ember/tests/routing/router_service_test/transitionTo_test.js b/packages/ember/tests/routing/router_service_test/transitionTo_test.js index 2405af054e0..69410b6abf1 100644 --- a/packages/ember/tests/routing/router_service_test/transitionTo_test.js +++ b/packages/ember/tests/routing/router_service_test/transitionTo_test.js @@ -4,7 +4,7 @@ import Route from '@ember/routing/route'; import NoneLocation from '@ember/routing/none-location'; import Controller from '@ember/controller'; import { run } from '@ember/runloop'; -import { action, get } from '@ember/object'; +import { action, get, set } from '@ember/object'; import { RouterTestCase, moduleFor } from 'internal-test-helpers'; import { InternalTransition as Transition } from 'router_js'; @@ -22,12 +22,12 @@ moduleFor( class extends NoneLocation { setURL(path) { testCase.state.push(path); - this.set('path', path); + set(this, 'path', path); } replaceURL(path) { testCase.state.splice(testCase.state.length - 1, 1, path); - this.set('path', path); + set(this, 'path', path); } } ); @@ -121,7 +121,7 @@ moduleFor( componentInstance.transitionToSister(); }); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.sister'); }); } @@ -153,7 +153,7 @@ moduleFor( componentInstance.transitionToSister(); }); - assert.equal(this.routerService.get('currentRouteName'), 'parent.sister'); + assert.equal(get(this.routerService, 'currentRouteName'), 'parent.sister'); }); } @@ -188,8 +188,8 @@ moduleFor( componentInstance.transitionToDynamic(); }); - assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); - assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); + assert.equal(get(this.routerService, 'currentRouteName'), 'dynamic'); + assert.equal(get(this.routerService, 'currentURL'), '/dynamic/1'); this.assertText('much dynamicism'); } @@ -233,8 +233,8 @@ moduleFor( componentInstance.transitionToDynamic(); }); - assert.equal(this.routerService.get('currentRouteName'), 'dynamic'); - assert.equal(this.routerService.get('currentURL'), '/dynamic/1'); + assert.equal(get(this.routerService, 'currentRouteName'), 'dynamic'); + assert.equal(get(this.routerService, 'currentURL'), '/dynamic/1'); this.assertText('much dynamicism'); } @@ -258,7 +258,7 @@ moduleFor( return this.routerService.transitionTo('parent.child', queryParams); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child'); + assert.equal(get(this.routerService, 'currentURL'), '/child'); }); } @@ -279,13 +279,13 @@ moduleFor( return this.routerService.transitionTo('parent.child'); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child'); + assert.equal(get(this.routerService, 'currentURL'), '/child'); }) .then(() => { return this.routerService.transitionTo(queryParams); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?sort=DESC'); + assert.equal(get(this.routerService, 'currentURL'), '/child?sort=DESC'); }); } @@ -309,7 +309,7 @@ moduleFor( return this.routerService.transitionTo('parent.child', queryParams); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?sort=DESC'); + assert.equal(get(this.routerService, 'currentURL'), '/child?sort=DESC'); }); } @@ -335,7 +335,7 @@ moduleFor( return this.routerService.transitionTo('parent.child', queryParams); }) .then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?url_sort=DESC'); + assert.equal(get(this.routerService, 'currentURL'), '/child?url_sort=DESC'); }); } @@ -394,7 +394,7 @@ moduleFor( ); return this.visit('/').then(() => { - assert.equal(this.routerService.get('currentURL'), '/child?url_sort=ASC'); + assert.equal(get(this.routerService, 'currentURL'), '/child?url_sort=ASC'); }); } @@ -421,7 +421,7 @@ moduleFor( ); return this.visit('/child?url_sort=a').then(() => { - assert.equal(this.routerService.get('currentURL'), '/?url_sort=a'); + assert.equal(get(this.routerService, 'currentURL'), '/?url_sort=a'); }); } } diff --git a/packages/ember/tests/routing/router_service_test/urlFor_test.js b/packages/ember/tests/routing/router_service_test/urlFor_test.js index 5ff61130e8d..0490b7286ab 100644 --- a/packages/ember/tests/routing/router_service_test/urlFor_test.js +++ b/packages/ember/tests/routing/router_service_test/urlFor_test.js @@ -211,7 +211,7 @@ moduleFor( return this.routerService.transitionTo(expectedURL); }) .then(() => { - assert.equal(expectedURL, this.routerService.get('currentURL')); + assert.equal(expectedURL, get(this.routerService, 'currentURL')); }); } @@ -239,7 +239,7 @@ moduleFor( return this.routerService.transitionTo(expectedURL); }) .then(() => { - assert.equal(expectedURL, this.routerService.get('currentURL')); + assert.equal(expectedURL, get(this.routerService, 'currentURL')); }); } @@ -259,7 +259,7 @@ moduleFor( return this.routerService.transitionTo(expectedURL); }) .then(() => { - actualURL = `${this.routerService.get('currentURL')}?foo=bar`; + actualURL = `${get(this.routerService, 'currentURL')}?foo=bar`; assert.equal(expectedURL, actualURL); }); @@ -291,7 +291,7 @@ moduleFor( return this.routerService.transitionTo(expectedURL); }) .then(() => { - actualURL = `${this.routerService.get('currentURL')}?foo=bar`; + actualURL = `${get(this.routerService, 'currentURL')}?foo=bar`; assert.equal(expectedURL, actualURL); }); diff --git a/packages/ember/tests/routing/substates_test.js b/packages/ember/tests/routing/substates_test.js index 6d328591b76..f7b9e3f472e 100644 --- a/packages/ember/tests/routing/substates_test.js +++ b/packages/ember/tests/routing/substates_test.js @@ -1,7 +1,7 @@ import { RSVP } from '@ember/-internals/runtime'; import Route from '@ember/routing/route'; import Controller from '@ember/controller'; -import { action } from '@ember/object'; +import { action, get, set } from '@ember/object'; import { service } from '@ember/service'; import { moduleFor, ApplicationTestCase, runTask } from 'internal-test-helpers'; @@ -35,7 +35,7 @@ moduleFor( get currentPath() { let currentPath; expectDeprecation(() => { - currentPath = this.getController('application').get('currentPath'); + currentPath = get(this.getController('application'), 'currentPath'); }, 'Accessing `currentPath` on `controller:application` is deprecated, use the `currentPath` property on `service:router` instead.'); return currentPath; } @@ -1268,7 +1268,7 @@ moduleFor( assert.equal(this.appRouter.currentPath, 'memere.loading', 'Initial route should be loading'); - memereController.set('test', 3); + set(memereController, 'test', 3); assert.equal( this.appRouter.currentPath, @@ -1277,7 +1277,7 @@ moduleFor( ); assert.equal( - memereController.get('test'), + get(memereController, 'test'), 3, 'Controller query param value should have changed' ); diff --git a/packages/ember/tests/routing/template_rendering_test.js b/packages/ember/tests/routing/template_rendering_test.js index ca03005c55b..c7e792525a0 100644 --- a/packages/ember/tests/routing/template_rendering_test.js +++ b/packages/ember/tests/routing/template_rendering_test.js @@ -2,6 +2,7 @@ import Route from '@ember/routing/route'; import Controller from '@ember/controller'; import EmberObject from '@ember/object'; +import { set } from '@ember/object'; import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers'; import { run } from '@ember/runloop'; import { Component } from '@ember/-internals/glimmer'; @@ -263,7 +264,9 @@ moduleFor( rootElement = document.getElementById('qunit-fixture'); assert.equal(rootElement.textContent.trim(), 'HiBye', 'initial render'); - run(() => this.applicationInstance.lookup('controller:sample').set('showTheThing', true)); + run(() => + set(this.applicationInstance.lookup('controller:sample'), 'showTheThing', true) + ); assert.equal(rootElement.textContent.trim(), 'HiYayBye', 'second render'); return this.visit('/2'); @@ -335,7 +338,7 @@ moduleFor( 'didInsertElement not invoked on displayed component' ); - run(() => indexController.set('showFirst', false)); + run(() => set(indexController, 'showFirst', false)); assert.strictEqual( myComponentCounter, diff --git a/packages/ember/tests/service_injection_test.js b/packages/ember/tests/service_injection_test.js index c3906044995..5fb1193f227 100644 --- a/packages/ember/tests/service_injection_test.js +++ b/packages/ember/tests/service_injection_test.js @@ -1,7 +1,7 @@ import Controller from '@ember/controller'; import Service, { service } from '@ember/service'; import { moduleFor, ApplicationTestCase } from 'internal-test-helpers'; -import { computed } from '@ember/object'; +import { computed, get } from '@ember/object'; moduleFor( 'Service Injection', @@ -21,7 +21,7 @@ moduleFor( await this.visit('/'); let controller = this.applicationInstance.lookup('controller:application'); - assert.ok(controller.get('myService') instanceof MyService); + assert.ok(get(controller, 'myService') instanceof MyService); } } ); diff --git a/packages/internal-test-helpers/lib/test-cases/application.ts b/packages/internal-test-helpers/lib/test-cases/application.ts index 81a09b77ce0..23a1ed34c95 100644 --- a/packages/internal-test-helpers/lib/test-cases/application.ts +++ b/packages/internal-test-helpers/lib/test-cases/application.ts @@ -1,5 +1,6 @@ import TestResolverApplicationTestCase from './test-resolver-application'; import Application from '@ember/application'; +import { get } from '@ember/object'; import Router from '@ember/routing/router'; import { runTask, runLoopSettled } from '../run'; @@ -42,7 +43,7 @@ export default abstract class ApplicationTestCase extends TestResolverApplicatio } get currentURL() { - return this.appRouter.get('currentURL'); + return get(this.appRouter, 'currentURL'); } async transitionTo() { diff --git a/packages/internal-test-helpers/lib/test-cases/query-param.ts b/packages/internal-test-helpers/lib/test-cases/query-param.ts index 18cddb58c0a..910df449ab2 100644 --- a/packages/internal-test-helpers/lib/test-cases/query-param.ts +++ b/packages/internal-test-helpers/lib/test-cases/query-param.ts @@ -1,6 +1,7 @@ import type { BootOptions } from '@ember/engine/instance'; import Controller from '@ember/controller'; import type EmberObject from '@ember/object'; +import { get, set, setProperties } from '@ember/object'; import NoneLocation from '@ember/routing/none-location'; import ApplicationTestCase from './application'; @@ -30,7 +31,7 @@ export default abstract class QueryParamTestCase extends ApplicationTestCase { testCase.expectedPushURL = null; } - this.set('path', path); + set(this, 'path', path); } replaceURL(path: string) { @@ -47,7 +48,7 @@ export default abstract class QueryParamTestCase extends ApplicationTestCase { testCase.expectedReplaceURL = null; } - this.set('path', path); + set(this, 'path', path); } } ); @@ -77,16 +78,16 @@ export default abstract class QueryParamTestCase extends ApplicationTestCase { async setAndFlush(obj: EmberObject, prop: string, value: unknown): Promise; async setAndFlush(obj: EmberObject, prop: Record | string, value?: unknown) { if (typeof prop === 'object') { - obj.setProperties(prop); + setProperties(obj, prop); } else { - obj.set(prop, value); + set(obj, prop, value); } await runLoopSettled(); } assertCurrentPath(path: string, message = `current path equals '${path}'`) { - this.assert.equal(this.appRouter.get('location.path'), path, message); + this.assert.equal(get(this.appRouter, 'location.path'), path, message); } /** diff --git a/tests/docs/expected.js b/tests/docs/expected.js index ec7a58e074e..65560f880e0 100644 --- a/tests/docs/expected.js +++ b/tests/docs/expected.js @@ -89,7 +89,6 @@ module.exports = { 'buildRouteInfoMetadata', 'cache', 'cached', - 'cacheFor', 'canCatalogEntriesByType', 'cancel', 'cancelRouterSetup', @@ -137,7 +136,6 @@ module.exports = { 'debugCreationStack', 'debugger', 'debugPreviousTransition', - 'decrementProperty', 'defer', 'deferReadiness', 'defineProperty', @@ -231,7 +229,6 @@ module.exports = { 'hash', 'hashSettled', 'hasListeners', - 'hasObserverFor', 'hasRegistration', 'hasRoute', 'helper', @@ -239,7 +236,6 @@ module.exports = { 'htmlSafe', 'if', 'in-element', - 'incrementProperty', 'info', 'init', 'initializer', @@ -318,7 +314,6 @@ module.exports = { 'not', 'notifyPropertyChange', 'observeModelType', - 'observer', 'off', 'on', 'once', @@ -448,7 +443,6 @@ module.exports = { 'this[RENDER]', 'throttle', 'to', - 'toggleProperty', 'toString', 'toHTML', 'tracked', diff --git a/type-tests/@ember/application-test/application.ts b/type-tests/@ember/application-test/application.ts index eaf28975645..cb15c542567 100755 --- a/type-tests/@ember/application-test/application.ts +++ b/type-tests/@ember/application-test/application.ts @@ -21,7 +21,7 @@ BaseApp.initializer({ BaseApp.instanceInitializer({ name: 'my-instance-initializer', initialize(app) { - (app.lookup('foo:bar') as Obj).get('foo'); + (app.lookup('foo:bar') as Obj).foo; }, }); diff --git a/type-tests/@ember/component-test/component.ts b/type-tests/@ember/component-test/component.ts index e1f82b69666..e7fd05696ef 100644 --- a/type-tests/@ember/component-test/component.ts +++ b/type-tests/@ember/component-test/component.ts @@ -1,5 +1,5 @@ import Component from '@ember/component'; -import Object, { computed, get } from '@ember/object'; +import Object, { computed, get, set } from '@ember/object'; import { expectTypeOf } from 'expect-type'; Component.extend({ @@ -25,7 +25,7 @@ class AnotherComponent extends Component { } hello(name: string) { - this.set('name', name); + set(this, 'name', name); this.name = name; } } @@ -44,7 +44,7 @@ class Bindings extends Component { @computed() get propertyB() { - if (!this.get('propertyA')) { + if (!this.propertyA) { return 'from-b'; } } diff --git a/type-tests/@ember/controller-test/main.ts b/type-tests/@ember/controller-test/main.ts index 4fc8c2f0347..d724ab6cd58 100644 --- a/type-tests/@ember/controller-test/main.ts +++ b/type-tests/@ember/controller-test/main.ts @@ -1,4 +1,5 @@ import Controller, { inject } from '@ember/controller'; +import { set } from '@ember/object'; class MyController extends Controller { queryParams = ['category']; @@ -9,6 +10,6 @@ class MyController extends Controller { @inject('second') declare second: Controller; toggleBody() { - this.toggleProperty('isExpanded'); + set(this, 'isExpanded', !this.isExpanded); } } diff --git a/type-tests/@ember/engine-test/engine.ts b/type-tests/@ember/engine-test/engine.ts index e6a0057874f..b1793b26c8b 100755 --- a/type-tests/@ember/engine-test/engine.ts +++ b/type-tests/@ember/engine-test/engine.ts @@ -19,7 +19,7 @@ BaseEngine.initializer({ BaseEngine.instanceInitializer({ name: 'my-instance-initializer', initialize(engine) { - (engine.lookup('foo:bar') as Obj).get('foo'); + (engine.lookup('foo:bar') as Obj).foo; }, }); diff --git a/type-tests/@ember/object-test/computed.ts b/type-tests/@ember/object-test/computed.ts index def8500b86f..431a163a391 100644 --- a/type-tests/@ember/object-test/computed.ts +++ b/type-tests/@ember/object-test/computed.ts @@ -1,4 +1,4 @@ -import EmberObject, { computed } from '@ember/object'; +import EmberObject, { computed, set } from '@ember/object'; import { alias, or, @@ -38,28 +38,28 @@ class Person extends EmberObject { @computed('firstName', 'lastName') get fullName(): string { - return `${this.get('firstName')} ${this.get('lastName')}`; + return `${this.firstName} ${this.lastName}`; } @(computed('fullName').readOnly()) get fullNameReadonly() { - return this.get('fullName'); + return this.fullName; } @computed('firstName', 'lastName') get fullNameWritable(): string { - return this.get('fullName'); + return this.fullName; } set fullNameWritable(value: string) { const [first, last] = value.split(' '); - this.set('firstName', first); - this.set('lastName', last); + set(this, 'firstName', first); + set(this, 'lastName', last); } @(computed().meta({ foo: 'bar' }).readOnly()) get combinators() { - return this.get('firstName'); + return this.firstName; } @alias('fullName') @@ -84,43 +84,22 @@ expectTypeOf(person.fullNameWritable).toEqualTypeOf(); expectTypeOf(person.combinators).toEqualTypeOf(); expectTypeOf(person.explicitlyDeclared).toEqualTypeOf(); -expectTypeOf(person.get('firstName')).toEqualTypeOf(); -expectTypeOf(person.get('age')).toEqualTypeOf(); -expectTypeOf(person.get('noArgs')).toEqualTypeOf(); -expectTypeOf(person.get('fullName')).toEqualTypeOf(); -expectTypeOf(person.get('fullNameReadonly')).toEqualTypeOf(); -expectTypeOf(person.get('fullNameWritable')).toEqualTypeOf(); -expectTypeOf(person.get('combinators')).toEqualTypeOf(); -expectTypeOf(person.get('explicitlyDeclared')).toEqualTypeOf(); - -expectTypeOf(person.getProperties('firstName', 'fullName', 'age')).toMatchTypeOf<{ - firstName: string; - fullName: string; - age: number; -}>(); - const person2 = Person.create({ fullName: 'Fred Smith', }); -expectTypeOf(person2.get('firstName')).toEqualTypeOf(); -expectTypeOf(person2.get('fullName')).toEqualTypeOf(); - const person3 = Person.extend({ firstName: 'Fred', fullName: 'Fred Smith', }).create(); -expectTypeOf(person3.get('firstName')).toEqualTypeOf(); -expectTypeOf(person3.get('fullName')).toEqualTypeOf(); - const person4 = Person.extend({ firstName: computed(() => 'Fred'), fullName: computed(() => 'Fred Smith'), }).create(); -expectTypeOf(person4.get('firstName')).toEqualTypeOf(); -expectTypeOf(person4.get('fullName')).toEqualTypeOf(); +expectTypeOf(person4.firstName).toEqualTypeOf(); +expectTypeOf(person4.fullName).toEqualTypeOf(); // computed property macros class Bar extends EmberObject { diff --git a/type-tests/@ember/object-test/create.ts b/type-tests/@ember/object-test/create.ts index e615991b6b4..c89b6a5a5a6 100644 --- a/type-tests/@ember/object-test/create.ts +++ b/type-tests/@ember/object-test/create.ts @@ -10,7 +10,6 @@ expectTypeOf(o).toBeObject(); // object returned by create type-checks as an instance of EmberObject expectTypeOf(o.isDestroyed).toBeBoolean(); expectTypeOf(o.isDestroying).toBeBoolean(); -expectTypeOf(o.get).toMatchTypeOf<(key: K) => EmberObject[K]>(); /** * One-argument case @@ -50,7 +49,6 @@ const p = Person.create(); expectTypeOf(p.firstName).toBeString(); expectTypeOf(p.fullName).toBeString(); -expectTypeOf(p.get('fullName')).toBeString(); Person.create({ firstName: 'string' }); Person.create({}, { firstName: 'string' }); diff --git a/type-tests/@ember/object-test/extend.ts b/type-tests/@ember/object-test/extend.ts index 19ee88b8a45..9e53757bfbd 100644 --- a/type-tests/@ember/object-test/extend.ts +++ b/type-tests/@ember/object-test/extend.ts @@ -8,9 +8,6 @@ class Person extends EmberObject { get fullName() { return `${this.firstName} ${this.lastName}`; } - get fullName2(): string { - return `${this.get('firstName')} ${this.get('lastName')}`; - } } expectTypeOf(Person.prototype.firstName).toBeString(); diff --git a/type-tests/@ember/object-test/object.ts b/type-tests/@ember/object-test/object.ts index 202508c0e0b..c2bca7bcdc2 100644 --- a/type-tests/@ember/object-test/object.ts +++ b/type-tests/@ember/object-test/object.ts @@ -51,18 +51,9 @@ class Foo extends Object { // today, this is an acceptable workaround for now. It is assignable *or* // castable. // eslint-disable-next-line @typescript-eslint/no-unused-vars - const a: number = this.get('b'); - - expectTypeOf(this.get('b').toFixed(4)).toEqualTypeOf(); - expectTypeOf(this.set('a', 'abc').split(',')).toEqualTypeOf(); - expectTypeOf(this.set('b', 10).toFixed(4)).toEqualTypeOf(); - - this.setProperties({ b: 11 }); - // this.setProperties({ b: '11' }); // @ts-expect-error - this.setProperties({ - a: 'def', - b: 11, - }); + const a: number = this.b; + + expectTypeOf(this.b.toFixed(4)).toEqualTypeOf(); } } @@ -70,20 +61,10 @@ export class Foo2 extends Object { name = ''; changeName(name: string) { - expectTypeOf(this.set('name', name)).toBeString(); expectTypeOf(set(this, 'name', name)).toBeString(); - // For some reason, `this` type lookup does not resolve correctly here. Used - // outside a class, like `get(someFoo, 'name')`, this works correctly. Since - // there are basically no cases inside a class where you *have* to use `get` - // today, this is an acceptable workaround for now. It is assignable *or* - // castable. - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const s: string = this.get('name'); expectTypeOf(get(this as Foo2, 'name')).toBeString(); - expectTypeOf((this as Foo2).get('name')).toBeString(); - expectTypeOf(this.setProperties({ name })).toEqualTypeOf<{ name: string }>(); expectTypeOf(setProperties(this, { name })).toEqualTypeOf<{ name: string }>(); } diff --git a/type-tests/@ember/object-test/observable.ts b/type-tests/@ember/object-test/observable.ts index 47f7d5b9b97..40b545a2ca9 100644 --- a/type-tests/@ember/object-test/observable.ts +++ b/type-tests/@ember/object-test/observable.ts @@ -7,19 +7,13 @@ class MyComponent extends EmberObject { init() { this._super.apply(this); - this.addObserver('foo', this, 'fooDidChange'); - this.addObserver('foo', this, this.fooDidChange); addObserver(this, 'foo', this, 'fooDidChange'); addObserver(this, 'foo', this, this.fooDidChange); - this.removeObserver('foo', this, 'fooDidChange'); - this.removeObserver('foo', this, this.fooDidChange); removeObserver(this, 'foo', this, 'fooDidChange'); removeObserver(this, 'foo', this, this.fooDidChange); const lambda = () => { this.fooDidChange(this, 'foo'); }; - this.addObserver('foo', lambda); - this.removeObserver('foo', lambda); addObserver(this, 'foo', lambda); removeObserver(this, 'foo', lambda); } @@ -29,17 +23,13 @@ class MyComponent extends EmberObject { } } -const myComponent = MyComponent.create(); -myComponent.addObserver('foo', null, () => {}); -myComponent.set('foo', 'baz'); - class Person extends EmberObject { name = 'Fred'; age = 29; @computed() get capitalized() { - return this.get('name').toUpperCase(); + return this.name.toUpperCase(); } } const person = Person.create(); @@ -50,9 +40,9 @@ function testGet() { expectTypeOf(get(person, 'name')).toEqualTypeOf(); expectTypeOf(get(person, 'age')).toEqualTypeOf(); expectTypeOf(get(person, 'capitalized')).toEqualTypeOf(); - expectTypeOf(person.get('name')).toEqualTypeOf(); - expectTypeOf(person.get('age')).toEqualTypeOf(); - expectTypeOf(person.get('capitalized')).toEqualTypeOf(); + expectTypeOf(person.name).toEqualTypeOf(); + expectTypeOf(person.age).toEqualTypeOf(); + expectTypeOf(person.capitalized).toEqualTypeOf(); expectTypeOf(get(pojo, 'name')).toEqualTypeOf(); } @@ -66,18 +56,6 @@ function testGetProperties() { expectTypeOf(getProperties(person, 'name', 'age', 'capitalized')).toEqualTypeOf< Pick >(); - expectTypeOf(person.getProperties('name')).toEqualTypeOf<{ name: string }>(); - expectTypeOf(person.getProperties('name', 'age')).toEqualTypeOf<{ name: string; age: number }>(); - expectTypeOf(person.getProperties(['name', 'age'])).toEqualTypeOf<{ - name: string; - age: number; - }>(); - - expectTypeOf(person.getProperties('name', 'age', 'capitalized')).toEqualTypeOf<{ - name: string; - age: number; - capitalized: string; - }>(); expectTypeOf(getProperties(pojo, 'name', 'age')).toEqualTypeOf<{ name: string; age: number }>(); } @@ -85,9 +63,6 @@ function testSet() { expectTypeOf(set(person, 'name', 'Joe')).toEqualTypeOf(); expectTypeOf(set(person, 'age', 35)).toEqualTypeOf(); expectTypeOf(set(person, 'capitalized', 'JOE')).toEqualTypeOf(); - expectTypeOf(person.set('name', 'Joe')).toEqualTypeOf<'Joe'>(); - expectTypeOf(person.set('age', 35)).toEqualTypeOf<35>(); - expectTypeOf(person.set('capitalized', 'JOE')).toEqualTypeOf<'JOE'>(); expectTypeOf(set(pojo, 'name', 'Joe')).toEqualTypeOf(); } @@ -100,14 +75,6 @@ function testSetProperties() { expectTypeOf(setProperties(person, { name: 'Joe', capitalized: 'JOE' })).toEqualTypeOf< Pick >(); - expectTypeOf(person.setProperties({ name: 'Joe' })).toEqualTypeOf<{ name: string }>(); - expectTypeOf(person.setProperties({ name: 'Joe', age: 35 })).toEqualTypeOf< - Pick - >(); - expectTypeOf(person.setProperties({ name: 'Joe', capitalized: 'JOE' })).toEqualTypeOf<{ - name: string; - capitalized: string; - }>(); expectTypeOf(setProperties(pojo, { name: 'Joe', age: 35 })).toEqualTypeOf< Pick >(); diff --git a/type-tests/@ember/object-test/reopen.ts b/type-tests/@ember/object-test/reopen.ts index cd361c11d5f..3319305adc8 100644 --- a/type-tests/@ember/object-test/reopen.ts +++ b/type-tests/@ember/object-test/reopen.ts @@ -1,4 +1,4 @@ -import EmberObject from '@ember/object'; +import EmberObject, { get } from '@ember/object'; import Mixin from '@ember/object/mixin'; import { expectTypeOf } from 'expect-type'; @@ -6,7 +6,7 @@ class Person extends EmberObject { name = ''; sayHello() { - alert(`Hello. My name is ${this.get('name')}`); + alert(`Hello. My name is ${this.name}`); } } @@ -53,13 +53,13 @@ const Person3 = Person2.reopen({ goodbyeMessage: 'goodbye', sayGoodbye(this: Person) { - alert(`${this.get('goodbyeMessage')}, ${this.get('name')}`); + alert(`${get(this, 'goodbyeMessage')}, ${get(this, 'name')}`); }, }); const person3 = Person3.create(); -person3.get('name'); -person3.get('goodbyeMessage'); +person3.name; +get(person3, 'goodbyeMessage'); person3.sayHello(); // @ts-expect-error person3.sayGoodbye(); diff --git a/type-tests/@ember/routing-test/route.ts b/type-tests/@ember/routing-test/route.ts index 819cb192602..ffe2f37a368 100755 --- a/type-tests/@ember/routing-test/route.ts +++ b/type-tests/@ember/routing-test/route.ts @@ -2,7 +2,7 @@ /* eslint-disable prefer-const */ import Route from '@ember/routing/route'; import type Array from '@ember/array'; -import EmberObject from '@ember/object'; +import EmberObject, { set } from '@ember/object'; import Controller from '@ember/controller'; import type Transition from '@ember/routing/transition'; import { expectTypeOf } from 'expect-type'; @@ -120,7 +120,7 @@ declare module '@ember/controller' { class SetupControllerTest extends Route { setupController(controller: Controller, model: {}, transition: Transition) { this._super(controller, model); - this.controllerFor('application').set('model', model); + set(this.controllerFor('application'), 'model', model); transition.abort(); } } diff --git a/type-tests/@ember/runloop-tests.ts b/type-tests/@ember/runloop-tests.ts index 6346746e6a4..08cd6453ad6 100644 --- a/type-tests/@ember/runloop-tests.ts +++ b/type-tests/@ember/runloop-tests.ts @@ -15,7 +15,7 @@ import { // private, supported via `declare module` below _backburner, } from '@ember/runloop'; -import EmberObject, { action } from '@ember/object'; +import EmberObject, { action, set } from '@ember/object'; import type { AnyFn, MethodsOf } from '@ember/-internals/utility-types'; import { expectTypeOf } from 'expect-type'; @@ -86,7 +86,7 @@ class TestBind extends EmberObject { editor: string | null = null; setupEditor(editor: string) { - this.set('editor', editor); + set(this, 'editor', editor); } } diff --git a/type-tests/ember/application.ts b/type-tests/ember/application.ts index 3f4aa047652..31604bc1338 100755 --- a/type-tests/ember/application.ts +++ b/type-tests/ember/application.ts @@ -17,7 +17,7 @@ BaseApp.initializer({ BaseApp.instanceInitializer({ name: 'my-instance-initializer', initialize(app) { - (app.lookup('foo:bar') as Obj).get('foo'); + Ember.get((app.lookup('foo:bar') as Obj), 'foo'); }, }); diff --git a/type-tests/ember/component.ts b/type-tests/ember/component.ts index 493645d31e2..ffae1f7953c 100755 --- a/type-tests/ember/component.ts +++ b/type-tests/ember/component.ts @@ -1,4 +1,5 @@ import Ember from 'ember'; +import { set } from '@ember/object'; import { expectTypeOf } from 'expect-type'; Ember.Component.extend({ @@ -20,7 +21,7 @@ class AnotherComponent extends Ember.Component { name = ''; hello(name: string) { - this.set('name', name); + set(this, 'name', name); this.name = name; } } @@ -39,7 +40,7 @@ class Bindings extends Ember.Component { @Ember.computed() get propertyB() { - if (!this.get('propertyA')) { + if (!this.propertyA) { return 'from-b'; } } diff --git a/type-tests/ember/computed.ts b/type-tests/ember/computed.ts index a2207e734a5..4971f70e237 100755 --- a/type-tests/ember/computed.ts +++ b/type-tests/ember/computed.ts @@ -1,4 +1,5 @@ import Ember from 'ember'; +import { set } from '@ember/object'; import { expectTypeOf } from 'expect-type'; function customMacro(message: string) { @@ -20,28 +21,28 @@ class Person extends Ember.Object { @Ember.computed('firstName', 'lastName') get fullName(): string { - return `${this.get('firstName')} ${this.get('lastName')}`; + return `${this.firstName} ${this.lastName}`; } @(Ember.computed('fullName').readOnly()) get fullNameReadonly() { - return this.get('fullName'); + return this.fullName; } @Ember.computed('firstName', 'lastName') get fullNameWritable(): string { - return this.get('fullName'); + return this.fullName; } set fullNameWritable(value: string) { const [first, last] = value.split(' '); - this.set('firstName', first); - this.set('lastName', last); + set(this, 'firstName', first); + set(this, 'lastName', last); } @(Ember.computed().meta({ foo: 'bar' }).readOnly()) get combinators() { - return this.get('firstName'); + return this.firstName; } @customMacro('hi') @@ -62,39 +63,25 @@ expectTypeOf(person.fullNameReadonly).toEqualTypeOf(); expectTypeOf(person.fullNameWritable).toEqualTypeOf(); expectTypeOf(person.combinators).toEqualTypeOf(); -expectTypeOf(person.get('firstName')).toEqualTypeOf(); -expectTypeOf(person.get('age')).toEqualTypeOf(); -expectTypeOf(person.get('noArgs')).toEqualTypeOf(); -expectTypeOf(person.get('fullName')).toEqualTypeOf(); -expectTypeOf(person.get('fullNameReadonly')).toEqualTypeOf(); -expectTypeOf(person.get('fullNameWritable')).toEqualTypeOf(); -expectTypeOf(person.get('combinators')).toEqualTypeOf(); - -expectTypeOf(person.getProperties('firstName', 'fullName', 'age')).toMatchTypeOf<{ - firstName: string; - fullName: string; - age: number; -}>(); - const person2 = Person.create({ fullName: 'Fred Smith', }); -expectTypeOf(person2.get('firstName')).toEqualTypeOf(); -expectTypeOf(person2.get('fullName')).toEqualTypeOf(); +expectTypeOf(person2.firstName).toEqualTypeOf(); +expectTypeOf(person2.fullName).toEqualTypeOf(); const person3 = Person.extend({ firstName: 'Fred', fullName: 'Fred Smith', }).create(); -expectTypeOf(person3.get('firstName')).toEqualTypeOf(); -expectTypeOf(person3.get('fullName')).toEqualTypeOf(); +expectTypeOf(person3.firstName).toEqualTypeOf(); +expectTypeOf(person3.fullName).toEqualTypeOf(); const person4 = Person.extend({ firstName: Ember.computed(() => 'Fred'), fullName: Ember.computed(() => 'Fred Smith'), }).create(); -expectTypeOf(person4.get('firstName')).toEqualTypeOf(); -expectTypeOf(person4.get('fullName')).toEqualTypeOf(); +expectTypeOf(person4.firstName).toEqualTypeOf(); +expectTypeOf(person4.fullName).toEqualTypeOf(); diff --git a/type-tests/ember/controller.ts b/type-tests/ember/controller.ts index 7e89a8d8334..f68560e0d1e 100755 --- a/type-tests/ember/controller.ts +++ b/type-tests/ember/controller.ts @@ -1,4 +1,5 @@ import Ember from 'ember'; +import { set } from '@ember/object'; class MyController extends Ember.Controller { queryParams = ['category']; @@ -6,6 +7,6 @@ class MyController extends Ember.Controller { isExpanded = false; toggleBody() { - this.toggleProperty('isExpanded'); + set(this, 'isExpanded', !this.isExpanded); } } diff --git a/type-tests/ember/create.ts b/type-tests/ember/create.ts index 5846fd2b037..d566517e663 100755 --- a/type-tests/ember/create.ts +++ b/type-tests/ember/create.ts @@ -10,7 +10,6 @@ expectTypeOf(o).toBeObject(); // object returned by create type-checks as an instance of Ember.Object expectTypeOf(o.isDestroyed).toBeBoolean(); expectTypeOf(o.isDestroying).toBeBoolean(); -expectTypeOf(o.get).toMatchTypeOf<(key: K) => Ember.Object[K]>(); /** * One-argument case @@ -50,7 +49,6 @@ const p = Person.create(); expectTypeOf(p.firstName).toBeString(); expectTypeOf(p.fullName).toBeString(); -expectTypeOf(p.get('fullName')).toBeString(); Person.create({ firstName: 'string' }); Person.create({}, { firstName: 'string' }); diff --git a/type-tests/ember/ember-module-tests.ts b/type-tests/ember/ember-module-tests.ts index 219032d8a4f..7c58fdf675c 100644 --- a/type-tests/ember/ember-module-tests.ts +++ b/type-tests/ember/ember-module-tests.ts @@ -66,9 +66,6 @@ expectTypeOf(Ember.isPresent([])).toEqualTypeOf(); class O2 extends Ember.Object { name = 'foo'; age = 3; - - nameWatcher = Ember.observer('name', () => {}); - nameWatcher2 = Ember.observer('name', 'fullName', () => {}); } const o2 = O2.create({ name: 'foo', diff --git a/type-tests/ember/ember-tests.ts b/type-tests/ember/ember-tests.ts index 1439f1200f1..1c4ff79628a 100755 --- a/type-tests/ember/ember-tests.ts +++ b/type-tests/ember/ember-tests.ts @@ -11,7 +11,7 @@ class DetailedPresident extends President { lastName = 'Obama'; @Ember.computed() get fullName() { - return `${this.get('firstName')} ${this.get('lastName')}`; + return `${this.firstName} ${this.lastName}`; } } @@ -27,9 +27,7 @@ class MyApp extends Ember.Application { } const App = MyApp.create(); -App.country.get('presidentName'); App.president = DetailedPresident.create(); -App.president.get('fullName'); declare class MyPerson extends Ember.Object { static createMan(): MyPerson; @@ -51,14 +49,14 @@ MyPerson2.create().helloWorld(); class Tom extends Person1 { name = 'Tom Dale'; helloWorld() { - this.say('Hi my name is ' + this.get('name')); + this.say('Hi my name is ' + this.name); } } const tom = Tom.create(); tom.helloWorld(); const PersonReopened = Person1.reopen({ isPerson: true }); -PersonReopened.create().get('isPerson'); +Ember.get(PersonReopened.create(), 'isPerson'); class Todo extends Ember.Object { isDone = false; @@ -69,20 +67,19 @@ class TodosController extends Ember.Object { @Ember.computed('todos.@each.isDone') get remaining() { - const todos = this.get('todos'); - return todos.filter((todo) => todo.get('isDone') === false).length; + const todos = this.todos; + return todos.filter((todo) => todo.isDone === false).length; } } App.todosController = TodosController.create(); -const todos = App.todosController.get('todos'); +const todos = App.todosController.todos; let todo = todos[0]; -todo?.set('isDone', true); -App.todosController.get('remaining'); +App.todosController.remaining; todo = Todo.create({ isDone: true }); todos.push(todo); -App.todosController.get('remaining'); +App.todosController.remaining; const NormalApp = Ember.Application.create({ rootElement: '#sidebar', @@ -92,7 +89,7 @@ class Person2 extends Ember.Object { name = ''; sayHello() { - console.log('Hello from ' + this.get('name')); + console.log('Hello from ' + this.name); } } class Person3 extends Ember.Object { @@ -104,7 +101,7 @@ const people2 = [ Person3.create({ name: 'Majd', isHappy: false }), ]; const isHappy = (person: Person3): boolean => { - return Boolean(person.get('isHappy')); + return Boolean(person.isHappy); }; people2.every(isHappy); diff --git a/type-tests/ember/engine.ts b/type-tests/ember/engine.ts index f409fb708c4..6d22fd4b4af 100755 --- a/type-tests/ember/engine.ts +++ b/type-tests/ember/engine.ts @@ -18,7 +18,7 @@ BaseEngine.initializer({ BaseEngine.instanceInitializer({ name: 'my-instance-initializer', initialize(engine) { - (engine.lookup('foo:bar') as Obj).get('foo'); + (engine.lookup('foo:bar') as Obj).foo; }, }); diff --git a/type-tests/ember/event.ts b/type-tests/ember/event.ts index e34eb37e0c6..fa6664da0dd 100755 --- a/type-tests/ember/event.ts +++ b/type-tests/ember/event.ts @@ -1,13 +1,5 @@ import Ember from 'ember'; -function testObserver() { - Ember.Object.extend({ - valueObserver: Ember.observer('value', () => { - // Executes whenever the "value" property changes - }), - }); -} - function testListener() { class TestListener extends Ember.Component { init() { diff --git a/type-tests/ember/extend.ts b/type-tests/ember/extend.ts index a994fa39867..8786ff43e92 100755 --- a/type-tests/ember/extend.ts +++ b/type-tests/ember/extend.ts @@ -9,7 +9,7 @@ class Person extends Ember.Object { return `${this.firstName} ${this.lastName}`; } get fullName2(): string { - return `${this.get('firstName')} ${this.get('lastName')}`; + return `${this.firstName} ${this.lastName}`; } } diff --git a/type-tests/ember/helper.ts b/type-tests/ember/helper.ts index 2cfc4141a60..dbf5eb6a0e4 100755 --- a/type-tests/ember/helper.ts +++ b/type-tests/ember/helper.ts @@ -25,7 +25,7 @@ class CurrentUserEmailHelper extends Ember.Helper { declare session: SessionService; compute(): string { - return this.get('session').get('currentUser').get('email'); + return this.session.currentUser.email; } } diff --git a/type-tests/ember/inject.ts b/type-tests/ember/inject.ts index 4f7fdc9ae95..6a949dbbf8e 100755 --- a/type-tests/ember/inject.ts +++ b/type-tests/ember/inject.ts @@ -1,4 +1,5 @@ import Ember from 'ember'; +import { set } from '@ember/object'; import { expectTypeOf } from 'expect-type'; class AuthService extends Ember.Service { @@ -32,13 +33,13 @@ class LoginRoute extends Ember.Route { declare application: ApplicationController; didTransition() { - if (!this.get('auth').get('isAuthenticated')) { - this.get('application').transitionToLogin(); + if (!this.auth.isAuthenticated) { + this.application.transitionToLogin(); } } anyOldMethod() { - this.get('application').set('string', 'must be a string'); + set(this.application, 'string', 'must be a string'); expectTypeOf(this.controllerFor('emberApplication')).toEqualTypeOf(); } } @@ -67,8 +68,8 @@ class ComponentInjection extends Ember.Component { queryParams: { seriously: 'yes' }, }); expectTypeOf(url).toBeString(); - if (!this.get('auth').isAuthenticated) { - this.get('applicationController').transitionToLogin(); + if (!this.auth.isAuthenticated) { + this.applicationController.transitionToLogin(); } } } diff --git a/type-tests/ember/mixin.ts b/type-tests/ember/mixin.ts index 55176a725ce..fff1738ecdc 100755 --- a/type-tests/ember/mixin.ts +++ b/type-tests/ember/mixin.ts @@ -8,9 +8,9 @@ interface EditableMixin extends Ember.Mixin { const EditableMixin = Ember.Mixin.create({ edit(this: EditableMixin & Ember.Object) { - this.get('controller'); + Ember.get(this, 'controller'); console.log('starting to edit'); - this.set('isEditing', true); + Ember.set(this, 'isEditing', true); }, isEditing: false, }); diff --git a/type-tests/ember/object.ts b/type-tests/ember/object.ts index 9ae285df6a1..9f04968db3e 100755 --- a/type-tests/ember/object.ts +++ b/type-tests/ember/object.ts @@ -41,16 +41,7 @@ class Foo extends Ember.Object { baz() { this.b = 10; - expectTypeOf(this.get('b').toFixed(4)).toEqualTypeOf(); - expectTypeOf(this.set('a', 'abc').split(',')).toEqualTypeOf(); - expectTypeOf(this.set('b', 10).toFixed(4)).toEqualTypeOf(); - - this.setProperties({ b: 11 }); - // this.setProperties({ b: '11' }); // @ts-expect-error - this.setProperties({ - a: 'def', - b: 11, - }); + expectTypeOf(this.b.toFixed(4)).toEqualTypeOf(); } } @@ -60,17 +51,8 @@ export class Foo2 extends Ember.Object { changeName(name: string) { expectTypeOf(Ember.set(this, 'name', name)).toBeString(); - // For some reason, `this` type lookup does not resolve correctly here. Used - // outside a class, like `get(someFoo, 'name')`, this works correctly. Since - // there are basically no cases inside a class where you *have* to use `get` - // today, this is an acceptable workaround for now. It is assignable *or* - // castable. - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const s: string = this.get('name'); expectTypeOf(Ember.get(this as Foo2, 'name')).toBeString(); - expectTypeOf((this as Foo2).get('name')).toBeString(); - expectTypeOf(this.setProperties({ name })).toEqualTypeOf<{ name: string }>(); expectTypeOf(Ember.setProperties(this, { name })).toEqualTypeOf<{ name: string }>(); } diff --git a/type-tests/ember/observable.ts b/type-tests/ember/observable.ts index 88fc7634aff..199d79c65d0 100755 --- a/type-tests/ember/observable.ts +++ b/type-tests/ember/observable.ts @@ -6,19 +6,13 @@ class MyComponent extends Ember.Component { init() { this._super(); - this.addObserver('foo', this, 'fooDidChange'); - this.addObserver('foo', this, this.fooDidChange); Ember.addObserver(this, 'foo', this, 'fooDidChange'); Ember.addObserver(this, 'foo', this, this.fooDidChange); - this.removeObserver('foo', this, 'fooDidChange'); - this.removeObserver('foo', this, this.fooDidChange); Ember.removeObserver(this, 'foo', this, 'fooDidChange'); Ember.removeObserver(this, 'foo', this, this.fooDidChange); const lambda = () => { this.fooDidChange(this, 'foo'); }; - this.addObserver('foo', lambda); - this.removeObserver('foo', lambda); Ember.addObserver(this, 'foo', lambda); Ember.removeObserver(this, 'foo', lambda); } @@ -33,18 +27,13 @@ class MyComponent extends Ember.Component { } } -const myComponent = MyComponent.create(); -myComponent.addObserver('foo', null, () => {}); -myComponent.set('foo', 'baz'); -expectTypeOf(myComponent.get('foo')).toEqualTypeOf(); - class Person extends Ember.Object { name = ''; age = 0; @Ember.computed() get capitalized() { - return this.get('name').toUpperCase(); + return this.name.toUpperCase(); } } const person = Person.create({ @@ -58,9 +47,6 @@ function testGet() { expectTypeOf(Ember.get(person, 'name')).toEqualTypeOf(); expectTypeOf(Ember.get(person, 'age')).toEqualTypeOf(); expectTypeOf(Ember.get(person, 'capitalized')).toEqualTypeOf(); - expectTypeOf(person.get('name')).toEqualTypeOf(); - expectTypeOf(person.get('age')).toEqualTypeOf(); - expectTypeOf(person.get('capitalized')).toEqualTypeOf(); expectTypeOf(Ember.get(pojo, 'name')).toEqualTypeOf(); } @@ -77,17 +63,6 @@ function testGetProperties() { expectTypeOf(Ember.getProperties(person, 'name', 'age', 'capitalized')).toEqualTypeOf< Pick >(); - expectTypeOf(person.getProperties('name')).toEqualTypeOf<{ name: string }>(); - expectTypeOf(person.getProperties('name', 'age')).toEqualTypeOf<{ name: string; age: number }>(); - expectTypeOf(person.getProperties(['name', 'age'])).toEqualTypeOf<{ - name: string; - age: number; - }>(); - expectTypeOf(person.getProperties('name', 'age', 'capitalized')).toEqualTypeOf<{ - name: string; - age: number; - capitalized: string; - }>(); expectTypeOf(Ember.getProperties(pojo, 'name', 'age')).toEqualTypeOf< Pick >(); @@ -97,9 +72,6 @@ function testSet() { expectTypeOf(Ember.set(person, 'name', 'Joe')).toBeString(); expectTypeOf(Ember.set(person, 'age', 35)).toBeNumber(); expectTypeOf(Ember.set(person, 'capitalized', 'JOE')).toBeString(); - expectTypeOf(person.set('name', 'Joe')).toBeString(); - expectTypeOf(person.set('age', 35)).toBeNumber(); - expectTypeOf(person.set('capitalized', 'JOE')).toBeString(); expectTypeOf(Ember.set(pojo, 'name', 'Joe')).toBeString(); } @@ -112,14 +84,6 @@ function testSetProperties() { expectTypeOf(Ember.setProperties(person, { name: 'Joe', capitalized: 'JOE' })).toEqualTypeOf< Pick >(); - expectTypeOf(person.setProperties({ name: 'Joe' })).toEqualTypeOf>(); - expectTypeOf(person.setProperties({ name: 'Joe', age: 35 })).toEqualTypeOf< - Pick - >(); - expectTypeOf(person.setProperties({ name: 'Joe', capitalized: 'JOE' })).toEqualTypeOf<{ - name: string; - capitalized: string; - }>(); expectTypeOf(Ember.setProperties(pojo, { name: 'Joe', age: 35 })).toEqualTypeOf< Pick >(); diff --git a/type-tests/ember/private/computed-tests.ts b/type-tests/ember/private/computed-tests.ts index 7a5448faa93..e4adebf72e6 100644 --- a/type-tests/ember/private/computed-tests.ts +++ b/type-tests/ember/private/computed-tests.ts @@ -15,12 +15,3 @@ class Example1 extends Ember.Object { return `${this.firstName} ${this.lastName}`; } } - -class Example2 extends Example1 { - foo() { - expectTypeOf(this.get('fullName').split(',')).toEqualTypeOf(); - expectTypeOf(this.get('allNames')[0]).toEqualTypeOf(); - expectTypeOf(this.get('firstName').split(',')).toEqualTypeOf(); - expectTypeOf(this.get('lastName').split(',')).toEqualTypeOf(); - } -} diff --git a/type-tests/ember/reopen.ts b/type-tests/ember/reopen.ts index a4cf4673dcf..b3e68e9c317 100755 --- a/type-tests/ember/reopen.ts +++ b/type-tests/ember/reopen.ts @@ -5,7 +5,7 @@ class Person extends Ember.Object { name = ''; sayHello() { - alert(`Hello. My name is ${this.get('name')}`); + alert(`Hello. My name is ${Ember.get(this, 'name')}`); } } @@ -52,13 +52,13 @@ const Person3 = Person2.reopen({ goodbyeMessage: 'goodbye', sayGoodbye(this: Person) { - alert(`${this.get('goodbyeMessage')}, ${this.get('name')}`); + alert(`${Ember.get(this, 'goodbyeMessage')}, ${Ember.get(this, 'name')}`); }, }); const person3 = Person3.create(); -person3.get('name'); -person3.get('goodbyeMessage'); +Ember.get(person3, 'name'); +Ember.get(person3, 'goodbyeMessage'); person3.sayHello(); // @ts-expect-error person3.sayGoodbye(); diff --git a/type-tests/ember/route.ts b/type-tests/ember/route.ts index 7e3bcf0e155..b065ecee2c1 100755 --- a/type-tests/ember/route.ts +++ b/type-tests/ember/route.ts @@ -1,6 +1,7 @@ import Route from '@ember/routing/route'; import Array from '@ember/array'; import Ember from 'ember'; // currently needed for Transition +import { set } from '@ember/object'; import type Transition from '@ember/routing/transition'; import { expectTypeOf } from 'expect-type'; import { service } from '@ember/service'; @@ -38,7 +39,7 @@ class Test extends Route { setupController(controller: Ember.Controller, model: {}) { this._super(controller, model); - this.controllerFor('application').set('model', model); + set(this.controllerFor('application'), 'model', model); } resetController(controller: Ember.Controller, isExiting: boolean, transition: Transition) {