diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1dfe1e05f3c..d9f73ef7baa 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -6,6 +6,7 @@ on:
- main
- beta
- release
+ - next
# release branches
- release*
- lts*
@@ -238,8 +239,8 @@ jobs:
blueprint-test,
browser-test,
]
- # Only run on pushes to branches that are not from the cron workflow
- if: github.event_name == 'push' && contains(github.ref, 'cron') != true
+ # Only run on pushes to branches that are not from the cron workflow or the next branch
+ if: github.event_name == 'push' && contains(github.ref, 'cron') != true && contains(github.ref, 'next') != true
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
diff --git a/broccoli/amd-compat-entrypoints/ember.debug.js b/broccoli/amd-compat-entrypoints/ember.debug.js
index c4ac39d47b3..68e0107aaae 100644
--- a/broccoli/amd-compat-entrypoints/ember.debug.js
+++ b/broccoli/amd-compat-entrypoints/ember.debug.js
@@ -56,36 +56,6 @@ d('@ember/-internals/runtime/index', emberinternalsRuntimeIndex);
import * as emberinternalsRuntimeLibExtRsvp from '@ember/-internals/runtime/lib/ext/rsvp';
d('@ember/-internals/runtime/lib/ext/rsvp', emberinternalsRuntimeLibExtRsvp);
-import * as emberinternalsRuntimeLibMixinsproxy from '@ember/-internals/runtime/lib/mixins/-proxy';
-d('@ember/-internals/runtime/lib/mixins/-proxy', emberinternalsRuntimeLibMixinsproxy);
-
-import * as emberinternalsRuntimeLibMixinsActionHandler from '@ember/-internals/runtime/lib/mixins/action_handler';
-d(
- '@ember/-internals/runtime/lib/mixins/action_handler',
- emberinternalsRuntimeLibMixinsActionHandler
-);
-
-import * as emberinternalsRuntimeLibMixinsComparable from '@ember/-internals/runtime/lib/mixins/comparable';
-d('@ember/-internals/runtime/lib/mixins/comparable', emberinternalsRuntimeLibMixinsComparable);
-
-import * as emberinternalsRuntimeLibMixinsContainerProxy from '@ember/-internals/runtime/lib/mixins/container_proxy';
-d(
- '@ember/-internals/runtime/lib/mixins/container_proxy',
- emberinternalsRuntimeLibMixinsContainerProxy
-);
-
-import * as emberinternalsRuntimeLibMixinsRegistryProxy from '@ember/-internals/runtime/lib/mixins/registry_proxy';
-d(
- '@ember/-internals/runtime/lib/mixins/registry_proxy',
- emberinternalsRuntimeLibMixinsRegistryProxy
-);
-
-import * as emberinternalsRuntimeLibMixinsTargetActionSupport from '@ember/-internals/runtime/lib/mixins/target_action_support';
-d(
- '@ember/-internals/runtime/lib/mixins/target_action_support',
- emberinternalsRuntimeLibMixinsTargetActionSupport
-);
-
import * as emberinternalsStringIndex from '@ember/-internals/string/index';
d('@ember/-internals/string/index', emberinternalsStringIndex);
@@ -110,9 +80,6 @@ d(
import * as emberinternalsViewsLibComponentLookup from '@ember/-internals/views/lib/component_lookup';
d('@ember/-internals/views/lib/component_lookup', emberinternalsViewsLibComponentLookup);
-import * as emberinternalsViewsLibMixinsActionSupport from '@ember/-internals/views/lib/mixins/action_support';
-d('@ember/-internals/views/lib/mixins/action_support', emberinternalsViewsLibMixinsActionSupport);
-
import * as emberinternalsViewsLibSystemActionManager from '@ember/-internals/views/lib/system/action_manager';
d('@ember/-internals/views/lib/system/action_manager', emberinternalsViewsLibSystemActionManager);
@@ -143,21 +110,12 @@ d('@ember/application/lib/lazy_load', emberApplicationLibLazyLoad);
import * as emberApplicationNamespace from '@ember/application/namespace';
d('@ember/application/namespace', emberApplicationNamespace);
-import * as emberArrayinternals from '@ember/array/-internals';
-d('@ember/array/-internals', emberArrayinternals);
-
import * as emberArrayIndex from '@ember/array/index';
d('@ember/array/index', emberArrayIndex);
import * as emberArrayLibMakeArray from '@ember/array/lib/make-array';
d('@ember/array/lib/make-array', emberArrayLibMakeArray);
-import * as emberArrayMutable from '@ember/array/mutable';
-d('@ember/array/mutable', emberArrayMutable);
-
-import * as emberArrayProxy from '@ember/array/proxy';
-d('@ember/array/proxy', emberArrayProxy);
-
import * as emberCanaryFeaturesIndex from '@ember/canary-features/index';
d('@ember/canary-features/index', emberCanaryFeaturesIndex);
@@ -215,12 +173,6 @@ d('@ember/engine/instance', emberEngineInstance);
import * as emberEngineLibEngineParent from '@ember/engine/lib/engine-parent';
d('@ember/engine/lib/engine-parent', emberEngineLibEngineParent);
-import * as emberEnumerableIndex from '@ember/enumerable/index';
-d('@ember/enumerable/index', emberEnumerableIndex);
-
-import * as emberEnumerableMutable from '@ember/enumerable/mutable';
-d('@ember/enumerable/mutable', emberEnumerableMutable);
-
import * as emberHelperIndex from '@ember/helper/index';
d('@ember/helper/index', emberHelperIndex);
@@ -242,12 +194,6 @@ d('@ember/object/computed', emberObjectComputed);
import * as emberObjectCore from '@ember/object/core';
d('@ember/object/core', emberObjectCore);
-import * as emberObjectEvented from '@ember/object/evented';
-d('@ember/object/evented', emberObjectEvented);
-
-import * as emberObjectEvents from '@ember/object/events';
-d('@ember/object/events', emberObjectEvents);
-
import * as emberObjectIndex from '@ember/object/index';
d('@ember/object/index', emberObjectIndex);
@@ -257,24 +203,12 @@ d('@ember/object/internals', emberObjectInternals);
import * as emberObjectLibComputedComputedMacros from '@ember/object/lib/computed/computed_macros';
d('@ember/object/lib/computed/computed_macros', emberObjectLibComputedComputedMacros);
-import * as emberObjectLibComputedReduceComputedMacros from '@ember/object/lib/computed/reduce_computed_macros';
-d('@ember/object/lib/computed/reduce_computed_macros', emberObjectLibComputedReduceComputedMacros);
-
import * as emberObjectMixin from '@ember/object/mixin';
d('@ember/object/mixin', emberObjectMixin);
-import * as emberObjectObservable from '@ember/object/observable';
-d('@ember/object/observable', emberObjectObservable);
-
import * as emberObjectObservers from '@ember/object/observers';
d('@ember/object/observers', emberObjectObservers);
-import * as emberObjectPromiseProxyMixin from '@ember/object/promise-proxy-mixin';
-d('@ember/object/promise-proxy-mixin', emberObjectPromiseProxyMixin);
-
-import * as emberObjectProxy from '@ember/object/proxy';
-d('@ember/object/proxy', emberObjectProxy);
-
import * as emberOwnerIndex from '@ember/owner/index';
d('@ember/owner/index', emberOwnerIndex);
diff --git a/package.json b/package.json
index 11c120a0c3f..7d187e03c16 100644
--- a/package.json
+++ b/package.json
@@ -99,12 +99,14 @@
"ember-cli-typescript-blueprint-polyfill": "^0.1.0",
"ember-cli-version-checker": "^5.1.2",
"ember-router-generator": "^2.0.0",
+ "ember-tracked-storage-polyfill": "^1.0.0",
"inflection": "^2.0.1",
"route-recognizer": "^0.3.4",
"router_js": "^8.0.5",
"semver": "^7.5.2",
"silent-error": "^1.1.1",
- "simple-html-tokenizer": "^0.5.11"
+ "simple-html-tokenizer": "^0.5.11",
+ "tracked-built-ins": "^4.0.0"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.731.0",
@@ -209,12 +211,6 @@
"@ember/-internals/routing/index.js": "ember-source/@ember/-internals/routing/index.js",
"@ember/-internals/runtime/index.js": "ember-source/@ember/-internals/runtime/index.js",
"@ember/-internals/runtime/lib/ext/rsvp.js": "ember-source/@ember/-internals/runtime/lib/ext/rsvp.js",
- "@ember/-internals/runtime/lib/mixins/-proxy.js": "ember-source/@ember/-internals/runtime/lib/mixins/-proxy.js",
- "@ember/-internals/runtime/lib/mixins/action_handler.js": "ember-source/@ember/-internals/runtime/lib/mixins/action_handler.js",
- "@ember/-internals/runtime/lib/mixins/comparable.js": "ember-source/@ember/-internals/runtime/lib/mixins/comparable.js",
- "@ember/-internals/runtime/lib/mixins/container_proxy.js": "ember-source/@ember/-internals/runtime/lib/mixins/container_proxy.js",
- "@ember/-internals/runtime/lib/mixins/registry_proxy.js": "ember-source/@ember/-internals/runtime/lib/mixins/registry_proxy.js",
- "@ember/-internals/runtime/lib/mixins/target_action_support.js": "ember-source/@ember/-internals/runtime/lib/mixins/target_action_support.js",
"@ember/-internals/string/index.js": "ember-source/@ember/-internals/string/index.js",
"@ember/-internals/utility-types/index.js": "ember-source/@ember/-internals/utility-types/index.js",
"@ember/-internals/utils/index.js": "ember-source/@ember/-internals/utils/index.js",
@@ -222,7 +218,6 @@
"@ember/-internals/views/lib/compat/attrs.js": "ember-source/@ember/-internals/views/lib/compat/attrs.js",
"@ember/-internals/views/lib/compat/fallback-view-registry.js": "ember-source/@ember/-internals/views/lib/compat/fallback-view-registry.js",
"@ember/-internals/views/lib/component_lookup.js": "ember-source/@ember/-internals/views/lib/component_lookup.js",
- "@ember/-internals/views/lib/mixins/action_support.js": "ember-source/@ember/-internals/views/lib/mixins/action_support.js",
"@ember/-internals/views/lib/system/action_manager.js": "ember-source/@ember/-internals/views/lib/system/action_manager.js",
"@ember/-internals/views/lib/system/event_dispatcher.js": "ember-source/@ember/-internals/views/lib/system/event_dispatcher.js",
"@ember/-internals/views/lib/system/utils.js": "ember-source/@ember/-internals/views/lib/system/utils.js",
@@ -232,12 +227,9 @@
"@ember/application/instance.js": "ember-source/@ember/application/instance.js",
"@ember/application/lib/lazy_load.js": "ember-source/@ember/application/lib/lazy_load.js",
"@ember/application/namespace.js": "ember-source/@ember/application/namespace.js",
- "@ember/array/-internals.js": "ember-source/@ember/array/-internals.js",
"@ember/array/index.js": "ember-source/@ember/array/index.js",
"@ember/array/lib/make-array.js": "ember-source/@ember/array/lib/make-array.js",
"@ember/array/make.js": "ember-source/@ember/array/make.js",
- "@ember/array/mutable.js": "ember-source/@ember/array/mutable.js",
- "@ember/array/proxy.js": "ember-source/@ember/array/proxy.js",
"@ember/canary-features/index.js": "ember-source/@ember/canary-features/index.js",
"@ember/component/helper.js": "ember-source/@ember/component/helper.js",
"@ember/component/index.js": "ember-source/@ember/component/index.js",
@@ -259,8 +251,6 @@
"@ember/engine/instance.js": "ember-source/@ember/engine/instance.js",
"@ember/engine/lib/engine-parent.js": "ember-source/@ember/engine/lib/engine-parent.js",
"@ember/engine/parent.js": "ember-source/@ember/engine/parent.js",
- "@ember/enumerable/index.js": "ember-source/@ember/enumerable/index.js",
- "@ember/enumerable/mutable.js": "ember-source/@ember/enumerable/mutable.js",
"@ember/helper/index.js": "ember-source/@ember/helper/index.js",
"@ember/instrumentation/index.js": "ember-source/@ember/instrumentation/index.js",
"@ember/modifier/index.js": "ember-source/@ember/modifier/index.js",
@@ -269,17 +259,12 @@
"@ember/object/compat.js": "ember-source/@ember/object/compat.js",
"@ember/object/computed.js": "ember-source/@ember/object/computed.js",
"@ember/object/core.js": "ember-source/@ember/object/core.js",
- "@ember/object/evented.js": "ember-source/@ember/object/evented.js",
- "@ember/object/events.js": "ember-source/@ember/object/events.js",
"@ember/object/index.js": "ember-source/@ember/object/index.js",
"@ember/object/internals.js": "ember-source/@ember/object/internals.js",
"@ember/object/lib/computed/computed_macros.js": "ember-source/@ember/object/lib/computed/computed_macros.js",
"@ember/object/lib/computed/reduce_computed_macros.js": "ember-source/@ember/object/lib/computed/reduce_computed_macros.js",
"@ember/object/mixin.js": "ember-source/@ember/object/mixin.js",
- "@ember/object/observable.js": "ember-source/@ember/object/observable.js",
"@ember/object/observers.js": "ember-source/@ember/object/observers.js",
- "@ember/object/promise-proxy-mixin.js": "ember-source/@ember/object/promise-proxy-mixin.js",
- "@ember/object/proxy.js": "ember-source/@ember/object/proxy.js",
"@ember/owner/index.js": "ember-source/@ember/owner/index.js",
"@ember/renderer/index.js": "ember-source/@ember/renderer/index.js",
"@ember/routing/-internals.js": "ember-source/@ember/routing/-internals.js",
@@ -388,7 +373,8 @@
"ember/version.js": "ember-source/ember/version.js",
"route-recognizer/index.js": "ember-source/route-recognizer/index.js",
"router_js/index.js": "ember-source/router_js/index.js",
- "rsvp/index.js": "ember-source/rsvp/index.js"
+ "rsvp/index.js": "ember-source/rsvp/index.js",
+ "tracked-built-ins/index.js": "ember-source/tracked-built-ins/index.js"
}
},
"typesVersions": {
@@ -402,4 +388,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 0b0da6ec97d..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');
@@ -239,7 +240,7 @@ export default class CurlyComponentManager
/*
* This hook is responsible for actually instantiating the component instance.
* It also is where we perform additional bookkeeping to support legacy
- * features like exposed by view mixins like ChildViewSupport, ActionSupport,
+ * features like exposed by view mixins like ChildViewSupport,
* etc.
*/
create(
@@ -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 e106e05157a..606576970e6 100644
--- a/packages/@ember/-internals/glimmer/lib/component.ts
+++ b/packages/@ember/-internals/glimmer/lib/component.ts
@@ -7,10 +7,8 @@ import {
} from '@ember/-internals/metal';
import type { PropertyDidChange } from '@ember/-internals/metal/lib/property_events';
import { getOwner } from '@ember/-internals/owner';
-import { TargetActionSupport } from '@ember/-internals/runtime';
import type { ViewStates } from '@ember/-internals/views';
import {
- ActionSupport,
addChildView,
CoreView,
EventDispatcher,
@@ -61,150 +59,6 @@ function matches(el: Element, selector: string): boolean {
@module @ember/component
*/
-interface ComponentMethods {
- // Overrideable methods are defined here since you can't `declare` a method in a class
-
- /**
- Called when the attributes passed into the component have been updated.
- Called both during the initial render of a container and during a rerender.
- Can be used in place of an observer; code placed here will be executed
- every time any attribute updates.
- @method didReceiveAttrs
- @public
- @since 1.13.0
- */
- didReceiveAttrs(): void;
-
- /**
- Called when the attributes passed into the component have been updated.
- Called both during the initial render of a container and during a rerender.
- Can be used in place of an observer; code placed here will be executed
- every time any attribute updates.
- @event didReceiveAttrs
- @public
- @since 1.13.0
- */
-
- /**
- Called after a component has been rendered, both on initial render and
- in subsequent rerenders.
- @method didRender
- @public
- @since 1.13.0
- */
- didRender(): void;
-
- /**
- Called after a component has been rendered, both on initial render and
- in subsequent rerenders.
- @event didRender
- @public
- @since 1.13.0
- */
-
- /**
- Called before a component has been rendered, both on initial render and
- in subsequent rerenders.
- @method willRender
- @public
- @since 1.13.0
- */
- willRender(): void;
-
- /**
- Called before a component has been rendered, both on initial render and
- in subsequent rerenders.
- @event willRender
- @public
- @since 1.13.0
- */
-
- /**
- Called when the attributes passed into the component have been changed.
- Called only during a rerender, not during an initial render.
- @method didUpdateAttrs
- @public
- @since 1.13.0
- */
- didUpdateAttrs(): void;
-
- /**
- Called when the attributes passed into the component have been changed.
- Called only during a rerender, not during an initial render.
- @event didUpdateAttrs
- @public
- @since 1.13.0
- */
-
- /**
- Called when the component is about to update and rerender itself.
- Called only during a rerender, not during an initial render.
- @method willUpdate
- @public
- @since 1.13.0
- */
- willUpdate(): void;
-
- /**
- Called when the component is about to update and rerender itself.
- Called only during a rerender, not during an initial render.
- @event willUpdate
- @public
- @since 1.13.0
- */
-
- /**
- Called when the component has updated and rerendered itself.
- Called only during a rerender, not during an initial render.
- @method didUpdate
- @public
- @since 1.13.0
- */
- didUpdate(): void;
-
- /**
- Called when the component has updated and rerendered itself.
- Called only during a rerender, not during an initial render.
- @event didUpdate
- @public
- @since 1.13.0
- */
-
- /**
- The HTML `id` of the component's element in the DOM. You can provide this
- value yourself but it must be unique (just as in HTML):
-
- ```handlebars
- {{my-component elementId="a-really-cool-id"}}
- ```
-
- ```handlebars
-
- ```
- If not manually set a default value will be provided by the framework.
- Once rendered an element's `elementId` is considered immutable and you
- should never change it. If you need to compute a dynamic value for the
- `elementId`, you should do this when the component or element is being
- instantiated:
-
- ```javascript
- export default class extends Component {
- init() {
- super.init(...arguments);
-
- var index = this.get('index');
- this.set('elementId', `component-id${index}`);
- }
- }
- ```
-
- @property elementId
- @type String
- @public
- */
- layoutName?: string;
-}
-
// A zero-runtime-overhead private symbol to use in branding the component to
// preserve its type parameter.
declare const SIGNATURE: unique symbol;
@@ -414,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
});
}
@@ -789,38 +643,14 @@ declare const SIGNATURE: unique symbol;
@class Component
@extends Ember.CoreView
- @uses Ember.TargetActionSupport
- @uses Ember.ActionSupport
@public
*/
-// This type param is used in the class, so must appear here.
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-interface Component
- extends CoreView,
- TargetActionSupport,
- ActionSupport,
- ComponentMethods {}
-
class Component
- extends CoreView.extend(
- TargetActionSupport,
- ActionSupport,
- {
- // These need to be overridable via extend/create but should still
- // have a default. Defining them here is the best way to achieve that.
- didReceiveAttrs() {},
- didRender() {},
- didUpdate() {},
- didUpdateAttrs() {},
- willRender() {},
- willUpdate() {},
- } as ComponentMethods,
- {
- concatenatedProperties: ['attributeBindings', 'classNames', 'classNameBindings'],
- classNames: EMPTY_ARRAY,
- classNameBindings: EMPTY_ARRAY,
- }
- )
+ extends CoreView.extend({
+ concatenatedProperties: ['attributeBindings', 'classNames', 'classNameBindings'],
+ classNames: EMPTY_ARRAY,
+ classNameBindings: EMPTY_ARRAY,
+ })
implements PropertyDidChange
{
isComponent = true;
@@ -1016,20 +846,6 @@ class Component
return this.__dispatcher;
}
- on(
- name: string,
- target: Target,
- method: string | ((this: Target, ...args: any[]) => void)
- ): this;
- on(name: string, method: ((...args: any[]) => void) | string): this;
- on(name: string, target: any, method?: any) {
- this._dispatcher?.setupHandlerForEmberEvent(name);
- // The `on` method here comes from the Evented mixin. Since this mixin
- // is applied to the parent of this class, however, we are still able
- // to use `super`.
- return super.on(name, target, method);
- }
-
// Changed to `rerender` on init
_rerender() {
dirtyTag(this[DIRTY_TAG]);
@@ -1051,7 +867,7 @@ class Component
getAttr(key: string) {
// TODO Intimate API should be deprecated
- return this.get(key);
+ return get(this, key);
}
/**
@@ -1681,6 +1497,98 @@ class Component
// End ViewMixin
+ // Begin lifecycle hooks
+
+ /**
+ Called when the attributes passed into the component have been updated.
+ Called both during the initial render of a container and during a rerender.
+ Can be used in place of an observer; code placed here will be executed
+ every time any attribute updates.
+ @method didReceiveAttrs
+ @public
+ @since 1.13.0
+ */
+ didReceiveAttrs(): void {}
+
+ /**
+ Called after a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @method didRender
+ @public
+ @since 1.13.0
+ */
+ didRender(): void {}
+
+ /**
+ Called after a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @event didRender
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called before a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @method willRender
+ @public
+ @since 1.13.0
+ */
+ willRender(): void {}
+
+ /**
+ Called before a component has been rendered, both on initial render and
+ in subsequent rerenders.
+ @event willRender
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the attributes passed into the component have been changed.
+ Called only during a rerender, not during an initial render.
+ @method didUpdateAttrs
+ @public
+ @since 1.13.0
+ */
+ didUpdateAttrs(): void {}
+
+ /**
+ Called when the attributes passed into the component have been changed.
+ Called only during a rerender, not during an initial render.
+ @event didUpdateAttrs
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the component is about to update and rerender itself.
+ Called only during a rerender, not during an initial render.
+ @method willUpdate
+ @public
+ @since 1.13.0
+ */
+ willUpdate(): void {}
+
+ /**
+ Called when the component is about to update and rerender itself.
+ Called only during a rerender, not during an initial render.
+ @event willUpdate
+ @public
+ @since 1.13.0
+ */
+
+ /**
+ Called when the component has updated and rerendered itself.
+ Called only during a rerender, not during an initial render.
+ @method didUpdate
+ @public
+ @since 1.13.0
+ */
+ didUpdate(): void {}
+
+ // End lifecycle hooks
+
static isComponentFactory = true;
static toString() {
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/each-in.ts b/packages/@ember/-internals/glimmer/lib/helpers/each-in.ts
index 682d71b7c8a..c43a9072b3c 100644
--- a/packages/@ember/-internals/glimmer/lib/helpers/each-in.ts
+++ b/packages/@ember/-internals/glimmer/lib/helpers/each-in.ts
@@ -2,8 +2,6 @@
@module ember
*/
import { tagForObject } from '@ember/-internals/metal';
-import { _contentFor } from '@ember/-internals/runtime';
-import { isProxy } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import type { CapturedArguments } from '@glimmer/interfaces';
import { createComputeRef, valueForRef } from '@glimmer/reference';
@@ -176,12 +174,6 @@ export default internalHelper(({ positional }: CapturedArguments) => {
consumeTag(tagForObject(iterable));
- if (isProxy(iterable)) {
- // this is because the each-in doesn't actually get(proxy, 'key') but bypasses it
- // and the proxy's tag is lazy updated on access
- iterable = _contentFor(iterable);
- }
-
return new EachInWrapper(iterable);
});
});
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/lib/utils/iterator.ts b/packages/@ember/-internals/glimmer/lib/utils/iterator.ts
index 34e3c512d64..927e90fadf8 100644
--- a/packages/@ember/-internals/glimmer/lib/utils/iterator.ts
+++ b/packages/@ember/-internals/glimmer/lib/utils/iterator.ts
@@ -1,12 +1,8 @@
-import { objectAt } from '@ember/-internals/metal';
-import type EmberArray from '@ember/array';
-import { isEmberArray } from '@ember/array/-internals';
import { isObject } from '@ember/-internals/utils';
import type { Nullable } from '@ember/-internals/utility-types';
import type { IteratorDelegate } from '@glimmer/reference';
import { consumeTag, isTracking, tagFor } from '@glimmer/validator';
import { EachInWrapper } from '../helpers/each-in';
-import type { NativeArray } from '@ember/array';
export default function toIterator(iterable: unknown): Nullable {
if (iterable instanceof EachInWrapper) {
@@ -21,7 +17,7 @@ function toEachInIterator(iterable: unknown) {
return null;
}
- if (Array.isArray(iterable) || isEmberArray(iterable)) {
+ if (Array.isArray(iterable)) {
return ObjectIterator.fromIndexable(iterable);
} else if (isNativeIterable(iterable)) {
return MapLikeNativeIterator.from(iterable as Iterable<[unknown, unknown]>);
@@ -39,8 +35,6 @@ function toEachIterator(iterable: unknown) {
if (Array.isArray(iterable)) {
return ArrayIterator.from(iterable);
- } else if (isEmberArray(iterable)) {
- return EmberArrayIterator.from(iterable);
} else if (isNativeIterable(iterable)) {
return ArrayLikeNativeIterator.from(iterable);
} else if (hasForEach(iterable)) {
@@ -101,20 +95,6 @@ class ArrayIterator extends BoundedIterator {
}
}
-class EmberArrayIterator extends BoundedIterator {
- static from(iterable: EmberArray | NativeArray) {
- return iterable.length > 0 ? new this(iterable) : null;
- }
-
- constructor(private array: EmberArray | NativeArray) {
- super(array.length);
- }
-
- valueFor(position: number): unknown {
- return objectAt(this.array as any, position);
- }
-}
-
class ObjectIterator extends BoundedIterator {
static fromIndexable(obj: Indexable) {
let keys = Object.keys(obj);
diff --git a/packages/@ember/-internals/glimmer/lib/utils/to-bool.ts b/packages/@ember/-internals/glimmer/lib/utils/to-bool.ts
index a17bdd505f7..0078aac18dd 100644
--- a/packages/@ember/-internals/glimmer/lib/utils/to-bool.ts
+++ b/packages/@ember/-internals/glimmer/lib/utils/to-bool.ts
@@ -1,15 +1,10 @@
import { isHTMLSafe } from './string';
-import { get, tagForProperty } from '@ember/-internals/metal';
+import { tagForProperty } from '@ember/-internals/metal';
import { isArray } from '@ember/array';
-import { isProxy } from '@ember/-internals/utils';
import { consumeTag } from '@glimmer/validator';
export default function toBool(predicate: unknown): boolean {
- if (isProxy(predicate)) {
- consumeTag(tagForProperty(predicate, 'content'));
-
- return Boolean(get(predicate, 'isTruthy'));
- } else if (isArray(predicate)) {
+ if (isArray(predicate)) {
consumeTag(tagForProperty(predicate as object, '[]'));
return (predicate as { length: number }).length !== 0;
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/append-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/append-test.js
index 3e89c2297a3..281dc29003e 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/components/append-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/components/append-test.js
@@ -56,7 +56,6 @@ class AbstractAppendTest extends RenderingTestCase {
}
componentsByName[name] = this;
pushHook('init');
- this.on('init', () => pushHook('on(init)'));
}
didReceiveAttrs() {
@@ -148,12 +147,10 @@ class AbstractAppendTest extends RenderingTestCase {
hooks,
[
['x-parent', 'init'],
- ['x-parent', 'on(init)'],
['x-parent', 'didReceiveAttrs'],
['x-parent', 'willRender'],
['x-parent', 'willInsertElement'],
['x-child', 'init'],
- ['x-child', 'on(init)'],
['x-child', 'didReceiveAttrs'],
['x-child', 'willRender'],
['x-child', 'willInsertElement'],
@@ -299,7 +296,6 @@ class AbstractAppendTest extends RenderingTestCase {
}
componentsByName[name] = this;
pushHook('init');
- this.on('init', () => pushHook('on(init)'));
}
didReceiveAttrs() {
@@ -380,14 +376,7 @@ class AbstractAppendTest extends RenderingTestCase {
this.component = XParent.create({ foo: 'zomg' });
- assert.deepEqual(
- hooks,
- [
- ['x-parent', 'init'],
- ['x-parent', 'on(init)'],
- ],
- 'creation of x-parent'
- );
+ assert.deepEqual(hooks, [['x-parent', 'init']], 'creation of x-parent');
hooks.length = 0;
@@ -399,7 +388,6 @@ class AbstractAppendTest extends RenderingTestCase {
['x-parent', 'willInsertElement'],
['x-child', 'init'],
- ['x-child', 'on(init)'],
['x-child', 'didReceiveAttrs'],
['x-child', 'willRender'],
['x-child', 'willInsertElement'],
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 ffc53313e27..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,11 +2,12 @@ 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 { A as emberA } from '@ember/array';
+import { action, get, set } from '@ember/object';
import { Component } from '../../utils/helpers';
+import { tracked } from 'tracked-built-ins';
+
moduleFor(
'Components test: contextual components',
class extends RenderingTestCase {
@@ -65,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');
}
@@ -103,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 ');
}
@@ -140,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');
}
@@ -177,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 ');
}
@@ -230,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');
}
@@ -256,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');
}
@@ -288,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');
}
@@ -358,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');
}
@@ -398,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,
});
@@ -444,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,
});
@@ -484,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');
}
@@ -507,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('');
}
@@ -530,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');
}
@@ -553,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('');
}
@@ -576,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');
}
@@ -651,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);
}
@@ -684,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);
}
@@ -721,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`);
}
@@ -763,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}}',
@@ -778,7 +779,7 @@ moduleFor(
ComponentClass: class extends Component {
@action
changeValue() {
- this.incrementProperty('myProp');
+ set(this, 'myProp', this.myProp + 1);
}
},
template: strip`
@@ -809,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');
}
@@ -872,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');
}
@@ -897,7 +898,7 @@ moduleFor(
message = 'hello';
@action
change() {
- this.set('message', 'goodbye');
+ set(this, 'message', 'goodbye');
}
},
template: strip`
@@ -968,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');
@@ -982,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');
@@ -1033,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');
@@ -1047,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');
@@ -1111,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');
@@ -1138,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');
@@ -1160,7 +1161,7 @@ moduleFor(
});
this.render('{{component (component "my-link") params=this.allParams}}', {
- allParams: emberA(['a', 'b']),
+ allParams: tracked(['a', 'b']),
});
this.assertText('ab');
@@ -1169,23 +1170,23 @@ moduleFor(
this.assertText('ab');
- runTask(() => this.context.get('allParams').pushObject('c'));
+ runTask(() => get(this.context, 'allParams').push('c'));
this.assertText('abc');
- runTask(() => this.context.get('allParams').popObject());
+ runTask(() => get(this.context, 'allParams').pop());
this.assertText('ab');
- runTask(() => this.context.get('allParams').clear());
+ runTask(() => get(this.context, 'allParams').splice(0, 2));
this.assertText('');
- runTask(() => this.context.set('allParams', emberA(['1', '2'])));
+ runTask(() => set(this.context, 'allParams', ['1', '2']));
this.assertText('12');
- runTask(() => this.context.set('allParams', emberA(['a', 'b'])));
+ runTask(() => set(this.context, 'allParams', ['a', 'b']));
this.assertText('ab');
}
@@ -1201,7 +1202,7 @@ moduleFor(
this.render(
'{{#let (hash link=(component "my-link")) as |c|}}{{c.link params=this.allParams}}{{/let}}',
{
- allParams: emberA(['a', 'b']),
+ allParams: tracked(['a', 'b']),
}
);
@@ -1211,23 +1212,23 @@ moduleFor(
this.assertText('ab');
- runTask(() => this.context.get('allParams').pushObject('c'));
+ runTask(() => get(this.context, 'allParams').push('c'));
this.assertText('abc');
- runTask(() => this.context.get('allParams').popObject());
+ runTask(() => get(this.context, 'allParams').pop());
this.assertText('ab');
- runTask(() => this.context.get('allParams').clear());
+ runTask(() => get(this.context, 'allParams').splice(0, 3));
this.assertText('');
- runTask(() => this.context.set('allParams', emberA(['1', '2'])));
+ runTask(() => set(this.context, 'allParams', ['1', '2']));
this.assertText('12');
- runTask(() => this.context.set('allParams', emberA(['a', 'b'])));
+ runTask(() => set(this.context, 'allParams', ['a', 'b']));
this.assertText('ab');
}
@@ -1249,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);
}
@@ -1274,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);
}
@@ -1466,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 2bf955d092e..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,18 +6,17 @@ import {
equalTokens,
equalsElement,
runTask,
- runLoopSettled,
} from 'internal-test-helpers';
+import { tracked as trackedBuiltIn } from 'tracked-built-ins';
+
import { action } from '@ember/object';
import { run } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';
import { tracked } from '@ember/-internals/metal';
import { alias } from '@ember/object/computed';
-import { on } from '@ember/object/evented';
import Service, { service } from '@ember/service';
-import EmberObject, { set, get, computed, observer } from '@ember/object';
-import { A as emberA } from '@ember/array';
+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');
}
@@ -1705,7 +1704,7 @@ moduleFor(
});
this.render('{{sample-component names=this.things}}', {
- things: emberA(['Foo', 4, 'Bar']),
+ things: trackedBuiltIn(['Foo', 4, 'Bar']),
});
this.assertText('Foo4Bar');
@@ -1714,19 +1713,19 @@ moduleFor(
this.assertText('Foo4Bar');
- runTask(() => this.context.get('things').pushObject(5));
+ runTask(() => get(this.context, 'things').push(5));
this.assertText('Foo4Bar5');
- runTask(() => this.context.get('things').shiftObject());
+ runTask(() => get(this.context, 'things').shift());
this.assertText('4Bar5');
- runTask(() => this.context.get('things').clear());
+ runTask(() => get(this.context, 'things').splice(0, 3));
this.assertText('');
- runTask(() => this.context.set('things', emberA(['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;
},
@@ -2564,7 +2563,7 @@ moduleFor(
template: 'Child: {{this.item}}.',
});
- let items = emberA(['Tom', 'Dick', 'Harry']);
+ let items = trackedBuiltIn(['Tom', 'Dick', 'Harry']);
this.render('{{non-block items=this.items}}', { items });
@@ -2574,15 +2573,15 @@ moduleFor(
this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]');
- runTask(() => this.context.get('items').pushObject('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').shiftObject());
+ runTask(() => get(this.context, 'items').shift());
this.assertText('In layout. [Child: Dick.][Child: Harry.][Child: Sergio.]');
- runTask(() => this.context.set('items', emberA(['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);
}
},
});
@@ -3007,22 +3006,27 @@ moduleFor(
init() {
super.init(...arguments);
- this.options = emberA([]);
+ this.options = [];
this.value = null;
}
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) {
- this.get('options').addObject(option);
+ if (get(this, 'options').indexOf(option) === -1) {
+ get(this, 'options').push(option);
+ }
}
unregisterOption(option) {
- this.get('options').removeObject(option);
+ let index = get(this, 'options').indexOf(option);
+ if (index > -1) {
+ get(this, 'options').splice(index, 1);
+ }
this.updateValue();
}
@@ -3039,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);
}
},
});
@@ -3077,7 +3081,7 @@ moduleFor(
}
willDestroyElement() {
- this.set('showFoo', false);
+ set(this, 'showFoo', false);
assert.ok(true, 'willDestroyElement was fired');
super.willDestroyElement(...arguments);
}
@@ -3091,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');
}
},
@@ -3147,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');
}
},
@@ -3159,52 +3125,6 @@ moduleFor(
runTask(() => set(this.context, 'foo', 5));
}
- ['@test triggering an event only attempts to invoke an identically named method, if it actually is a function (GH#15228)'](
- assert
- ) {
- assert.expect(3);
-
- let payload = ['arbitrary', 'event', 'data'];
-
- this.registerComponent('evented-component', {
- ComponentClass: Component.extend({
- someTruthyProperty: true,
-
- init() {
- this._super(...arguments);
- this.trigger('someMethod', ...payload);
- this.trigger('someTruthyProperty', ...payload);
- },
-
- someMethod(...data) {
- assert.deepEqual(
- data,
- payload,
- 'the method `someMethod` should be called, when `someMethod` is triggered'
- );
- },
-
- listenerForSomeMethod: on('someMethod', function (...data) {
- assert.deepEqual(
- data,
- payload,
- 'the listener `listenerForSomeMethod` should be called, when `someMethod` is triggered'
- );
- }),
-
- listenerForSomeTruthyProperty: on('someTruthyProperty', function (...data) {
- assert.deepEqual(
- data,
- payload,
- 'the listener `listenerForSomeTruthyProperty` should be called, when `someTruthyProperty` is triggered'
- );
- }),
- }),
- });
-
- this.render(`{{evented-component}}`);
- }
-
['@test component yielding in an {{#each}} has correct block values after rerendering (GH#14284)']() {
this.registerComponent('list-items', {
template: `{{#each this.items as |item|}}{{yield item}}{{/each}}`,
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 1c4f3bed6c0..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,11 +1,11 @@
import { classes, moduleFor, RenderingTestCase, runTask, strip } from 'internal-test-helpers';
import { schedule } from '@ember/runloop';
-import { set, setProperties } from '@ember/object';
-import { A as emberA } from '@ember/array';
+import { get, set, setProperties } from '@ember/object';
import { getViewElement, getViewId } from '@ember/-internals/views';
import { Component } from '../../utils/helpers';
+import { tracked } from 'tracked-built-ins';
class LifeCycleHooksTest extends RenderingTestCase {
constructor() {
@@ -174,8 +174,6 @@ class LifeCycleHooksTest extends RenderingTestCase {
assertNoElement('init', this);
assertState('init', 'preRender', this);
- this.on('init', () => pushHook('on(init)'));
-
schedule('afterRender', () => {
this.isInitialRender = false;
});
@@ -336,19 +334,16 @@ class LifeCycleHooksTest extends RenderingTestCase {
// Sync hooks
['the-top', 'init'],
- ['the-top', 'on(init)'],
['the-top', 'didReceiveAttrs'],
['the-top', 'willRender'],
['the-top', 'willInsertElement'],
['the-middle', 'init'],
- ['the-middle', 'on(init)'],
['the-middle', 'didReceiveAttrs'],
['the-middle', 'willRender'],
['the-middle', 'willInsertElement'],
['the-bottom', 'init'],
- ['the-bottom', 'on(init)'],
['the-bottom', 'didReceiveAttrs'],
['the-bottom', 'willRender'],
['the-bottom', 'willInsertElement'],
@@ -368,15 +363,12 @@ class LifeCycleHooksTest extends RenderingTestCase {
nonInteractive: [
// Sync hooks
['the-top', 'init'],
- ['the-top', 'on(init)'],
['the-top', 'didReceiveAttrs'],
['the-middle', 'init'],
- ['the-middle', 'on(init)'],
['the-middle', 'didReceiveAttrs'],
['the-bottom', 'init'],
- ['the-bottom', 'on(init)'],
['the-bottom', 'didReceiveAttrs'],
],
});
@@ -576,25 +568,21 @@ class LifeCycleHooksTest extends RenderingTestCase {
// Sync hooks
['the-parent', 'init'],
- ['the-parent', 'on(init)'],
['the-parent', 'didReceiveAttrs'],
['the-parent', 'willRender'],
['the-parent', 'willInsertElement'],
['the-first-child', 'init'],
- ['the-first-child', 'on(init)'],
['the-first-child', 'didReceiveAttrs'],
['the-first-child', 'willRender'],
['the-first-child', 'willInsertElement'],
['the-second-child', 'init'],
- ['the-second-child', 'on(init)'],
['the-second-child', 'didReceiveAttrs'],
['the-second-child', 'willRender'],
['the-second-child', 'willInsertElement'],
['the-last-child', 'init'],
- ['the-last-child', 'on(init)'],
['the-last-child', 'didReceiveAttrs'],
['the-last-child', 'willRender'],
['the-last-child', 'willInsertElement'],
@@ -618,19 +606,15 @@ class LifeCycleHooksTest extends RenderingTestCase {
// Sync hooks
['the-parent', 'init'],
- ['the-parent', 'on(init)'],
['the-parent', 'didReceiveAttrs'],
['the-first-child', 'init'],
- ['the-first-child', 'on(init)'],
['the-first-child', 'didReceiveAttrs'],
['the-second-child', 'init'],
- ['the-second-child', 'on(init)'],
['the-second-child', 'didReceiveAttrs'],
['the-last-child', 'init'],
- ['the-last-child', 'on(init)'],
['the-last-child', 'didReceiveAttrs'],
],
});
@@ -890,19 +874,16 @@ class LifeCycleHooksTest extends RenderingTestCase {
// Sync hooks
['the-top', 'init'],
- ['the-top', 'on(init)'],
['the-top', 'didReceiveAttrs'],
['the-top', 'willRender'],
['the-top', 'willInsertElement'],
['the-middle', 'init'],
- ['the-middle', 'on(init)'],
['the-middle', 'didReceiveAttrs'],
['the-middle', 'willRender'],
['the-middle', 'willInsertElement'],
['the-bottom', 'init'],
- ['the-bottom', 'on(init)'],
['the-bottom', 'didReceiveAttrs'],
['the-bottom', 'willRender'],
['the-bottom', 'willInsertElement'],
@@ -923,15 +904,12 @@ class LifeCycleHooksTest extends RenderingTestCase {
// Sync hooks
['the-top', 'init'],
- ['the-top', 'on(init)'],
['the-top', 'didReceiveAttrs'],
['the-middle', 'init'],
- ['the-middle', 'on(init)'],
['the-middle', 'didReceiveAttrs'],
['the-bottom', 'init'],
- ['the-bottom', 'on(init)'],
['the-bottom', 'didReceiveAttrs'],
],
});
@@ -1071,17 +1049,12 @@ class LifeCycleHooksTest extends RenderingTestCase {
let initialHooks = () => {
let ret = [
['an-item', 'init'],
- ['an-item', 'on(init)'],
['an-item', 'didReceiveAttrs'],
];
if (this.isInteractive) {
ret.push(['an-item', 'willRender'], ['an-item', 'willInsertElement']);
}
- ret.push(
- ['nested-item', 'init'],
- ['nested-item', 'on(init)'],
- ['nested-item', 'didReceiveAttrs']
- );
+ ret.push(['nested-item', 'init'], ['nested-item', 'didReceiveAttrs']);
if (this.isInteractive) {
ret.push(['nested-item', 'willRender'], ['nested-item', 'willInsertElement']);
}
@@ -1177,13 +1150,11 @@ class LifeCycleHooksTest extends RenderingTestCase {
['nested-item', 'willClearRender'],
['no-items', 'init'],
- ['no-items', 'on(init)'],
['no-items', 'didReceiveAttrs'],
['no-items', 'willRender'],
['no-items', 'willInsertElement'],
['nested-item', 'init'],
- ['nested-item', 'on(init)'],
['nested-item', 'didReceiveAttrs'],
['nested-item', 'willRender'],
['nested-item', 'willInsertElement'],
@@ -1218,11 +1189,9 @@ class LifeCycleHooksTest extends RenderingTestCase {
nonInteractive: [
['no-items', 'init'],
- ['no-items', 'on(init)'],
['no-items', 'didReceiveAttrs'],
['nested-item', 'init'],
- ['nested-item', 'on(init)'],
['nested-item', 'didReceiveAttrs'],
['an-item', 'willDestroy'],
@@ -1350,7 +1319,7 @@ moduleFor(
width = '5';
didInsertElement() {
schedule('afterRender', () => {
- this.set('width', '10');
+ set(this, 'width', '10');
});
}
};
@@ -1371,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');
});
}
};
@@ -1396,7 +1365,7 @@ moduleFor(
customHref = 'http://google.com';
attributeBindings = ['customHref:href'];
willRender() {
- this.set('customHref', 'http://willRender.com');
+ set(this, 'customHref', 'http://willRender.com');
}
};
@@ -1464,7 +1433,7 @@ moduleFor(
template: NestedTemplate,
});
- let array = emberA([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]);
+ let array = tracked([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]);
this.render(
strip`
@@ -1487,8 +1456,8 @@ moduleFor(
this.assertText('1AB2AB3AB4AB5AB6AB7AB');
runTask(() => {
- array.removeAt(2);
- array.removeAt(2);
+ array.splice(2, 1);
+ array.splice(2, 1);
set(this.context, 'model.shouldShow', false);
});
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 2902b9eaff4..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
@@ -5,14 +5,15 @@ import {
runTask,
} from 'internal-test-helpers';
import Controller, { inject as injectController } from '@ember/controller';
-import { A as emberA } from '@ember/array';
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';
import Engine from '@ember/engine';
import { DEBUG } from '@glimmer/env';
import { compile } from '../../../utils/helpers';
+import { tracked } from 'tracked-built-ins';
// IE includes the host name
function normalizeUrl(url) {
@@ -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'),
@@ -1536,7 +1537,7 @@ moduleFor(
controller = this;
}
- routeNames = emberA(['foo', 'bar', 'rar']);
+ routeNames = tracked(['foo', 'bar', 'rar']);
route1 = 'bar';
route2 = 'foo';
}
@@ -1575,11 +1576,11 @@ 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']);
- runTask(() => controller.routeNames.shiftObject());
+ runTask(() => controller.routeNames.shift());
linksEqual(this.$('a'), ['/bar', '/rar', '/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 a53984e0304..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
@@ -5,14 +5,15 @@ import {
runTask,
} from 'internal-test-helpers';
import Controller, { inject as injectController } from '@ember/controller';
-import { A as emberA } from '@ember/array';
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';
import Engine from '@ember/engine';
import { DEBUG } from '@glimmer/env';
import { compile } from '../../../utils/helpers';
+import { tracked } from 'tracked-built-ins';
// IE includes the host name
function normalizeUrl(url) {
@@ -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'),
@@ -1447,7 +1448,7 @@ moduleFor(
controller = this;
}
- routeNames = emberA(['foo', 'bar', 'rar']);
+ routeNames = tracked(['foo', 'bar', 'rar']);
route1 = 'bar';
route2 = 'foo';
}
@@ -1486,11 +1487,11 @@ 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']);
- runTask(() => controller.routeNames.shiftObject());
+ runTask(() => controller.routeNames.shift());
linksEqual(this.$('a'), ['/bar', '/rar', '/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/target-action-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/target-action-test.js
deleted file mode 100644
index 628beffa8f8..00000000000
--- a/packages/@ember/-internals/glimmer/tests/integration/components/target-action-test.js
+++ /dev/null
@@ -1,194 +0,0 @@
-import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers';
-
-import { action, set } from '@ember/object';
-import Mixin from '@ember/object/mixin';
-import Controller from '@ember/controller';
-import EmberObject from '@ember/object';
-
-import { Component } from '../../utils/helpers';
-
-moduleFor(
- 'Components test: send',
- class extends RenderingTestCase {
- ['@test sending to undefined actions triggers an error'](assert) {
- assert.expect(2);
-
- let component;
-
- this.registerComponent('foo-bar', {
- ComponentClass: class extends Component {
- init() {
- super.init();
- component = this;
- }
-
- @action
- foo(message) {
- assert.equal('bar', message);
- }
- },
- });
-
- this.render('{{foo-bar}}');
-
- runTask(() => component.send('foo', 'bar'));
-
- expectAssertion(() => {
- return component.send('baz', 'bar');
- }, /had no action handler for: baz/);
- }
-
- ['@test `send` will call send from a target if it is defined']() {
- let component;
- let target = {
- send: (message, payload) => {
- this.assert.equal('foo', message);
- this.assert.equal('baz', payload);
- },
- };
-
- this.registerComponent('foo-bar', {
- ComponentClass: class extends Component {
- init() {
- super.init(...arguments);
- component = this;
- }
- target = target;
- },
- });
-
- this.render('{{foo-bar}}');
-
- runTask(() => component.send('foo', 'baz'));
- }
-
- ['@test a handled action can be bubbled to the target for continued processing']() {
- this.assert.expect(2);
-
- let component;
-
- this.registerComponent('foo-bar', {
- ComponentClass: Component.extend({
- init() {
- this._super(...arguments);
- component = this;
- },
- actions: {
- poke: () => {
- this.assert.ok(true, 'component action called');
- return true;
- },
- },
- target: Controller.extend({
- actions: {
- poke: () => {
- this.assert.ok(true, 'action bubbled to controller');
- },
- },
- }).create(),
- }),
- });
-
- this.render('{{foo-bar poke="poke"}}');
-
- runTask(() => component.send('poke'));
- }
-
- ["@test action can be handled by a superclass' actions object"](assert) {
- this.assert.expect(4);
-
- let component;
-
- let SuperComponent = class extends Component {
- @action
- foo() {
- assert.ok(true, 'foo');
- }
-
- @action
- bar(msg) {
- assert.equal(msg, 'HELLO');
- }
- };
-
- let BarViewMixin = Mixin.create({
- actions: {
- bar(msg) {
- assert.equal(msg, 'HELLO');
- this._super(msg);
- },
- },
- });
-
- this.registerComponent('x-index', {
- ComponentClass: class extends SuperComponent.extend(BarViewMixin) {
- init() {
- super.init(...arguments);
- component = this;
- }
-
- @action
- baz() {
- assert.ok(true, 'baz');
- }
- },
- });
-
- this.render('{{x-index}}');
-
- runTask(() => {
- component.send('foo');
- component.send('bar', 'HELLO');
- component.send('baz');
- });
- }
-
- ['@test actions cannot be provided at create time'](assert) {
- this.registerComponent('foo-bar', class extends Component {});
- let ComponentFactory = this.owner.factoryFor('component:foo-bar');
-
- expectAssertion(() => {
- ComponentFactory.create({
- actions: {
- foo() {
- assert.ok(true, 'foo');
- },
- },
- });
- }, /`actions` must be provided at extend time, not at create time/);
- // but should be OK on an object that doesn't mix in Ember.ActionHandler
- EmberObject.create({
- actions: ['foo'],
- });
- }
-
- ['@test asserts if called on a destroyed component']() {
- let component;
-
- this.registerComponent('rip-alley', {
- ComponentClass: class extends Component {
- init() {
- super.init(...arguments);
- component = this;
- }
-
- toString() {
- return 'component:rip-alley';
- }
- },
- });
-
- this.render('{{#if this.shouldRender}}{{rip-alley}}{{/if}}', {
- shouldRender: true,
- });
-
- runTask(() => {
- set(this.context, 'shouldRender', false);
- });
-
- expectAssertion(() => {
- component.send('trigger-me-dead');
- }, "Attempted to call .send() with the action 'trigger-me-dead' on the destroyed object 'component:rip-alley'.");
- }
- }
-);
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 72f12a716fe..8b2ef03c063 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js
@@ -1,13 +1,10 @@
import EmberObject from '@ember/object';
-import { A } from '@ember/array';
-import ArrayProxy from '@ember/array/proxy';
-import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
import { tracked } from '@ember/-internals/metal';
import { computed, get, set } from '@ember/object';
-import { Promise } from 'rsvp';
import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers';
import GlimmerishComponent from '../../utils/glimmerish-component';
import { Component } from '../../utils/helpers';
+import { TrackedArray } from 'tracked-built-ins';
moduleFor(
'Component Tracked Properties',
@@ -46,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');
}
@@ -81,60 +78,10 @@ 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');
}
- '@test creating an array proxy inside a tracking context does not trigger backtracking assertion'() {
- let PromiseArray = ArrayProxy.extend(PromiseProxyMixin);
-
- class LoaderComponent extends GlimmerishComponent {
- get data() {
- if (!this._data) {
- this._data = PromiseArray.create({
- promise: Promise.resolve([1, 2, 3]),
- });
- }
-
- return this._data;
- }
- }
-
- this.registerComponent('loader', {
- ComponentClass: LoaderComponent,
- template: '{{#each this.data as |item|}}{{item}}{{/each}}',
- });
-
- this.render('');
-
- this.assertText('123');
- }
-
- '@test creating an array proxy inside a tracking context and immediately updating its content before usage does not trigger backtracking assertion'() {
- class LoaderComponent extends GlimmerishComponent {
- get data() {
- if (!this._data) {
- this._data = ArrayProxy.create({
- content: A(),
- });
-
- this._data.content.pushObjects([1, 2, 3]);
- }
-
- return this._data;
- }
- }
-
- this.registerComponent('loader', {
- ComponentClass: LoaderComponent,
- template: '{{#each this.data as |item|}}{{item}}{{/each}}',
- });
-
- this.render('');
-
- this.assertText('123');
- }
-
'@test tracked properties that are uninitialized do not throw an error'() {
class CountComponent extends Component {
@tracked count;
@@ -242,9 +189,9 @@ moduleFor(
'@test array properties rerender when updated'() {
class NumListComponent extends Component {
- @tracked numbers = A([1, 2, 3]);
+ @tracked numbers = new TrackedArray([1, 2, 3]);
- addNumber = () => this.numbers.pushObject(4);
+ addNumber = () => this.numbers.push(4);
}
this.registerComponent('num-list', {
@@ -307,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', {
@@ -621,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');
@@ -648,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!');
}
@@ -678,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!');
}
@@ -703,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 2e3c96609f8..3eed756a7a0 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/content-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/content-test.js
@@ -4,9 +4,8 @@ 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 ObjectProxy from '@ember/object/proxy';
import { constructStyleDeprecationMessage } from '@ember/-internals/views';
import { Component, SafeString, htmlSafe } from '../utils/helpers';
@@ -294,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();
}
};
@@ -321,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();
}
};
@@ -344,249 +343,6 @@ class DynamicContentTest extends RenderingTestCase {
this.assertInvariants();
}
- ['@test it can read from a proxy object']() {
- this.renderPath('this.proxy.name', {
- proxy: ObjectProxy.create({ content: { name: 'Tom Dale' } }),
- });
-
- this.assertContent('Tom Dale');
-
- this.assertStableRerender();
-
- runTask(() => set(this.context, 'proxy.content.name', 'Yehuda Katz'));
-
- this.assertContent('Yehuda Katz');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'proxy.content', { name: 'Godfrey Chan' }));
-
- this.assertContent('Godfrey Chan');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'proxy.name', 'Stefan Penner'));
-
- this.assertContent('Stefan Penner');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'proxy.content', null));
-
- this.assertIsEmpty();
-
- runTask(() =>
- set(this.context, 'proxy', ObjectProxy.create({ content: { name: 'Tom Dale' } }))
- );
-
- this.assertContent('Tom Dale');
- this.assertInvariants();
- }
-
- ['@test it can read from a nested path in a proxy object']() {
- this.renderPath('this.proxy.name.last', {
- proxy: ObjectProxy.create({
- content: { name: { first: 'Tom', last: 'Dale' } },
- }),
- });
-
- this.assertContent('Dale');
-
- this.assertStableRerender();
-
- runTask(() => set(this.context, 'proxy.content.name.last', 'Cruise'));
-
- this.assertContent('Cruise');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'proxy.content.name.first', 'Suri'));
-
- this.assertStableRerender();
-
- runTask(() => set(this.context, 'proxy.content.name', { first: 'Yehuda', last: 'Katz' }));
-
- this.assertContent('Katz');
- this.assertInvariants();
-
- runTask(() =>
- set(this.context, 'proxy.content', {
- name: { first: 'Godfrey', last: 'Chan' },
- })
- );
-
- this.assertContent('Chan');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'proxy.name', { first: 'Stefan', last: 'Penner' }));
-
- this.assertContent('Penner');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'proxy', null));
-
- this.assertIsEmpty();
-
- runTask(() =>
- set(
- this.context,
- 'proxy',
- ObjectProxy.create({
- content: { name: { first: 'Tom', last: 'Dale' } },
- })
- )
- );
-
- this.assertContent('Dale');
- this.assertInvariants();
- }
-
- ['@test it can read from a path flipping between a proxy and a real object']() {
- this.renderPath('this.proxyOrObject.name.last', {
- proxyOrObject: ObjectProxy.create({
- content: { name: { first: 'Tom', last: 'Dale' } },
- }),
- });
-
- this.assertContent('Dale');
-
- this.assertStableRerender();
-
- runTask(() =>
- set(this.context, 'proxyOrObject', {
- name: { first: 'Tom', last: 'Dale' },
- })
- );
-
- this.assertStableRerender();
-
- runTask(() => set(this.context, 'proxyOrObject.name.last', 'Cruise'));
-
- this.assertContent('Cruise');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'proxyOrObject.name.first', 'Suri'));
-
- this.assertStableRerender();
-
- runTask(() =>
- set(this.context, 'proxyOrObject', {
- name: { first: 'Yehuda', last: 'Katz' },
- })
- );
-
- this.assertContent('Katz');
- this.assertInvariants();
-
- runTask(() =>
- set(
- this.context,
- 'proxyOrObject',
- ObjectProxy.create({
- content: { name: { first: 'Godfrey', last: 'Chan' } },
- })
- )
- );
-
- this.assertContent('Chan');
- this.assertInvariants();
-
- runTask(() =>
- set(this.context, 'proxyOrObject.content.name', {
- first: 'Stefan',
- last: 'Penner',
- })
- );
-
- this.assertContent('Penner');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'proxyOrObject', null));
-
- this.assertIsEmpty();
-
- runTask(() =>
- set(
- this.context,
- 'proxyOrObject',
- ObjectProxy.create({
- content: { name: { first: 'Tom', last: 'Dale' } },
- })
- )
- );
-
- this.assertContent('Dale');
- this.assertInvariants();
- }
-
- ['@test it can read from a path flipping between a real object and a proxy']() {
- this.renderPath('this.objectOrProxy.name.last', {
- objectOrProxy: { name: { first: 'Tom', last: 'Dale' } },
- });
-
- this.assertContent('Dale');
-
- this.assertStableRerender();
-
- runTask(() =>
- set(
- this.context,
- 'objectOrProxy',
- ObjectProxy.create({
- content: { name: { first: 'Tom', last: 'Dale' } },
- })
- )
- );
-
- this.assertStableRerender();
-
- runTask(() => set(this.context, 'objectOrProxy.content.name.last', 'Cruise'));
-
- this.assertContent('Cruise');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'objectOrProxy.content.name.first', 'Suri'));
-
- this.assertStableRerender();
-
- runTask(() =>
- set(this.context, 'objectOrProxy.content', {
- name: { first: 'Yehuda', last: 'Katz' },
- })
- );
-
- this.assertContent('Katz');
- this.assertInvariants();
-
- runTask(() =>
- set(this.context, 'objectOrProxy', {
- name: { first: 'Godfrey', last: 'Chan' },
- })
- );
-
- this.assertContent('Chan');
- this.assertInvariants();
-
- runTask(() =>
- set(this.context, 'objectOrProxy.name', {
- first: 'Stefan',
- last: 'Penner',
- })
- );
-
- this.assertContent('Penner');
- this.assertInvariants();
-
- runTask(() => set(this.context, 'objectOrProxy', null));
-
- this.assertIsEmpty();
-
- runTask(() =>
- set(this.context, 'objectOrProxy', {
- name: { first: 'Tom', last: 'Dale' },
- })
- );
-
- this.assertContent('Dale');
- this.assertInvariants();
- }
-
['@test it can read from a null object']() {
let nullObject = Object.create(null);
nullObject['message'] = 'hello';
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/event-dispatcher-test.js b/packages/@ember/-internals/glimmer/tests/integration/event-dispatcher-test.js
index 60c37711e7d..2d1be1ef98f 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/event-dispatcher-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/event-dispatcher-test.js
@@ -149,35 +149,6 @@ moduleFor(
}
}
- ['@test event listeners are called when event is triggered'](assert) {
- let receivedEvent;
- let browserEvent;
-
- this.registerComponent('x-button', {
- ComponentClass: class extends Component {
- tagName = 'button';
- init() {
- super.init();
- Object.keys(SUPPORTED_EMBER_EVENTS).forEach((browserEvent) => {
- this.on(SUPPORTED_EMBER_EVENTS[browserEvent], (event) => (receivedEvent = event));
- });
- }
- },
- });
-
- this.render(`{{x-button}}`);
-
- let elementNode = this.$('button');
- let element = elementNode[0];
-
- for (browserEvent in SUPPORTED_EMBER_EVENTS) {
- receivedEvent = null;
- runTask(() => triggerEvent(elementNode, browserEvent));
- assert.ok(receivedEvent, `${browserEvent} event was triggered`);
- assert.strictEqual(receivedEvent.target, element);
- }
- }
-
['@test events bubble view hierarchy for form elements'](assert) {
let receivedEvent;
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 d23c8e7f482..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,15 +1,10 @@
-import EmberObject from '@ember/object';
-import { A } from '@ember/array';
-import MutableArray from '@ember/array/mutable';
-import {
- tracked,
- nativeDescDecorator as descriptor,
- notifyPropertyChange,
-} from '@ember/-internals/metal';
+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';
import { Component } from '../../utils/helpers';
+import { TrackedArray } from 'tracked-built-ins';
moduleFor(
'Helper Tracked Properties',
@@ -142,65 +137,10 @@ moduleFor(
'@test array properties rerender when updated'() {
class NumListComponent extends Component {
- @tracked numbers = A([1, 2, 3]);
+ @tracked numbers = new TrackedArray([1, 2, 3]);
addNumber = () => {
- this.numbers.pushObject(4);
- };
- }
-
- this.registerComponent('num-list', {
- ComponentClass: NumListComponent,
- template: strip`
-
- `,
- });
-
- this.registerHelper('join', ([value]) => {
- return value.join(', ');
- });
-
- this.render('');
-
- this.assertText('1, 2, 3');
-
- runTask(() => this.$('button').click());
-
- this.assertText('1, 2, 3, 4');
- }
-
- '@test custom ember array properties rerender when updated'() {
- let CustomArray = class extends EmberObject.extend(MutableArray) {
- init() {
- super.init(...arguments);
- this._vals = [1, 2, 3];
- }
-
- objectAt(index) {
- return this._vals[index];
- }
-
- replace(start, deleteCount, items = []) {
- this._vals.splice(start, deleteCount, ...items);
- notifyPropertyChange(this, '[]');
- }
-
- join() {
- return this._vals.join(...arguments);
- }
-
- get length() {
- return this._vals.length;
- }
- };
-
- class NumListComponent extends Component {
- @tracked numbers = CustomArray.create();
-
- addNumber = () => {
- this.numbers.pushObject(4);
+ this.numbers.push(4);
};
}
@@ -383,13 +323,13 @@ moduleFor(
this.assertText('bob-value');
- runTask(() => obj.set('value', 'sal'));
+ runTask(() => set(obj, 'value', 'sal'));
this.assertText('sal-value');
}
- '@test each-in autotracks arrays acorrectly'() {
- let obj = EmberObject.create({ arr: A([1]) });
+ '@test each-in autotracks arrays correctly'() {
+ let obj = EmberObject.create({ arr: new TrackedArray([1]) });
this.registerComponent('person', {
ComponentClass: class extends Component {
@@ -406,7 +346,7 @@ moduleFor(
this.assertText('1');
- runTask(() => obj.arr.pushObject(2));
+ runTask(() => obj.arr.push(2));
this.assertText('12');
}
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 5944b35356e..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,13 +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 { A as emberA } from '@ember/array';
+import { set, setProperties } from '@ember/object';
import { Component } from '../../utils/helpers';
@@ -42,7 +35,7 @@ moduleFor(
['@test should be able to use unbound helper in #each helper']() {
this.render(`{{#each this.items as |item|}}- {{unbound item}}
{{/each}}
`, {
- items: emberA(['a', 'b', 'c', 1, 2, 3]),
+ items: ['a', 'b', 'c', 1, 2, 3],
});
this.assertText('abc123');
@@ -56,7 +49,7 @@ moduleFor(
this.render(
`{{#each this.items as |item|}}- {{unbound item.wham}}
{{/each}}
`,
{
- items: emberA([{ wham: 'bam' }, { wham: 1 }]),
+ items: [{ wham: 'bam' }, { wham: 1 }],
}
);
@@ -66,11 +59,11 @@ moduleFor(
this.assertText('bam1');
- runTask(() => this.context.items.setEach('wham', 'HEY'));
+ runTask(() => this.context.items.forEach((i) => (i.wham = 'HEY')));
this.assertText('bam1');
- runTask(() => set(this.context, 'items', emberA([{ wham: 'bam' }, { wham: 1 }])));
+ runTask(() => set(this.context, 'items', [{ wham: 'bam' }, { wham: 1 }]));
this.assertText('bam1');
}
@@ -110,7 +103,7 @@ moduleFor(
}
['@test should property escape unsafe hrefs']() {
- let unsafeUrls = emberA([
+ let unsafeUrls = [
{
name: 'Bob',
url: 'javascript:bob-is-cool',
@@ -123,7 +116,7 @@ moduleFor(
name: 'Richard',
url: 'javascript:richard-is-cool',
},
- ]);
+ ];
this.render(
``,
@@ -152,7 +145,7 @@ moduleFor(
this.assertHTML(escapedHtml);
- runTask(() => this.context.people.setEach('url', 'http://google.com'));
+ runTask(() => this.context.people.forEach((i) => (i.url = 'http://google.com')));
this.assertHTML(escapedHtml);
@@ -369,83 +362,13 @@ 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());
this.render(
`{{#each this.people as |person|}}{{capitalize person.firstName}} {{unbound (capitalize person.firstName)}}{{/each}}`,
{
- people: emberA([
+ people: [
{
firstName: 'shooby',
lastName: 'taylor',
@@ -454,7 +377,7 @@ moduleFor(
firstName: 'cindy',
lastName: 'taylor',
},
- ]),
+ ],
}
);
@@ -464,98 +387,24 @@ moduleFor(
this.assertText('SHOOBY SHOOBYCINDY CINDY');
- runTask(() => this.context.people.setEach('firstName', 'chad'));
+ runTask(() => this.context.people.forEach((i) => set(i, 'firstName', 'chad')));
this.assertText('CHAD SHOOBYCHAD CINDY');
runTask(() =>
- set(
- this.context,
- 'people',
- emberA([
- {
- firstName: 'shooby',
- lastName: 'taylor',
- },
- {
- firstName: 'cindy',
- lastName: 'taylor',
- },
- ])
- )
- );
-
- 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: {
+ set(this.context, 'people', [
+ {
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',
- })
+ {
+ firstName: 'cindy',
+ lastName: 'taylor',
+ },
+ ])
);
- this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor');
+ this.assertText('SHOOBY SHOOBYCINDY CINDY');
}
['@test should be able to render bound form of a helper inside unbound form of same helper']() {
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-in-test.js b/packages/@ember/-internals/glimmer/tests/integration/syntax/each-in-test.js
index 25d6dd32c20..a68ac9529b9 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/syntax/each-in-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/each-in-test.js
@@ -2,7 +2,6 @@ import { applyMixins, moduleFor, RenderingTestCase, runTask, strip } from 'inter
import { get, set } from '@ember/object';
import EmberObject from '@ember/object';
-import ObjectProxy from '@ember/object/proxy';
import {
FalsyGenerator,
@@ -63,35 +62,7 @@ applyMixins(
])
);
-applyMixins(
- EachInProxyTest,
-
- new TruthyGenerator([ObjectProxy.create({ content: { 'Not empty': 1 } })]),
-
- new FalsyGenerator([
- ObjectProxy.create(),
- ObjectProxy.create({ content: null }),
- ObjectProxy.create({ content: {} }),
- ObjectProxy.create({ content: Object.create(null) }),
- ObjectProxy.create({ content: Object.create({}) }),
- ObjectProxy.create({ content: Object.create({ 'Not Empty': 1 }) }),
- ObjectProxy.create({ content: EmberObject.create() }),
- ])
-);
-
-// Truthy/Falsy tests
-moduleFor(
- 'Syntax test: {{#each-in}} with `ObjectProxy`',
- class extends EachInProxyTest {
- get truthyValue() {
- return ObjectProxy.create({ content: { 'Not Empty': 1 } });
- }
-
- get falsyValue() {
- return ObjectProxy.create({ content: null });
- }
- }
-);
+applyMixins(EachInProxyTest);
moduleFor('Syntax test: {{#each-in}}', BasicSyntaxTest);
@@ -515,110 +486,6 @@ moduleFor(
}
);
-moduleFor(
- 'Syntax test: {{#each-in}} with object proxies',
- class extends EachInTest {
- constructor() {
- super(...arguments);
- this.allowsSetProp = true;
- }
- createHash(pojo) {
- let hash = ObjectProxy.create({ content: pojo });
- return {
- hash,
- delegate: {
- setProp(context, key, value) {
- set(context, `hash.${key}`, value);
- },
- updateNestedValue(context, key, innerKey, value) {
- let target = get(context.hash, key);
- set(target, innerKey, value);
- },
- },
- };
- }
-
- ['@test it iterates over the content, not the proxy']() {
- let content = {
- Smartphones: 8203,
- 'JavaScript Frameworks': Infinity,
- };
-
- let proxy = ObjectProxy.create({
- content,
- foo: 'bar',
- });
-
- this.render(
- strip`
-
- {{#each-in this.categories as |category count|}}
- - {{category}}: {{count}}
- {{/each-in}}
-
- `,
- { categories: proxy }
- );
-
- this.assertHTML(strip`
-
- - Smartphones: 8203
- - JavaScript Frameworks: Infinity
-
- `);
-
- this.assertStableRerender();
-
- runTask(() => {
- set(proxy, 'content.Smartphones', 100);
- set(proxy, 'content.Tweets', 443115);
- });
-
- this.assertHTML(strip`
-
- - Smartphones: 100
- - JavaScript Frameworks: Infinity
- - Tweets: 443115
-
- `);
-
- runTask(() => {
- set(proxy, 'content', {
- Smartphones: 100,
- Tablets: 20,
- });
- });
-
- this.assertHTML(strip`
-
- - Smartphones: 100
- - Tablets: 20
-
- `);
-
- runTask(() =>
- set(
- this.context,
- 'categories',
- ObjectProxy.create({
- content: {
- Smartphones: 8203,
- 'JavaScript Frameworks': Infinity,
- },
- })
- )
- );
-
- this.assertHTML(strip`
-
- - Smartphones: 8203
- - JavaScript Frameworks: Infinity
-
- `);
- }
- }
-);
-
moduleFor(
'Syntax test: {{#each-in}} with ES6 Maps',
class extends EachInTest {
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 e4ed8e69213..9d218e4b4ef 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js
@@ -1,9 +1,7 @@
import { moduleFor, RenderingTestCase, applyMixins, strip, runTask } from 'internal-test-helpers';
-import { notifyPropertyChange, on } from '@ember/-internals/metal';
-import { get, set, computed } from '@ember/object';
-import { A as emberA } from '@ember/array';
-import ArrayProxy from '@ember/array/proxy';
+import { notifyPropertyChange } from '@ember/-internals/metal';
+import { get, set } from '@ember/object';
import { RSVP } from '@ember/-internals/runtime';
import { Component, htmlSafe } from '../../utils/helpers';
@@ -13,6 +11,7 @@ import {
FalsyGenerator,
ArrayTestCases,
} from '../../utils/shared-conditional-tests';
+import { TrackedArray } from 'tracked-built-ins';
class ArrayDelegate {
constructor(content, target) {
@@ -157,11 +156,8 @@ class BasicEachTest extends TogglingEachTest {}
const TRUTHY_CASES = [
['hello'],
- emberA(['hello']),
makeSet(['hello']),
new ForEachable(['hello']),
- ArrayProxy.create({ content: ['hello'] }),
- ArrayProxy.create({ content: emberA(['hello']) }),
new ArrayIterable(['hello']),
];
@@ -172,11 +168,8 @@ const FALSY_CASES = [
'',
0,
[],
- emberA([]),
makeSet([]),
new ForEachable([]),
- ArrayProxy.create({ content: [] }),
- ArrayProxy.create({ content: emberA([]) }),
new ArrayIterable([]),
];
@@ -527,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() {
@@ -1025,16 +1018,6 @@ moduleFor(
}
);
-moduleFor(
- 'Syntax test: {{#each}} with emberA-wrapped arrays',
- class extends EachTest {
- createList(items) {
- let wrapped = emberA(items);
- return { list: wrapped, delegate: wrapped };
- }
- }
-);
-
moduleFor(
'Syntax test: {{#each}} with native Set',
class extends EachTest {
@@ -1073,65 +1056,6 @@ moduleFor(
}
);
-moduleFor(
- 'Syntax test: {{#each}} with array proxies, modifying itself',
- class extends EachTest {
- createList(items) {
- let proxty = ArrayProxy.create({ content: emberA(items) });
- return { list: proxty, delegate: proxty };
- }
- }
-);
-
-moduleFor(
- 'Syntax test: {{#each}} with array proxies, replacing its content',
- class extends EachTest {
- createList(items) {
- let wrapped = emberA(items);
- return {
- list: wrapped,
- delegate: ArrayProxy.create({ content: wrapped }),
- };
- }
- }
-);
-
-moduleFor(
- 'Syntax test: {{#each}} with array proxies, arrangedContent depends on external content',
- class extends EachTest {
- createList(items) {
- let wrapped = emberA(items);
- let proxy = class extends ArrayProxy {
- @computed('wrappedItems.[]')
- get arrangedContent() {
- // Slice the items to ensure that updates must be propogated
- return this.wrappedItems.slice();
- }
- }.create({
- wrappedItems: wrapped,
- });
-
- return { list: proxy, delegate: wrapped };
- }
- }
-);
-
-moduleFor(
- 'Syntax test: {{#each}} with array proxies, content is updated after init',
- class extends EachTest {
- createList(items) {
- let wrapped = emberA(items);
- let proxy = ArrayProxy.extend({
- setup: on('init', function () {
- this.set('content', emberA(wrapped));
- }),
- }).create();
-
- return { list: proxy, delegate: wrapped };
- }
- }
-);
-
moduleFor(
'Syntax test: {{#each as}} undefined path',
class extends RenderingTestCase {
@@ -1164,8 +1088,8 @@ moduleFor(
moduleFor(
'Syntax test: {{#each}} with sparse arrays',
class extends RenderingTestCase {
- ['@test it should itterate over holes']() {
- let sparseArray = [];
+ ['@test it should iterate over holes']() {
+ let sparseArray = new TrackedArray();
sparseArray[3] = 'foo';
sparseArray[4] = 'bar';
@@ -1174,7 +1098,7 @@ moduleFor(
{{#each this.list as |value key|}}
[{{key}}:{{value}}]
{{/each}}`,
- { list: emberA(sparseArray) }
+ { list: sparseArray }
);
this.assertText('[0:][1:][2:][3:foo][4:bar]');
@@ -1183,7 +1107,7 @@ moduleFor(
runTask(() => {
let list = get(this.context, 'list');
- list.pushObject('baz');
+ list.push('baz');
});
this.assertText('[0:][1:][2:][3:foo][4:bar][5:baz]');
diff --git a/packages/@ember/-internals/glimmer/tests/integration/syntax/if-unless-test.js b/packages/@ember/-internals/glimmer/tests/integration/syntax/if-unless-test.js
index 4e8330db4f6..0a61915148f 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/syntax/if-unless-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/if-unless-test.js
@@ -1,6 +1,5 @@
import { RenderingTestCase, moduleFor, strip, runTask } from 'internal-test-helpers';
-import { A as emberA } from '@ember/array';
import { set } from '@ember/object';
import { Component } from '../../utils/helpers';
@@ -60,7 +59,7 @@ moduleFor(
{{else}}
Nothing Here!
{{/if}}`,
- { cond: true, numbers: emberA([1, 2, 3]) }
+ { cond: true, numbers: [1, 2, 3] }
);
this.assertText('123');
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 f2516061932..5859a47abcd 100644
--- a/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js
+++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js
@@ -1,8 +1,7 @@
import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers';
import { get, set } from '@ember/object';
-import { A as emberA, removeAt } from '@ember/array';
-import ObjectProxy from '@ember/object/proxy';
+import { removeAt } from '@ember/array';
moduleFor(
'Syntax test: {{#let as}}',
@@ -122,45 +121,11 @@ moduleFor(
this.assertText('-Yehuda-');
}
- ['@test can access alias of a proxy']() {
- this.render(`{{#let this.proxy as |person|}}{{person.name}}{{/let}}`, {
- proxy: ObjectProxy.create({ content: { name: 'Tom Dale' } }),
- });
-
- this.assertText('Tom Dale');
-
- runTask(() => this.rerender());
-
- this.assertText('Tom Dale');
-
- runTask(() => set(this.context, 'proxy.name', 'Yehuda Katz'));
-
- this.assertText('Yehuda Katz');
-
- runTask(() => set(this.context, 'proxy.content', { name: 'Godfrey Chan' }));
-
- this.assertText('Godfrey Chan');
-
- runTask(() => set(this.context, 'proxy.content.name', 'Stefan Penner'));
-
- this.assertText('Stefan Penner');
-
- runTask(() => set(this.context, 'proxy.content', null));
-
- this.assertText('');
-
- runTask(() =>
- set(this.context, 'proxy', ObjectProxy.create({ content: { name: 'Tom Dale' } }))
- );
-
- this.assertText('Tom Dale');
- }
-
['@test can access alias of an array']() {
this.render(
`{{#let this.arrayThing as |words|}}{{#each words as |word|}}{{word}}{{/each}}{{/let}}`,
{
- arrayThing: emberA(['Hello', ' ', 'world']),
+ arrayThing: ['Hello', ' ', 'world'],
}
);
@@ -172,10 +137,10 @@ moduleFor(
runTask(() => {
let array = get(this.context, 'arrayThing');
- array.replace(0, 1, ['Goodbye']);
+ array.splice(0, 1, ['Goodbye']);
removeAt(array, 1);
- array.insertAt(1, ', ');
- array.pushObject('!');
+ array.splice(1, 0, ', ');
+ array.push('!');
});
this.assertText('Goodbye, world!');
@@ -196,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/glimmer/tests/utils/shared-conditional-tests.js b/packages/@ember/-internals/glimmer/tests/utils/shared-conditional-tests.js
index bf725ea1634..b0da0a643d9 100644
--- a/packages/@ember/-internals/glimmer/tests/utils/shared-conditional-tests.js
+++ b/packages/@ember/-internals/glimmer/tests/utils/shared-conditional-tests.js
@@ -5,11 +5,10 @@ import { RenderingTestCase, applyMixins, runTask } from 'internal-test-helpers';
import { htmlSafe } from '@ember/-internals/glimmer';
import { get, set } from '@ember/object';
import EmberObject from '@ember/object';
-import ObjectProxy from '@ember/object/proxy';
-import { A as emberA, removeAt } from '@ember/array';
-import ArrayProxy from '@ember/array/proxy';
+import { removeAt } from '@ember/array';
import { Component } from './helpers';
+import { tracked } from 'tracked-built-ins';
class AbstractConditionalsTest extends RenderingTestCase {
get truthyValue() {
@@ -161,58 +160,6 @@ export class StableFalsyGenerator extends FalsyGenerator {
}
}
-class ObjectProxyGenerator extends AbstractGenerator {
- generate(value, idx) {
- // This is inconsistent with our usual to-bool policy, but the current proxy implementation
- // simply uses !!content to determine truthiness
- if (value) {
- return {
- [`@test it should consider an object proxy with \`${JSON.stringify(
- value
- )}\` truthy [${idx}]`]() {
- this.renderValues(ObjectProxy.create({ content: value }));
-
- this.assertText('T1');
-
- runTask(() => this.rerender());
-
- this.assertText('T1');
-
- runTask(() => set(this.context, 'cond1.content', this.falsyValue));
-
- this.assertText('F1');
-
- runTask(() => set(this.context, 'cond1', ObjectProxy.create({ content: value })));
-
- this.assertText('T1');
- },
- };
- } else {
- return {
- [`@test it should consider an object proxy with \`${JSON.stringify(
- value
- )}\` falsy [${idx}]`]() {
- this.renderValues(ObjectProxy.create({ content: value }));
-
- this.assertText('F1');
-
- runTask(() => this.rerender());
-
- this.assertText('F1');
-
- runTask(() => set(this.context, 'cond1.content', this.truthyValue));
-
- this.assertText('T1');
-
- runTask(() => set(this.context, 'cond1', ObjectProxy.create({ content: value })));
-
- this.assertText('F1');
- },
- };
- }
- }
-}
-
// Testing behaviors shared across all conditionals, i.e. {{#if}}, {{#unless}},
// {{#each}}, {{#each-in}}, (if) and (unless)
export class BasicConditionalsTest extends AbstractConditionalsTest {
@@ -245,50 +192,10 @@ export class BasicConditionalsTest extends AbstractConditionalsTest {
}
}
-// Testing behaviors related to ember objects, object proxies, etc
-export const ObjectTestCases = {
- ['@test it considers object proxies without content falsy']() {
- this.renderValues(
- ObjectProxy.create({ content: {} }),
- ObjectProxy.create({ content: EmberObject.create() }),
- ObjectProxy.create({ content: null })
- );
-
- this.assertText('T1T2F3');
-
- runTask(() => this.rerender());
-
- this.assertText('T1T2F3');
-
- runTask(() => {
- set(this.context, 'cond1.content', null);
- set(this.context, 'cond2.content', null);
- });
-
- this.assertText('F1F2F3');
-
- runTask(() => {
- set(this.context, 'cond1.content', EmberObject.create());
- set(this.context, 'cond2.content', {});
- set(this.context, 'cond3.content', { foo: 'bar' });
- });
-
- this.assertText('T1T2T3');
-
- runTask(() => {
- set(this.context, 'cond1', ObjectProxy.create({ content: {} }));
- set(this.context, 'cond2', ObjectProxy.create({ content: EmberObject.create() }));
- set(this.context, 'cond3', ObjectProxy.create({ content: null }));
- });
-
- this.assertText('T1T2F3');
- },
-};
-
// Testing behaviors related to arrays and array proxies
export const ArrayTestCases = {
['@test it considers empty arrays falsy']() {
- this.renderValues(emberA(['hello']), emberA());
+ this.renderValues(tracked(['hello']), tracked([]));
this.assertText('T1F2');
@@ -301,80 +208,15 @@ export const ArrayTestCases = {
this.assertText('F1F2');
runTask(() => {
- get(this.context, 'cond1').pushObject('hello');
- get(this.context, 'cond2').pushObjects([1]);
+ get(this.context, 'cond1').push('hello');
+ get(this.context, 'cond2').push(1);
});
this.assertText('T1T2');
runTask(() => {
- set(this.context, 'cond1', emberA(['hello']));
- set(this.context, 'cond2', emberA());
- });
-
- this.assertText('T1F2');
- },
-
- ['@test it considers array proxies without content falsy']() {
- this.renderValues(
- ArrayProxy.create({ content: emberA(['hello']) }),
- ArrayProxy.create({ content: null })
- );
-
- this.assertText('T1F2');
-
- runTask(() => this.rerender());
-
- this.assertText('T1F2');
-
- runTask(() => {
- set(this.context, 'cond1.content', null);
- set(this.context, 'cond2.content', null);
- });
-
- this.assertText('F1F2');
-
- runTask(() => {
- set(this.context, 'cond1.content', emberA(['hello']));
- set(this.context, 'cond2.content', emberA([1]));
- });
-
- this.assertText('T1T2');
-
- runTask(() => {
- set(this.context, 'cond1', ArrayProxy.create({ content: emberA(['hello']) }));
- set(this.context, 'cond2', ArrayProxy.create({ content: null }));
- });
-
- this.assertText('T1F2');
- },
-
- ['@test it considers array proxies with empty arrays falsy']() {
- this.renderValues(
- ArrayProxy.create({ content: emberA(['hello']) }),
- ArrayProxy.create({ content: emberA() })
- );
-
- this.assertText('T1F2');
-
- runTask(() => this.rerender());
-
- this.assertText('T1F2');
-
- runTask(() => removeAt(get(this.context, 'cond1.content'), 0));
-
- this.assertText('F1F2');
-
- runTask(() => {
- get(this.context, 'cond1.content').pushObject('hello');
- get(this.context, 'cond2.content').pushObjects([1]);
- });
-
- this.assertText('T1T2');
-
- runTask(() => {
- set(this.context, 'cond1', ArrayProxy.create({ content: emberA(['hello']) }));
- set(this.context, 'cond2', ArrayProxy.create({ content: emberA() }));
+ set(this.context, 'cond1', ['hello']);
+ set(this.context, 'cond2', []);
});
this.assertText('T1F2');
@@ -391,12 +233,10 @@ const IfUnlessWithTestCases = [
'undefined',
1,
['hello'],
- emberA(['hello']),
{},
{ foo: 'bar' },
EmberObject.create(),
EmberObject.create({ foo: 'bar' }),
- ObjectProxy.create({ content: true }),
Object,
function () {},
async function () {},
@@ -408,51 +248,7 @@ const IfUnlessWithTestCases = [
htmlSafe(' '),
]),
- new StableFalsyGenerator([
- false,
- null,
- undefined,
- '',
- 0,
- [],
- emberA(),
- ObjectProxy.create({ content: undefined }),
- htmlSafe(''),
- ]),
-
- new ObjectProxyGenerator([
- true,
- ' ',
- 'hello',
- 'false',
- 'null',
- 'undefined',
- 1,
- ['hello'],
- emberA(['hello']),
- ArrayProxy.create({ content: ['hello'] }),
- ArrayProxy.create({ content: [] }),
- {},
- { foo: 'bar' },
- EmberObject.create(),
- EmberObject.create({ foo: 'bar' }),
- ObjectProxy.create({ content: true }),
- ObjectProxy.create({ content: undefined }),
- new String('hello'),
- new String(''),
- new Boolean(true),
- new Boolean(false),
- new Date(),
- false,
- null,
- undefined,
- '',
- 0,
- [],
- emberA(),
- ]),
-
- ObjectTestCases,
+ new StableFalsyGenerator([false, null, undefined, '', 0, [], htmlSafe('')]),
ArrayTestCases,
];
diff --git a/packages/@ember/-internals/metal/index.ts b/packages/@ember/-internals/metal/index.ts
index 608bfa75037..4ffc6d8507c 100644
--- a/packages/@ember/-internals/metal/index.ts
+++ b/packages/@ember/-internals/metal/index.ts
@@ -21,16 +21,10 @@ export {
hasUnknownProperty,
} from './lib/property_get';
export { set, _setProp, trySet } from './lib/property_set';
-export {
- objectAt,
- replace,
- replaceInNativeArray,
- addArrayObserver,
- removeArrayObserver,
-} from './lib/array';
+export { objectAt, replace, addArrayObserver, removeArrayObserver } from './lib/array';
export { arrayContentWillChange, arrayContentDidChange } from './lib/array_events';
export { eachProxyArrayWillChange, eachProxyArrayDidChange } from './lib/each_proxy_events';
-export { addListener, hasListeners, on, removeListener, sendEvent } from './lib/events';
+export { addListener, hasListeners, removeListener, sendEvent } from './lib/events';
export {
beginPropertyChanges,
diff --git a/packages/@ember/-internals/metal/lib/array.ts b/packages/@ember/-internals/metal/lib/array.ts
index fa9f25ea28a..1de58c4b4de 100644
--- a/packages/@ember/-internals/metal/lib/array.ts
+++ b/packages/@ember/-internals/metal/lib/array.ts
@@ -1,12 +1,7 @@
-import type EmberArray from '@ember/array';
-import type MutableArray from '@ember/array/mutable';
-import { assert } from '@ember/debug';
import { arrayContentDidChange, arrayContentWillChange } from './array_events';
import { addListener, removeListener } from './events';
-const EMPTY_ARRAY = Object.freeze([]);
-
-type ObservedArray = (T[] | EmberArray) & ObservedObject;
+type ObservedArray = T[] & ObservedObject;
interface ObservedObject {
_revalidate?: () => void;
@@ -14,31 +9,11 @@ interface ObservedObject {
export { objectAt } from './object-at';
-// Ideally, we'd use MutableArray.detect but for unknown reasons this causes
-// the node tests to fail strangely.
-function isMutableArray(obj: unknown): obj is MutableArray {
- return obj != null && typeof (obj as MutableArray).replace === 'function';
-}
-
-export function replace(
- array: T[] | MutableArray,
- start: number,
- deleteCount: number,
- items: readonly T[] = EMPTY_ARRAY as []
-): void {
- if (isMutableArray(array)) {
- array.replace(start, deleteCount, items);
- } else {
- assert('Can only replace content of a native array or MutableArray', Array.isArray(array));
- replaceInNativeArray(array, start, deleteCount, items);
- }
-}
-
const CHUNK_SIZE = 60000;
// To avoid overflowing the stack, we splice up to CHUNK_SIZE items at a time.
// See https://code.google.com/p/chromium/issues/detail?id=56588 for more details.
-export function replaceInNativeArray(
+export function replace(
array: T[],
start: number,
deleteCount: number,
@@ -93,7 +68,7 @@ function arrayObserversHelper(
}
export function addArrayObserver(
- array: EmberArray,
+ array: T[],
target: object | Function | null,
opts: ArrayObserverOptions
): ObservedArray {
@@ -101,7 +76,7 @@ export function addArrayObserver(
}
export function removeArrayObserver(
- array: T[] | EmberArray,
+ array: T[],
target: object | Function | null,
opts: ArrayObserverOptions
): ObservedArray {
diff --git a/packages/@ember/-internals/metal/lib/events.ts b/packages/@ember/-internals/metal/lib/events.ts
index ab77fb52c86..aaf1489147f 100644
--- a/packages/@ember/-internals/metal/lib/events.ts
+++ b/packages/@ember/-internals/metal/lib/events.ts
@@ -3,8 +3,6 @@
*/
import type { Meta } from '@ember/-internals/meta';
import { meta as metaFor, peekMeta } from '@ember/-internals/meta';
-import { setListeners } from '@ember/-internals/utils';
-import type { AnyFn } from '@ember/-internals/utility-types';
import { assert } from '@ember/debug';
/*
@@ -176,45 +174,3 @@ export function hasListeners(obj: object, eventName: string): boolean {
let matched = meta.matchingListeners(eventName);
return matched !== undefined && matched.length > 0;
}
-
-/**
- Define a property as a function that should be executed when
- a specified event or events are triggered.
-
- ``` javascript
- import EmberObject from '@ember/object';
- import { on } from '@ember/object/evented';
- import { sendEvent } from '@ember/object/events';
-
- let Job = EmberObject.extend({
- logCompleted: on('completed', function() {
- console.log('Job completed!');
- })
- });
-
- let job = Job.create();
-
- sendEvent(job, 'completed'); // Logs 'Job completed!'
- ```
-
- @method on
- @static
- @for @ember/object/evented
- @param {String} eventNames*
- @param {Function} func
- @return {Function} the listener function, passed as last argument to on(...)
- @public
-*/
-export function on(...args: [...eventNames: string[], func: T]): T {
- let func = args.pop();
- let events = args as string[];
-
- assert('on expects function as last argument', typeof func === 'function');
- assert(
- 'on called without valid event names',
- events.length > 0 && events.every((p) => typeof p === 'string' && p.length > 0)
- );
-
- setListeners(func, events);
- return func;
-}
diff --git a/packages/@ember/-internals/metal/lib/object-at.ts b/packages/@ember/-internals/metal/lib/object-at.ts
index e85207863cb..384dd4320de 100644
--- a/packages/@ember/-internals/metal/lib/object-at.ts
+++ b/packages/@ember/-internals/metal/lib/object-at.ts
@@ -1,9 +1,4 @@
-import type EmberArray from '@ember/array';
-
-export function objectAt(array: T[] | EmberArray, index: number): T | undefined {
- if (Array.isArray(array)) {
- return array[index];
- } else {
- return array.objectAt(index);
- }
+/** @deprecated Use `array[index]` instead. */
+export function objectAt(array: readonly T[], index: number): T | undefined {
+ return array[index];
}
diff --git a/packages/@ember/-internals/metal/lib/property_get.ts b/packages/@ember/-internals/metal/lib/property_get.ts
index 8f2e28a82d0..0618f33664c 100644
--- a/packages/@ember/-internals/metal/lib/property_get.ts
+++ b/packages/@ember/-internals/metal/lib/property_get.ts
@@ -1,9 +1,7 @@
/**
@module @ember/object
*/
-import type ProxyMixin from '@ember/-internals/runtime/lib/mixins/-proxy';
-import { setProxy, symbol } from '@ember/-internals/utils';
-import { isEmberArray } from '@ember/array/-internals';
+import { symbol } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { consumeTag, isTracking, tagFor, track } from '@glimmer/validator';
@@ -128,7 +126,7 @@ export function _getProp(obj: unknown, keyName: string) {
if (isTracking()) {
consumeTag(tagFor(obj, keyName));
- if (Array.isArray(value) || isEmberArray(value)) {
+ if (Array.isArray(value)) {
// Add the tag of the returned value if it is an array, since arrays
// should always cause updates if they are consumed and then changed
consumeTag(tagFor(value, '[]'));
@@ -173,10 +171,6 @@ _getProp({ unknownProperty() {} }, 1 as any);
get({}, 'foo');
get({}, 'foo.bar');
-let fakeProxy = {} as ProxyMixin;
-setProxy(fakeProxy);
-
track(() => _getProp({}, 'a'));
track(() => _getProp({}, 1 as any));
track(() => _getProp({ a: [] }, 'a'));
-track(() => _getProp({ a: fakeProxy }, 'a'));
diff --git a/packages/@ember/-internals/metal/lib/tracked.ts b/packages/@ember/-internals/metal/lib/tracked.ts
index 226b632c2e3..ca3d6f021fa 100644
--- a/packages/@ember/-internals/metal/lib/tracked.ts
+++ b/packages/@ember/-internals/metal/lib/tracked.ts
@@ -1,5 +1,4 @@
import { meta as metaFor } from '@ember/-internals/meta';
-import { isEmberArray } from '@ember/array/-internals';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { consumeTag, dirtyTagFor, tagFor, trackedData } from '@glimmer/validator';
@@ -159,7 +158,7 @@ function descriptorForField([target, key, desc]: ElementDescriptor): DecoratorPr
// Add the tag of the returned value if it is an array, since arrays
// should always cause updates if they are consumed and then changed
- if (Array.isArray(value) || isEmberArray(value)) {
+ if (Array.isArray(value)) {
consumeTag(tagFor(value, '[]'));
}
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/alias_test.js b/packages/@ember/-internals/metal/tests/alias_test.js
index a9c4a2635ce..022d34bc15c 100644
--- a/packages/@ember/-internals/metal/tests/alias_test.js
+++ b/packages/@ember/-internals/metal/tests/alias_test.js
@@ -9,7 +9,6 @@ import {
tagForProperty,
} from '..';
import EmberObject from '@ember/object';
-import { A } from '@ember/array';
import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
import { destroy } from '@glimmer/destroyable';
import { valueForTag, validateTag } from '@glimmer/validator';
@@ -69,28 +68,29 @@ moduleFor(
assert.equal(count, 1);
}
- ['@test nested aliases should trigger computed property invalidation [GH#19279]'](assert) {
- let AttributeModel = class extends EmberObject {
- @alias('additives.length')
- countAdditives;
- additives = A();
- };
-
- let RootModel = class extends EmberObject {
- @computed('metaAttributes.@each.countAdditives')
- get allAdditives() {
- return this.metaAttributes.reduce((acc, el) => {
- return acc.concat(el.additives);
- }, []);
- }
- metaAttributes = A([AttributeModel.create()]);
- };
-
- let model = RootModel.create();
- assert.equal(model.allAdditives.length, 0);
- model.metaAttributes[0].additives.pushObject('foo');
- assert.equal(model.allAdditives.length, 1);
- }
+ // TODO: Revisit this
+ // ['@test nested aliases should trigger computed property invalidation [GH#19279]'](assert) {
+ // let AttributeModel = class extends EmberObject {
+ // @alias('additives.length')
+ // countAdditives;
+ // additives = new TrackedArray();
+ // };
+
+ // let RootModel = class extends EmberObject {
+ // @computed('metaAttributes.@each.countAdditives')
+ // get allAdditives() {
+ // return this.metaAttributes.reduce((acc, el) => {
+ // return acc.concat(el.additives);
+ // }, []);
+ // }
+ // metaAttributes = [AttributeModel.create()];
+ // };
+
+ // let model = RootModel.create();
+ // assert.equal(model.allAdditives.length, 0);
+ // model.metaAttributes[0].additives.push('foo');
+ // assert.equal(model.allAdditives.length, 1);
+ // }
async [`@test inheriting an observer of the alias from the prototype then
redefining the alias on the instance to another property dependent on same key
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/events_test.js b/packages/@ember/-internals/metal/tests/events_test.js
index 109792c39b7..fdc395aaa70 100644
--- a/packages/@ember/-internals/metal/tests/events_test.js
+++ b/packages/@ember/-internals/metal/tests/events_test.js
@@ -1,5 +1,4 @@
-import { on, addListener, removeListener, sendEvent, hasListeners } from '..';
-import Mixin from '@ember/object/mixin';
+import { addListener, removeListener, sendEvent, hasListeners } from '..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor(
@@ -138,62 +137,5 @@ moduleFor(
addListener(obj, 'event!', F);
assert.equal(hasListeners(obj, 'event!'), true, 'has listeners');
}
-
- ['@test a listener can be added as part of a mixin'](assert) {
- let triggered = 0;
- let MyMixin = Mixin.create({
- foo1: on('bar', function () {
- triggered++;
- }),
-
- foo2: on('bar', function () {
- triggered++;
- }),
- });
-
- let obj = {};
- MyMixin.apply(obj);
-
- sendEvent(obj, 'bar');
- assert.equal(triggered, 2, 'should invoke listeners');
- }
-
- [`@test 'on' asserts for invalid arguments`]() {
- expectAssertion(() => {
- Mixin.create({
- foo1: on('bar'),
- });
- }, 'on expects function as last argument');
-
- expectAssertion(() => {
- Mixin.create({
- foo1: on(function () {}),
- });
- }, 'on called without valid event names');
- }
-
- ['@test a listener added as part of a mixin may be overridden'](assert) {
- let triggered = 0;
- let FirstMixin = Mixin.create({
- foo: on('bar', function () {
- triggered++;
- }),
- });
- let SecondMixin = Mixin.create({
- foo: on('baz', function () {
- triggered++;
- }),
- });
-
- let obj = {};
- FirstMixin.apply(obj);
- SecondMixin.apply(obj);
-
- sendEvent(obj, 'bar');
- assert.equal(triggered, 0, 'should not invoke from overridden property');
-
- sendEvent(obj, 'baz');
- assert.equal(triggered, 1, 'should invoke from subclass property');
- }
}
);
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/package.json b/packages/@ember/-internals/package.json
index 4acae247231..9a9ef015325 100644
--- a/packages/@ember/-internals/package.json
+++ b/packages/@ember/-internals/package.json
@@ -29,7 +29,6 @@
"@ember/debug": "workspace:*",
"@ember/destroyable": "workspace:*",
"@ember/engine": "workspace:*",
- "@ember/enumerable": "workspace:*",
"@ember/helper": "workspace:*",
"@ember/instrumentation": "workspace:*",
"@ember/modifier": "workspace:*",
@@ -65,7 +64,8 @@
"expect-type": "^0.15.0",
"internal-test-helpers": "workspace:*",
"router_js": "^8.0.5",
- "rsvp": "^4.8.5"
+ "rsvp": "^4.8.5",
+ "tracked-built-ins": "^4.0.0"
},
"devDependencies": {
"@ember/template-compiler": "workspace:*"
diff --git a/packages/@ember/-internals/runtime/index.ts b/packages/@ember/-internals/runtime/index.ts
index ec028a7a2da..fb977fe1c7a 100644
--- a/packages/@ember/-internals/runtime/index.ts
+++ b/packages/@ember/-internals/runtime/index.ts
@@ -1,9 +1 @@
-export { default as RegistryProxyMixin } from './lib/mixins/registry_proxy';
-export { default as ContainerProxyMixin } from './lib/mixins/container_proxy';
-export { default as Comparable } from './lib/mixins/comparable';
-export { default as ActionHandler } from './lib/mixins/action_handler';
-export { default as _ProxyMixin, contentFor as _contentFor } from './lib/mixins/-proxy';
-export { default as MutableEnumerable } from '@ember/enumerable/mutable';
-export { default as TargetActionSupport } from './lib/mixins/target_action_support';
-
export { default as RSVP, onerrorDefault } from './lib/ext/rsvp'; // just for side effect of extending Ember.RSVP
diff --git a/packages/@ember/-internals/runtime/lib/mixins/-proxy.ts b/packages/@ember/-internals/runtime/lib/mixins/-proxy.ts
deleted file mode 100644
index f45c14a2855..00000000000
--- a/packages/@ember/-internals/runtime/lib/mixins/-proxy.ts
+++ /dev/null
@@ -1,147 +0,0 @@
-/**
-@module ember
-*/
-
-import { meta } from '@ember/-internals/meta';
-import Mixin from '@ember/object/mixin';
-import {
- get,
- set,
- defineProperty,
- tagForObject,
- computed,
- tagForProperty,
-} from '@ember/-internals/metal';
-import { setProxy, setupMandatorySetter, isObject, isProxy } from '@ember/-internals/utils';
-import { assert } from '@ember/debug';
-import { DEBUG } from '@glimmer/env';
-import { setCustomTagFor } from '@glimmer/manager';
-import type { UpdatableTag, Tag } from '@glimmer/validator';
-import { combine, updateTag, tagFor, tagMetaFor } from '@glimmer/validator';
-
-export function contentFor(proxy: ProxyMixin): T | null {
- let content = get(proxy, 'content');
- // SAFETY: Ideally we'd assert instead of casting, but @glimmer/validator doesn't give us
- // sufficient public types for this. Previously this code was .js and worked correctly so
- // hopefully this is sufficiently reliable.
- updateTag(tagForObject(proxy) as UpdatableTag, tagForObject(content));
- return content;
-}
-
-function customTagForProxy(proxy: object, key: string, addMandatorySetter?: boolean): Tag {
- assert('Expected a proxy', isProxy(proxy));
-
- let meta = tagMetaFor(proxy);
- let tag = tagFor(proxy, key, meta);
-
- if (DEBUG) {
- // TODO: Replace this with something more first class for tracking tags in DEBUG
- // SAFETY: This is not an officially supported property but setting shouldn't cause issues.
- (tag as any)._propertyKey = key;
- }
-
- if (key in proxy) {
- if (DEBUG && addMandatorySetter) {
- assert('[BUG] setupMandatorySetter should be set when debugging', setupMandatorySetter);
- setupMandatorySetter(tag, proxy, key);
- }
-
- return tag;
- } else {
- let tags: Tag[] = [tag, tagFor(proxy, 'content', meta)];
-
- let content = contentFor(proxy);
-
- if (isObject(content)) {
- tags.push(tagForProperty(content, key, addMandatorySetter));
- }
-
- return combine(tags);
- }
-}
-
-/**
- `Ember.ProxyMixin` forwards all properties not defined by the proxy itself
- to a proxied `content` object. See ObjectProxy for more details.
-
- @class ProxyMixin
- @namespace Ember
- @private
-*/
-interface ProxyMixin {
- /**
- The object whose properties will be forwarded.
-
- @property content
- @type {unknown}
- @default null
- @public
- */
- content: T | null;
-
- willDestroy(): void;
-
- isTruthy: boolean;
-
- unknownProperty(key: K): T[K] | undefined;
- unknownProperty(key: string): unknown;
-
- setUnknownProperty(key: K, value: T[K]): T[K];
- setUnknownProperty(key: string, value: V): V;
-}
-
-const ProxyMixin = Mixin.create({
- /**
- The object whose properties will be forwarded.
-
- @property content
- @type {unknown}
- @default null
- @public
- */
- content: null,
-
- init() {
- this._super(...arguments);
- setProxy(this);
- tagForObject(this);
- setCustomTagFor(this, customTagForProxy);
- },
-
- willDestroy() {
- this.set('content', null);
- this._super(...arguments);
- },
-
- isTruthy: computed('content', function () {
- return Boolean(get(this, 'content'));
- }),
-
- unknownProperty(key: string) {
- let content = contentFor(this);
- return content ? get(content, key) : undefined;
- },
-
- setUnknownProperty(key: string, value: unknown) {
- let m = meta(this);
-
- if (m.isInitializing() || m.isPrototypeMeta(this)) {
- // if marked as prototype or object is initializing then just
- // defineProperty rather than delegate
- defineProperty(this, key, null, value);
- return value;
- }
-
- let content = contentFor(this);
-
- assert(
- `Cannot delegate set('${key}', ${value}) to the 'content' property of object proxy ${this}: its 'content' is undefined.`,
- content
- );
-
- // SAFETY: We don't actually guarantee that this is an object, so this isn't necessarily safe :(
- return set(content as object, key, value);
- },
-});
-
-export default ProxyMixin;
diff --git a/packages/@ember/-internals/runtime/lib/mixins/action_handler.ts b/packages/@ember/-internals/runtime/lib/mixins/action_handler.ts
deleted file mode 100644
index 29c13f32c7c..00000000000
--- a/packages/@ember/-internals/runtime/lib/mixins/action_handler.ts
+++ /dev/null
@@ -1,227 +0,0 @@
-/**
-@module ember
-*/
-
-import Mixin from '@ember/object/mixin';
-import { get } from '@ember/-internals/metal';
-import { assert } from '@ember/debug';
-
-/**
- `Ember.ActionHandler` is available on some familiar classes including
- `Route`, `Component`, and `Controller`.
- (Internally the mixin is used by `Ember.CoreView`, `Ember.ControllerMixin`,
- and `Route` and available to the above classes through
- inheritance.)
-
- @class ActionHandler
- @namespace Ember
- @private
-*/
-interface ActionHandler {
- actions?: Record unknown>;
- send(actionName: string, ...args: unknown[]): void;
-}
-const ActionHandler = Mixin.create({
- mergedProperties: ['actions'],
-
- /**
- The collection of functions, keyed by name, available on this
- `ActionHandler` as action targets.
-
- These functions will be invoked when a matching `{{action}}` is triggered
- from within a template and the application's current route is this route.
-
- Actions can also be invoked from other parts of your application
- via `ActionHandler#send`.
-
- The `actions` hash will inherit action handlers from
- the `actions` hash defined on extended parent classes
- or mixins rather than just replace the entire hash, e.g.:
-
- ```app/mixins/can-display-banner.js
- import Mixin from '@ember/object/mixin';
-
- export default Mixin.create({
- actions: {
- displayBanner(msg) {
- // ...
- }
- }
- });
- ```
-
- ```app/routes/welcome.js
- import Route from '@ember/routing/route';
- import CanDisplayBanner from '../mixins/can-display-banner';
-
- export default Route.extend(CanDisplayBanner, {
- actions: {
- playMusic() {
- // ...
- }
- }
- });
-
- // `WelcomeRoute`, when active, will be able to respond
- // to both actions, since the actions hash is merged rather
- // then replaced when extending mixins / parent classes.
- this.send('displayBanner');
- this.send('playMusic');
- ```
-
- Within a Controller, Route or Component's action handler,
- the value of the `this` context is the Controller, Route or
- Component object:
-
- ```app/routes/song.js
- import Route from '@ember/routing/route';
-
- export default Route.extend({
- actions: {
- myAction() {
- this.controllerFor("song");
- this.transitionTo("other.route");
- ...
- }
- }
- });
- ```
-
- It is also possible to call `this._super(...arguments)` from within an
- action handler if it overrides a handler defined on a parent
- class or mixin:
-
- Take for example the following routes:
-
- ```app/mixins/debug-route.js
- import Mixin from '@ember/object/mixin';
-
- export default Mixin.create({
- actions: {
- debugRouteInformation() {
- console.debug("It's a-me, console.debug!");
- }
- }
- });
- ```
-
- ```app/routes/annoying-debug.js
- import Route from '@ember/routing/route';
- import DebugRoute from '../mixins/debug-route';
-
- export default Route.extend(DebugRoute, {
- actions: {
- debugRouteInformation() {
- // also call the debugRouteInformation of mixed in DebugRoute
- this._super(...arguments);
-
- // show additional annoyance
- window.alert(...);
- }
- }
- });
- ```
-
- ## Bubbling
-
- By default, an action will stop bubbling once a handler defined
- on the `actions` hash handles it. To continue bubbling the action,
- you must return `true` from the handler:
-
- ```app/router.js
- Router.map(function() {
- this.route("album", function() {
- this.route("song");
- });
- });
- ```
-
- ```app/routes/album.js
- import Route from '@ember/routing/route';
-
- export default Route.extend({
- actions: {
- startPlaying: function() {
- }
- }
- });
- ```
-
- ```app/routes/album-song.js
- import Route from '@ember/routing/route';
-
- export default Route.extend({
- actions: {
- startPlaying() {
- // ...
-
- if (actionShouldAlsoBeTriggeredOnParentRoute) {
- return true;
- }
- }
- }
- });
- ```
-
- @property actions
- @type Object
- @default null
- @public
- */
-
- /**
- Triggers a named action on the `ActionHandler`. Any parameters
- supplied after the `actionName` string will be passed as arguments
- to the action target function.
-
- If the `ActionHandler` has its `target` property set, actions may
- bubble to the `target`. Bubbling happens when an `actionName` can
- not be found in the `ActionHandler`'s `actions` hash or if the
- action target function returns `true`.
-
- Example
-
- ```app/routes/welcome.js
- import Route from '@ember/routing/route';
-
- export default Route.extend({
- actions: {
- playTheme() {
- this.send('playMusic', 'theme.mp3');
- },
- playMusic(track) {
- // ...
- }
- }
- });
- ```
-
- @method send
- @param {String} actionName The action to trigger
- @param {*} context a context to send with the action
- @public
- */
- send(actionName: string, ...args: any[]) {
- assert(
- `Attempted to call .send() with the action '${actionName}' on the destroyed object '${this}'.`,
- !this.isDestroying && !this.isDestroyed
- );
- if (this.actions && this.actions[actionName]) {
- let shouldBubble = this.actions[actionName].apply(this, args) === true;
- if (!shouldBubble) {
- return;
- }
- }
-
- let target = get(this, 'target');
- if (target) {
- assert(
- `The \`target\` for ${this} (${target}) does not have a \`send\` method`,
- typeof target.send === 'function'
- );
- target.send(...arguments);
- }
- },
-});
-
-export default ActionHandler;
diff --git a/packages/@ember/-internals/runtime/lib/mixins/comparable.ts b/packages/@ember/-internals/runtime/lib/mixins/comparable.ts
deleted file mode 100644
index 451fd1d4885..00000000000
--- a/packages/@ember/-internals/runtime/lib/mixins/comparable.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import Mixin from '@ember/object/mixin';
-
-/**
-@module ember
-*/
-
-/**
- Implements some standard methods for comparing objects. Add this mixin to
- any class you create that can compare its instances.
-
- You should implement the `compare()` method.
-
- @class Comparable
- @namespace Ember
- @since Ember 0.9
- @private
-*/
-interface Comparable {
- compare: ((a: unknown, b: unknown) => -1 | 0 | 1) | null;
-}
-const Comparable = Mixin.create({
- /**
- __Required.__ You must implement this method to apply this mixin.
-
- Override to return the result of the comparison of the two parameters. The
- compare method should return:
-
- - `-1` if `a < b`
- - `0` if `a == b`
- - `1` if `a > b`
-
- Default implementation raises an exception.
-
- @method compare
- @param a {Object} the first object to compare
- @param b {Object} the second object to compare
- @return {Number} the result of the comparison
- @private
- */
- compare: null,
-});
-
-export default Comparable;
diff --git a/packages/@ember/-internals/runtime/lib/mixins/container_proxy.ts b/packages/@ember/-internals/runtime/lib/mixins/container_proxy.ts
deleted file mode 100644
index 9b9a870a7c9..00000000000
--- a/packages/@ember/-internals/runtime/lib/mixins/container_proxy.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import { schedule, join } from '@ember/runloop';
-/**
-@module ember
-*/
-import type Container from '@ember/-internals/container/lib/container';
-import Mixin from '@ember/object/mixin';
-import type { ContainerProxy } from '@ember/-internals/owner';
-
-// This is defined as a separate interface so that it can be used in the definition of
-// `Owner` without also including the `__container__` property.
-
-/**
- ContainerProxyMixin is used to provide public access to specific
- container functionality.
-
- @class ContainerProxyMixin
- @extends ContainerProxy
- @private
-*/
-interface ContainerProxyMixin extends ContainerProxy {
- /** @internal */
- __container__: Container;
-}
-const ContainerProxyMixin = Mixin.create({
- /**
- The container stores state.
-
- @private
- @property {Ember.Container} __container__
- */
- __container__: null,
-
- ownerInjection() {
- return this.__container__.ownerInjection();
- },
-
- lookup(fullName: string, options: object) {
- return this.__container__.lookup(fullName, options);
- },
-
- destroy() {
- let container = this.__container__;
-
- if (container) {
- join(() => {
- container.destroy();
- schedule('destroy', container, 'finalizeDestroy');
- });
- }
-
- this._super();
- },
-
- factoryFor(fullName: string) {
- return this.__container__.factoryFor(fullName);
- },
-});
-
-export default ContainerProxyMixin;
diff --git a/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.ts b/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.ts
deleted file mode 100644
index 1399a185d49..00000000000
--- a/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
-@module ember
-*/
-
-import type { Registry } from '@ember/-internals/container';
-import type { RegistryProxy } from '@ember/-internals/owner';
-import type { AnyFn } from '@ember/-internals/utility-types';
-
-import { assert } from '@ember/debug';
-import Mixin from '@ember/object/mixin';
-
-/**
- RegistryProxyMixin is used to provide public access to specific
- registry functionality.
-
- @class RegistryProxyMixin
- @extends RegistryProxy
- @private
-*/
-interface RegistryProxyMixin extends RegistryProxy {
- /** @internal */
- __registry__: Registry;
-}
-const RegistryProxyMixin = Mixin.create({
- __registry__: null,
-
- resolveRegistration(fullName: string) {
- assert('fullName must be a proper full name', this.__registry__.isValidFullName(fullName));
- return this.__registry__.resolve(fullName);
- },
-
- register: registryAlias('register'),
- unregister: registryAlias('unregister'),
- hasRegistration: registryAlias('has'),
- registeredOption: registryAlias('getOption'),
- registerOptions: registryAlias('options'),
- registeredOptions: registryAlias('getOptions'),
- registerOptionsForType: registryAlias('optionsForType'),
- registeredOptionsForType: registryAlias('getOptionsForType'),
-});
-
-type AliasMethods =
- | 'register'
- | 'unregister'
- | 'has'
- | 'getOption'
- | 'options'
- | 'getOptions'
- | 'optionsForType'
- | 'getOptionsForType';
-
-function registryAlias(name: N) {
- return function (this: RegistryProxyMixin, ...args: Parameters) {
- // We need this cast because `Parameters` is deferred so that it is not
- // possible for TS to see it will always produce the right type. However,
- // since `AnyFn` has a rest type, it is allowed. See discussion on [this
- // issue](https://github.com/microsoft/TypeScript/issues/47615).
- return (this.__registry__[name] as AnyFn)(...args);
- };
-}
-
-export default RegistryProxyMixin;
diff --git a/packages/@ember/-internals/runtime/lib/mixins/target_action_support.ts b/packages/@ember/-internals/runtime/lib/mixins/target_action_support.ts
deleted file mode 100644
index e4448ab7392..00000000000
--- a/packages/@ember/-internals/runtime/lib/mixins/target_action_support.ts
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
-@module ember
-*/
-
-import { context } from '@ember/-internals/environment';
-import { get, computed } from '@ember/-internals/metal';
-import Mixin from '@ember/object/mixin';
-import { assert } from '@ember/debug';
-import { DEBUG } from '@glimmer/env';
-
-/**
-`Ember.TargetActionSupport` is a mixin that can be included in a class
-to add a `triggerAction` method with semantics similar to the Handlebars
-`{{action}}` helper. In normal Ember usage, the `{{action}}` helper is
-usually the best choice. This mixin is most often useful when you are
-doing more complex event handling in Components.
-
-@class TargetActionSupport
-@namespace Ember
-@extends Mixin
-@private
-*/
-interface TargetActionSupport {
- target: unknown;
- action: string | null;
- actionContext: unknown;
- actionContextObject: unknown;
- triggerAction(opts?: object): unknown;
-
- /** @internal */
- _target?: unknown;
-}
-const TargetActionSupport = Mixin.create({
- target: null,
- action: null,
- actionContext: null,
-
- actionContextObject: computed('actionContext', function () {
- let actionContext = get(this, 'actionContext');
-
- if (typeof actionContext === 'string') {
- let value = get(this, actionContext);
- if (value === undefined) {
- value = get(context.lookup, actionContext);
- }
- return value;
- } else {
- return actionContext;
- }
- }),
-
- /**
- Send an `action` with an `actionContext` to a `target`. The action, actionContext
- and target will be retrieved from properties of the object. For example:
-
- ```javascript
- import { alias } from '@ember/object/computed';
-
- App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
- target: alias('controller'),
- action: 'save',
- actionContext: alias('context'),
- click() {
- this.triggerAction(); // Sends the `save` action, along with the current context
- // to the current controller
- }
- });
- ```
-
- The `target`, `action`, and `actionContext` can be provided as properties of
- an optional object argument to `triggerAction` as well.
-
- ```javascript
- App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
- click() {
- this.triggerAction({
- action: 'save',
- target: this.get('controller'),
- actionContext: this.get('context')
- }); // Sends the `save` action, along with the current context
- // to the current controller
- }
- });
- ```
-
- The `actionContext` defaults to the object you are mixing `TargetActionSupport` into.
- But `target` and `action` must be specified either as properties or with the argument
- to `triggerAction`, or a combination:
-
- ```javascript
- import { alias } from '@ember/object/computed';
-
- App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
- target: alias('controller'),
- click() {
- this.triggerAction({
- action: 'save'
- }); // Sends the `save` action, along with a reference to `this`,
- // to the current controller
- }
- });
- ```
-
- @method triggerAction
- @param opts {Object} (optional, with the optional keys action, target and/or actionContext)
- @return {Boolean} true if the action was sent successfully and did not return false
- @private
- */
- triggerAction(opts: { action?: string; target?: unknown; actionContext?: unknown } = {}) {
- let { action, target, actionContext } = opts;
- action = action || get(this, 'action');
- target = target || getTarget(this);
-
- if (actionContext === undefined) {
- actionContext = get(this, 'actionContextObject') || this;
- }
-
- let context = Array.isArray(actionContext) ? actionContext : [actionContext];
-
- if (target && action) {
- let ret;
-
- if (isSendable(target)) {
- ret = target.send(action, ...context);
- } else {
- assert(
- `The action '${action}' did not exist on ${target}`,
- typeof (target as any)[action] === 'function'
- );
- ret = (target as any)[action](...context);
- }
-
- if (ret !== false) {
- return true;
- }
- }
-
- return false;
- },
-});
-
-interface Sendable {
- send(action: string, ...context: unknown[]): unknown;
-}
-
-function isSendable(obj: unknown): obj is Sendable {
- return obj != null && typeof obj === 'object' && typeof (obj as Sendable).send === 'function';
-}
-
-function getTarget(instance: TargetActionSupport) {
- let target = get(instance, 'target');
- if (target) {
- if (typeof target === 'string') {
- let value = get(instance, target);
- if (value === undefined) {
- value = get(context.lookup, target);
- }
-
- return value;
- } else {
- return target;
- }
- }
-
- if (instance._target) {
- return instance._target;
- }
-
- return null;
-}
-
-if (DEBUG) {
- Object.seal(TargetActionSupport);
-}
-
-export default TargetActionSupport;
diff --git a/packages/@ember/-internals/runtime/tests/array/any-test.js b/packages/@ember/-internals/runtime/tests/array/any-test.js
deleted file mode 100644
index 58928a04fe2..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/any-test.js
+++ /dev/null
@@ -1,55 +0,0 @@
-import { A as emberA } from '@ember/array';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class AnyTests extends AbstractTestCase {
- '@test any should should invoke callback on each item as long as you return false'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let found = [];
- let result;
-
- result = obj.any(function (i) {
- found.push(i);
- return false;
- });
-
- this.assert.equal(result, false, 'return value of obj.any');
- this.assert.deepEqual(found, ary, 'items passed during any() should match');
- }
-
- '@test any should stop invoking when you return true'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let cnt = ary.length - 2;
- let exp = cnt;
- let found = [];
- let result;
-
- result = obj.any(function (i) {
- found.push(i);
- return --cnt <= 0;
- });
- this.assert.equal(result, true, 'return value of obj.any');
- this.assert.equal(found.length, exp, 'should invoke proper number of times');
- this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during any() should match');
- }
-
- '@test any should return true if any object matches the callback'() {
- let obj = emberA([0, 1, 2]);
- let result;
-
- result = obj.any((i) => Boolean(i));
- this.assert.equal(result, true, 'return value of obj.any');
- }
-
- '@test any should produce correct results even if the matching element is undefined'(assert) {
- let obj = emberA([undefined]);
- let result;
-
- result = obj.any(() => true);
- assert.equal(result, true, 'return value of obj.any');
- }
-}
-
-runArrayTests('any', AnyTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/apply-test.js b/packages/@ember/-internals/runtime/tests/array/apply-test.js
deleted file mode 100644
index aeff3fc25f9..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/apply-test.js
+++ /dev/null
@@ -1,31 +0,0 @@
-import { NativeArray } from '@ember/array';
-import { AbstractTestCase, moduleFor } from 'internal-test-helpers';
-
-class ArrayPrototypeExtensionSelfReferenceTests extends AbstractTestCase {
- '@test should not create non-Symbol, enumerable properties that refer to itself'() {
- // Don't want to pollute Array.prototype so we make a fake / simple prototype
- function ThrowAwayArray() {}
-
- // Extend our throw-away prototype (like EXTEND_PROTOTYPES.Array would)
- NativeArray.apply(ThrowAwayArray.prototype);
-
- // Create an instance to test
- let obj = new ThrowAwayArray();
-
- // Make sure that no enumerable properties refer back to the object (creating a cyclic structure)
- for (let p in obj) {
- this.assert.notStrictEqual(
- obj[p],
- obj,
- `Property "${p}" is an enumerable part of the prototype
- so must not refer back to the original array.
- Otherwise code that explores all properties,
- such as jQuery.extend and other "deep cloning" functions,
- will get stuck in an infinite loop.
- `.replace(/\s+/g, ' ')
- );
- }
- }
-}
-
-moduleFor(`NativeArray: apply`, ArrayPrototypeExtensionSelfReferenceTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/compact-test.js b/packages/@ember/-internals/runtime/tests/array/compact-test.js
deleted file mode 100644
index eabf464d860..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/compact-test.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class CompactTests extends AbstractTestCase {
- '@test removes null and undefined values from enumerable'() {
- let obj = this.newObject([null, 1, false, '', undefined, 0, null]);
- let ary = obj.compact();
- this.assert.deepEqual(ary, [1, false, '', 0]);
- }
-}
-
-runArrayTests('compact', CompactTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/every-test.js b/packages/@ember/-internals/runtime/tests/array/every-test.js
deleted file mode 100644
index a23a6cf81a0..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/every-test.js
+++ /dev/null
@@ -1,82 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-import EmberObject from '@ember/object';
-
-class EveryTest extends AbstractTestCase {
- '@test every should should invoke callback on each item as long as you return true'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let found = [];
- let result;
-
- result = obj.every(function (i) {
- found.push(i);
- return true;
- });
- this.assert.equal(result, true, 'return value of obj.every');
- this.assert.deepEqual(found, ary, 'items passed during every() should match');
- }
-
- '@test every should stop invoking when you return false'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let cnt = ary.length - 2;
- let exp = cnt;
- let found = [];
- let result;
-
- result = obj.every(function (i) {
- found.push(i);
- return --cnt > 0;
- });
- this.assert.equal(result, false, 'return value of obj.every');
- this.assert.equal(found.length, exp, 'should invoke proper number of times');
- this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during every() should match');
- }
-}
-
-class IsEveryTest extends AbstractTestCase {
- '@test should return true of every property matches'() {
- let obj = this.newObject([
- { foo: 'foo', bar: 'BAZ' },
- EmberObject.create({ foo: 'foo', bar: 'bar' }),
- ]);
-
- this.assert.equal(obj.isEvery('foo', 'foo'), true, 'isEvery(foo)');
- this.assert.equal(obj.isEvery('bar', 'bar'), false, 'isEvery(bar)');
- }
-
- '@test should return true of every property is true'() {
- let obj = this.newObject([
- { foo: 'foo', bar: true },
- EmberObject.create({ foo: 'bar', bar: false }),
- ]);
-
- // different values - all eval to true
- this.assert.equal(obj.isEvery('foo'), true, 'isEvery(foo)');
- this.assert.equal(obj.isEvery('bar'), false, 'isEvery(bar)');
- }
-
- '@test should return true if every property matches null'() {
- let obj = this.newObject([
- { foo: null, bar: 'BAZ' },
- EmberObject.create({ foo: null, bar: null }),
- ]);
-
- this.assert.equal(obj.isEvery('foo', null), true, "isEvery('foo', null)");
- this.assert.equal(obj.isEvery('bar', null), false, "isEvery('bar', null)");
- }
-
- '@test should return true if every property is undefined'() {
- let obj = this.newObject([
- { foo: undefined, bar: 'BAZ' },
- EmberObject.create({ bar: undefined }),
- ]);
-
- this.assert.equal(obj.isEvery('foo', undefined), true, "isEvery('foo', undefined)");
- this.assert.equal(obj.isEvery('bar', undefined), false, "isEvery('bar', undefined)");
- }
-}
-
-runArrayTests('every', EveryTest);
-runArrayTests('isEvery', IsEveryTest);
diff --git a/packages/@ember/-internals/runtime/tests/array/filter-test.js b/packages/@ember/-internals/runtime/tests/array/filter-test.js
deleted file mode 100644
index d0d97028563..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/filter-test.js
+++ /dev/null
@@ -1,102 +0,0 @@
-import EmberObject from '@ember/object';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class FilterTest extends AbstractTestCase {
- '@test filter should invoke on each item'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let cnt = ary.length - 2;
- let found = [];
- let result;
-
- // return true on all but the last two
- result = obj.filter(function (i) {
- found.push(i);
- return --cnt >= 0;
- });
- this.assert.deepEqual(found, ary, 'should have invoked on each item');
- this.assert.deepEqual(result, ary.slice(0, -2), 'filtered array should exclude items');
- }
-}
-
-class FilterByTest extends AbstractTestCase {
- '@test should include in result if property is true'() {
- let obj, ary;
-
- ary = [{ foo: 'foo', bar: true }, EmberObject.create({ foo: 'bar', bar: false })];
-
- obj = this.newObject(ary);
-
- // different values - all eval to true
- this.assert.deepEqual(obj.filterBy('foo'), ary, 'filterBy(foo)');
- this.assert.deepEqual(obj.filterBy('bar'), [ary[0]], 'filterBy(bar)');
- }
-
- '@test should filter on second argument if provided'() {
- let obj, ary;
-
- ary = [
- { name: 'obj1', foo: 3 },
- EmberObject.create({ name: 'obj2', foo: 2 }),
- { name: 'obj3', foo: 2 },
- EmberObject.create({ name: 'obj4', foo: 3 }),
- ];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.filterBy('foo', 3), [ary[0], ary[3]], "filterBy('foo', 3)')");
- }
-
- '@test should correctly filter null second argument'() {
- let obj, ary;
-
- ary = [
- { name: 'obj1', foo: 3 },
- EmberObject.create({ name: 'obj2', foo: null }),
- { name: 'obj3', foo: null },
- EmberObject.create({ name: 'obj4', foo: 3 }),
- ];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.filterBy('foo', null), [ary[1], ary[2]], "filterBy('foo', 3)')");
- }
-
- '@test should correctly filter explicit undefined second argument'() {
- let obj, ary;
-
- ary = [
- { name: 'obj1', foo: 3 },
- EmberObject.create({ name: 'obj2', foo: 3 }),
- { name: 'obj3', foo: undefined },
- EmberObject.create({ name: 'obj4', foo: undefined }),
- { name: 'obj5' },
- EmberObject.create({ name: 'obj6' }),
- ];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.filterBy('foo', undefined), ary.slice(2), "filterBy('foo', 3)')");
- }
-
- '@test should not match undefined properties without second argument'() {
- let obj, ary;
-
- ary = [
- { name: 'obj1', foo: 3 },
- EmberObject.create({ name: 'obj2', foo: 3 }),
- { name: 'obj3', foo: undefined },
- EmberObject.create({ name: 'obj4', foo: undefined }),
- { name: 'obj5' },
- EmberObject.create({ name: 'obj6' }),
- ];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.filterBy('foo'), ary.slice(0, 2), "filterBy('foo', 3)')");
- }
-}
-
-runArrayTests('filter', FilterTest);
-runArrayTests('filter', FilterByTest);
diff --git a/packages/@ember/-internals/runtime/tests/array/find-test.js b/packages/@ember/-internals/runtime/tests/array/find-test.js
deleted file mode 100644
index 02b34fe5323..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/find-test.js
+++ /dev/null
@@ -1,86 +0,0 @@
-import EmberObject from '@ember/object';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class FindTests extends AbstractTestCase {
- '@test find should invoke callback on each item as long as you return false'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let found = [];
- let result;
-
- result = obj.find(function (i) {
- found.push(i);
- return false;
- });
- this.assert.equal(result, undefined, 'return value of obj.find');
- this.assert.deepEqual(found, ary, 'items passed during find() should match');
- }
-
- '@test every should stop invoking when you return true'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let cnt = ary.length - 2;
- let exp = cnt;
- let found = [];
- let result;
-
- result = obj.find(function (i) {
- found.push(i);
- return --cnt >= 0;
- });
- this.assert.equal(result, ary[exp - 1], 'return value of obj.find');
- this.assert.equal(found.length, exp, 'should invoke proper number of times');
- this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during find() should match');
- }
-}
-
-class FindByTests extends AbstractTestCase {
- '@test should return first object of property matches'() {
- let ary, obj;
-
- ary = [{ foo: 'foo', bar: 'BAZ' }, EmberObject.create({ foo: 'foo', bar: 'bar' })];
-
- obj = this.newObject(ary);
-
- this.assert.equal(obj.findBy('foo', 'foo'), ary[0], 'findBy(foo)');
- this.assert.equal(obj.findBy('bar', 'bar'), ary[1], 'findBy(bar)');
- }
-
- '@test should return first object with truthy prop'() {
- let ary, obj;
-
- ary = [{ foo: 'foo', bar: false }, EmberObject.create({ foo: 'bar', bar: true })];
-
- obj = this.newObject(ary);
-
- // different values - all eval to true
- this.assert.equal(obj.findBy('foo'), ary[0], 'findBy(foo)');
- this.assert.equal(obj.findBy('bar'), ary[1], 'findBy(bar)');
- }
-
- '@test should return first null property match'() {
- let ary, obj;
-
- ary = [{ foo: null, bar: 'BAZ' }, EmberObject.create({ foo: null, bar: null })];
-
- obj = this.newObject(ary);
-
- this.assert.equal(obj.findBy('foo', null), ary[0], "findBy('foo', null)");
- this.assert.equal(obj.findBy('bar', null), ary[1], "findBy('bar', null)");
- }
-
- '@test should return first undefined property match'() {
- let ary, obj;
-
- ary = [{ foo: undefined, bar: 'BAZ' }, EmberObject.create({})];
-
- obj = this.newObject(ary);
-
- this.assert.equal(obj.findBy('foo', undefined), ary[0], "findBy('foo', undefined)");
- this.assert.equal(obj.findBy('bar', undefined), ary[1], "findBy('bar', undefined)");
- }
-}
-
-runArrayTests('find', FindTests);
-runArrayTests('findBy', FindByTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/firstObject-test.js b/packages/@ember/-internals/runtime/tests/array/firstObject-test.js
deleted file mode 100644
index b44ce9c2a04..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/firstObject-test.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import { get, set } from '@ember/object';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class FirstObjectTests extends AbstractTestCase {
- '@test returns first item in enumerable'() {
- let obj = this.newObject();
- this.assert.equal(get(obj, 'firstObject'), this.toArray(obj)[0]);
- }
-
- '@test returns undefined if enumerable is empty'() {
- let obj = this.newObject([]);
- this.assert.equal(get(obj, 'firstObject'), undefined);
- }
-
- '@test can not be set'() {
- let obj = this.newObject([]);
-
- this.assert.equal(get(obj, 'firstObject'), this.toArray(obj)[0]);
-
- this.assert.throws(() => {
- set(obj, 'firstObject', 'foo!');
- }, /Cannot set read-only property "firstObject" on object/);
- }
-}
-
-runArrayTests('firstObject', FirstObjectTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/forEach-test.js b/packages/@ember/-internals/runtime/tests/array/forEach-test.js
deleted file mode 100644
index 062a1302c36..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/forEach-test.js
+++ /dev/null
@@ -1,68 +0,0 @@
-import { guidFor } from '@ember/-internals/utils';
-import { get } from '@ember/-internals/metal';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class ForEachTests extends AbstractTestCase {
- '@test forEach should iterate over list'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let found = [];
-
- obj.forEach((i) => found.push(i));
- this.assert.deepEqual(found, ary, 'items passed during forEach should match');
- }
-
- '@test forEach should iterate over list after mutation'() {
- if (get(this, 'canTestMutation')) {
- this.assert.expect(0);
- return;
- }
-
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let found = [];
-
- obj.forEach((i) => found.push(i));
- this.assert.deepEqual(found, ary, 'items passed during forEach should match');
-
- this.mutate(obj);
- ary = this.toArray(obj);
- found = [];
-
- obj.forEach((i) => found.push(i));
- this.assert.deepEqual(found, ary, 'items passed during forEach should match');
- }
-
- '@test 2nd target parameter'() {
- let obj = this.newObject();
- let target = this;
-
- obj.forEach(() => {
- // ES6TODO: When transpiled we will end up with "use strict" which disables automatically binding to the global context.
- // Therefore, the following test can never pass in strict mode unless we modify the `map` function implementation to
- // use `Ember.lookup` if target is not specified.
- //
- // equal(guidFor(this), guidFor(global), 'should pass the global object as this if no context');
- });
-
- obj.forEach(() => {
- this.assert.equal(guidFor(this), guidFor(target), 'should pass target as this if context');
- }, target);
- }
-
- '@test callback params'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let loc = 0;
-
- obj.forEach((item, idx, enumerable) => {
- this.assert.equal(item, ary[loc], 'item param');
- this.assert.equal(idx, loc, 'idx param');
- this.assert.equal(guidFor(enumerable), guidFor(obj), 'enumerable param');
- loc++;
- });
- }
-}
-
-runArrayTests('forEach', ForEachTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/includes-test.js b/packages/@ember/-internals/runtime/tests/array/includes-test.js
deleted file mode 100644
index c8119057d9e..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/includes-test.js
+++ /dev/null
@@ -1,46 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class IncludesTests extends AbstractTestCase {
- '@test includes returns correct value if startAt is positive'() {
- let data = newFixture(3);
- let obj = this.newObject(data);
-
- this.assert.equal(obj.includes(data[1], 1), true, 'should return true if included');
- this.assert.equal(obj.includes(data[0], 1), false, 'should return false if not included');
- }
-
- '@test includes returns correct value if startAt is negative'() {
- let data = newFixture(3);
- let obj = this.newObject(data);
-
- this.assert.equal(obj.includes(data[1], -2), true, 'should return true if included');
- this.assert.equal(obj.includes(data[0], -2), false, 'should return false if not included');
- }
-
- '@test includes returns true if startAt + length is still negative'() {
- let data = newFixture(1);
- let obj = this.newObject(data);
-
- this.assert.equal(obj.includes(data[0], -2), true, 'should return true if included');
- this.assert.equal(
- obj.includes(newFixture(1), -2),
- false,
- 'should return false if not included'
- );
- }
-
- '@test includes returns false if startAt out of bounds'() {
- let data = newFixture(1);
- let obj = this.newObject(data);
-
- this.assert.equal(obj.includes(data[0], 2), false, 'should return false if startAt >= length');
- this.assert.equal(
- obj.includes(newFixture(1), 2),
- false,
- 'should return false if startAt >= length'
- );
- }
-}
-
-runArrayTests('includes', IncludesTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/indexOf-test.js b/packages/@ember/-internals/runtime/tests/array/indexOf-test.js
deleted file mode 100644
index aa03ed0f118..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/indexOf-test.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class IndexOfTests extends AbstractTestCase {
- '@test should return index of object'() {
- let expected = newFixture(3);
- let obj = this.newObject(expected);
- let len = 3;
-
- for (let idx = 0; idx < len; idx++) {
- this.assert.equal(
- obj.indexOf(expected[idx]),
- idx,
- `obj.indexOf(${expected[idx]}) should match idx`
- );
- }
- }
-
- '@test should return -1 when requesting object not in index'() {
- let obj = this.newObject(newFixture(3));
- let foo = {};
-
- this.assert.equal(obj.indexOf(foo), -1, 'obj.indexOf(foo) should be < 0');
- }
-}
-
-runArrayTests('indexOf', IndexOfTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/invoke-test.js b/packages/@ember/-internals/runtime/tests/array/invoke-test.js
deleted file mode 100644
index a8e7a7e55fc..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/invoke-test.js
+++ /dev/null
@@ -1,61 +0,0 @@
-import EmberObject from '@ember/object';
-import { NativeArray } from '@ember/array';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class InvokeTests extends AbstractTestCase {
- '@test invoke should call on each object that implements'() {
- let cnt, ary, obj;
-
- function F(amt) {
- cnt += amt === undefined ? 1 : amt;
- }
- cnt = 0;
- ary = [
- { foo: F },
- EmberObject.create({ foo: F }),
-
- // NOTE: does not impl foo - invoke should just skip
- EmberObject.create({ bar: F }),
-
- { foo: F },
- ];
-
- obj = this.newObject(ary);
- obj.invoke('foo');
- this.assert.equal(cnt, 3, 'should have invoked 3 times');
-
- cnt = 0;
- obj.invoke('foo', 2);
- this.assert.equal(cnt, 6, 'should have invoked 3 times, passing param');
- }
-
- '@test invoke should return an array containing the results of each invoked method'(assert) {
- let obj = this.newObject([
- {
- foo() {
- return 'one';
- },
- },
- {}, // intentionally not including `foo` method
- {
- foo() {
- return 'two';
- },
- },
- ]);
-
- let result = obj.invoke('foo');
- assert.deepEqual(result, ['one', undefined, 'two']);
- }
-
- '@test invoke should return an extended array (aka Ember.A)'(assert) {
- let obj = this.newObject([{ foo() {} }, { foo() {} }]);
-
- let result = obj.invoke('foo');
-
- assert.ok(NativeArray.detect(result), 'NativeArray has been applied');
- }
-}
-
-runArrayTests('invoke', InvokeTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/isAny-test.js b/packages/@ember/-internals/runtime/tests/array/isAny-test.js
deleted file mode 100644
index 56fd637dba4..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/isAny-test.js
+++ /dev/null
@@ -1,53 +0,0 @@
-import EmberObject from '@ember/object';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class IsAnyTests extends AbstractTestCase {
- '@test should return true of any property matches'() {
- let obj = this.newObject([
- { foo: 'foo', bar: 'BAZ' },
- EmberObject.create({ foo: 'foo', bar: 'bar' }),
- ]);
-
- this.assert.equal(obj.isAny('foo', 'foo'), true, 'isAny(foo)');
- this.assert.equal(obj.isAny('bar', 'bar'), true, 'isAny(bar)');
- this.assert.equal(obj.isAny('bar', 'BIFF'), false, 'isAny(BIFF)');
- }
-
- '@test should return true of any property is true'() {
- let obj = this.newObject([
- { foo: 'foo', bar: true },
- EmberObject.create({ foo: 'bar', bar: false }),
- ]);
-
- // different values - all eval to true
- this.assert.equal(obj.isAny('foo'), true, 'isAny(foo)');
- this.assert.equal(obj.isAny('bar'), true, 'isAny(bar)');
- this.assert.equal(obj.isAny('BIFF'), false, 'isAny(biff)');
- }
-
- '@test should return true if any property matches null'() {
- let obj = this.newObject([
- { foo: null, bar: 'bar' },
- EmberObject.create({ foo: 'foo', bar: null }),
- ]);
-
- this.assert.equal(obj.isAny('foo', null), true, "isAny('foo', null)");
- this.assert.equal(obj.isAny('bar', null), true, "isAny('bar', null)");
- }
-
- '@test should return true if any property is undefined'() {
- let obj = this.newObject([{ foo: undefined, bar: 'bar' }, EmberObject.create({ foo: 'foo' })]);
-
- this.assert.equal(obj.isAny('foo', undefined), true, "isAny('foo', undefined)");
- this.assert.equal(obj.isAny('bar', undefined), true, "isAny('bar', undefined)");
- }
-
- '@test should not match undefined properties without second argument'() {
- let obj = this.newObject([{ foo: undefined }, EmberObject.create({})]);
-
- this.assert.equal(obj.isAny('foo'), false, "isAny('foo', undefined)");
- }
-}
-
-runArrayTests('isAny', IsAnyTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/lastIndexOf-test.js b/packages/@ember/-internals/runtime/tests/array/lastIndexOf-test.js
deleted file mode 100644
index 88ff7ec93a2..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/lastIndexOf-test.js
+++ /dev/null
@@ -1,78 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class LastIndexOfTests extends AbstractTestCase {
- "@test should return index of object's last occurrence"() {
- let expected = newFixture(3);
- let obj = this.newObject(expected);
- let len = 3;
-
- for (let idx = 0; idx < len; idx++) {
- this.assert.equal(
- obj.lastIndexOf(expected[idx]),
- idx,
- `obj.lastIndexOf(${expected[idx]}) should match idx`
- );
- }
- }
-
- "@test should return index of object's last occurrence even startAt search location is equal to length"() {
- let expected = newFixture(3);
- let obj = this.newObject(expected);
- let len = 3;
-
- for (let idx = 0; idx < len; idx++) {
- this.assert.equal(
- obj.lastIndexOf(expected[idx], len),
- idx,
- `obj.lastIndexOfs(${expected[idx]}) should match idx`
- );
- }
- }
-
- "@test should return index of object's last occurrence even startAt search location is greater than length"() {
- let expected = newFixture(3);
- let obj = this.newObject(expected);
- let len = 3;
-
- for (let idx = 0; idx < len; idx++) {
- this.assert.equal(
- obj.lastIndexOf(expected[idx], len + 1),
- idx,
- `obj.lastIndexOf(${expected[idx]}) should match idx`
- );
- }
- }
-
- '@test should return -1 when no match is found'() {
- let obj = this.newObject(newFixture(3));
- let foo = {};
-
- this.assert.equal(obj.lastIndexOf(foo), -1, 'obj.lastIndexOf(foo) should be -1');
- }
-
- '@test should return -1 when no match is found even startAt search location is equal to length'() {
- let obj = this.newObject(newFixture(3));
- let foo = {};
-
- this.assert.equal(
- obj.lastIndexOf(foo, get(obj, 'length')),
- -1,
- 'obj.lastIndexOf(foo) should be -1'
- );
- }
-
- '@test should return -1 when no match is found even startAt search location is greater than length'() {
- let obj = this.newObject(newFixture(3));
- let foo = {};
-
- this.assert.equal(
- obj.lastIndexOf(foo, get(obj, 'length') + 1),
- -1,
- 'obj.lastIndexOf(foo) should be -1'
- );
- }
-}
-
-runArrayTests('lastIndexOf', LastIndexOfTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/lastObject-test.js b/packages/@ember/-internals/runtime/tests/array/lastObject-test.js
deleted file mode 100644
index 35f52092453..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/lastObject-test.js
+++ /dev/null
@@ -1,31 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-import { get, set } from '@ember/object';
-
-class LastObjectTests extends AbstractTestCase {
- '@test returns last item in enumerable'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
-
- this.assert.equal(get(obj, 'lastObject'), ary[ary.length - 1]);
- }
-
- '@test returns undefined if enumerable is empty'() {
- let obj = this.newObject([]);
-
- this.assert.equal(get(obj, 'lastObject'), undefined);
- }
-
- '@test can not be set'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
-
- this.assert.equal(get(obj, 'lastObject'), ary[ary.length - 1]);
-
- this.assert.throws(function () {
- set(obj, 'lastObject', 'foo!');
- }, /Cannot set read-only property "lastObject" on object/);
- }
-}
-
-runArrayTests('lastObject', LastObjectTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/map-test.js b/packages/@ember/-internals/runtime/tests/array/map-test.js
deleted file mode 100644
index 03e5fc98354..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/map-test.js
+++ /dev/null
@@ -1,68 +0,0 @@
-import { guidFor } from '@ember/-internals/utils';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-import { get } from '@ember/object';
-
-const mapFunc = (item) => (item ? item.toString() : null);
-
-class MapTests extends AbstractTestCase {
- '@test map should iterate over list'() {
- let obj = this.newObject();
- let ary = this.toArray(obj).map(mapFunc);
- let found = [];
-
- found = obj.map(mapFunc);
- this.assert.deepEqual(found, ary, 'mapped arrays should match');
- }
-
- '@test map should iterate over list after mutation'() {
- if (get(this, 'canTestMutation')) {
- this.assert.expect(0);
- return;
- }
-
- let obj = this.newObject();
- let ary = this.toArray(obj).map(mapFunc);
- let found;
-
- found = obj.map(mapFunc);
- this.assert.deepEqual(found, ary, 'items passed during forEach should match');
-
- this.mutate(obj);
- ary = this.toArray(obj).map(mapFunc);
- found = obj.map(mapFunc);
- this.assert.deepEqual(found, ary, 'items passed during forEach should match');
- }
-
- '@test 2nd target parameter'() {
- let obj = this.newObject();
- let target = this;
-
- obj.map(() => {
- // ES6TODO: When transpiled we will end up with "use strict" which disables automatically binding to the global context.
- // Therefore, the following test can never pass in strict mode unless we modify the `map` function implementation to
- // use `Ember.lookup` if target is not specified.
- //
- // equal(guidFor(this), guidFor(global), 'should pass the global object as this if no context');
- });
-
- obj.map(() => {
- this.assert.equal(guidFor(this), guidFor(target), 'should pass target as this if context');
- }, target);
- }
-
- '@test callback params'() {
- let obj = this.newObject();
- let ary = this.toArray(obj);
- let loc = 0;
-
- obj.map((item, idx, enumerable) => {
- this.assert.equal(item, ary[loc], 'item param');
- this.assert.equal(idx, loc, 'idx param');
- this.assert.equal(guidFor(enumerable), guidFor(obj), 'enumerable param');
- loc++;
- });
- }
-}
-
-runArrayTests('map', MapTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/mapBy-test.js b/packages/@ember/-internals/runtime/tests/array/mapBy-test.js
deleted file mode 100644
index 115910327d7..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/mapBy-test.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class MapByTests extends AbstractTestCase {
- '@test get value of each property'() {
- let obj = this.newObject([{ a: 1 }, { a: 2 }]);
- this.assert.equal(obj.mapBy('a').join(''), '12');
- }
-
- '@test should work also through getEach alias'() {
- let obj = this.newObject([{ a: 1 }, { a: 2 }]);
- this.assert.equal(obj.getEach('a').join(''), '12');
- }
-}
-
-runArrayTests('mapBy', MapByTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/objectAt-test.js b/packages/@ember/-internals/runtime/tests/array/objectAt-test.js
deleted file mode 100644
index ff2572b65a8..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/objectAt-test.js
+++ /dev/null
@@ -1,34 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class ObjectAtTests extends AbstractTestCase {
- '@test should return object at specified index'() {
- let expected = newFixture(3);
- let obj = this.newObject(expected);
- let len = expected.length;
-
- for (let idx = 0; idx < len; idx++) {
- this.assert.equal(obj.objectAt(idx), expected[idx], `obj.objectAt(${idx}) should match`);
- }
- }
-
- '@test should return undefined when requesting objects beyond index'() {
- let obj;
-
- obj = this.newObject(newFixture(3));
- this.assert.equal(
- obj.objectAt(obj, 5),
- undefined,
- 'should return undefined for obj.objectAt(5) when len = 3'
- );
-
- obj = this.newObject([]);
- this.assert.equal(
- obj.objectAt(obj, 0),
- undefined,
- 'should return undefined for obj.objectAt(0) when len = 0'
- );
- }
-}
-
-runArrayTests('objectAt', ObjectAtTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/reduce-test.js b/packages/@ember/-internals/runtime/tests/array/reduce-test.js
deleted file mode 100644
index cf549f7ce08..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/reduce-test.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class ReduceTests extends AbstractTestCase {
- '@test collects a summary value from an enumeration'() {
- let obj = this.newObject([1, 2, 3]);
- let res = obj.reduce((previousValue, item) => previousValue + item, 0);
- this.assert.equal(res, 6);
- }
-
- '@test passes index of item to callback'() {
- let obj = this.newObject([1, 2, 3]);
- let res = obj.reduce((previousValue, item, index) => previousValue + index, 0);
- this.assert.equal(res, 3);
- }
-
- '@test passes enumerable object to callback'() {
- let obj = this.newObject([1, 2, 3]);
- let res = obj.reduce((previousValue, item, index, enumerable) => enumerable, 0);
- this.assert.equal(res, obj);
- }
-}
-
-runArrayTests('reduce', ReduceTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/reject-test.js b/packages/@ember/-internals/runtime/tests/array/reject-test.js
deleted file mode 100644
index 01e5741cd17..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/reject-test.js
+++ /dev/null
@@ -1,134 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-import EmberObject from '@ember/object';
-
-class RejectTest extends AbstractTestCase {
- '@test should reject any item that does not meet the condition'() {
- let obj = this.newObject([1, 2, 3, 4]);
- let result;
-
- result = obj.reject((i) => i < 3);
- this.assert.deepEqual(result, [3, 4], 'reject the correct items');
- }
-
- '@test should be the inverse of filter'() {
- let obj = this.newObject([1, 2, 3, 4]);
- let isEven = (i) => i % 2 === 0;
- let filtered, rejected;
-
- filtered = obj.filter(isEven);
- rejected = obj.reject(isEven);
-
- this.assert.deepEqual(filtered, [2, 4], 'filtered evens');
- this.assert.deepEqual(rejected, [1, 3], 'rejected evens');
- }
-}
-
-class RejectByTest extends AbstractTestCase {
- '@test should reject based on object'() {
- let obj, ary;
-
- ary = [{ foo: 'foo', bar: 'BAZ' }, EmberObject.create({ foo: 'foo', bar: 'bar' })];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.rejectBy('foo', 'foo'), [], 'rejectBy(foo)');
- this.assert.deepEqual(obj.rejectBy('bar', 'bar'), [ary[0]], 'rejectBy(bar)');
- }
-
- '@test should include in result if property is false'() {
- let obj, ary;
-
- ary = [{ foo: false, bar: true }, EmberObject.create({ foo: false, bar: false })];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.rejectBy('foo'), ary, 'rejectBy(foo)');
- this.assert.deepEqual(obj.rejectBy('bar'), [ary[1]], 'rejectBy(bar)');
- }
-
- '@test should reject on second argument if provided'() {
- let obj, ary;
-
- ary = [
- { name: 'obj1', foo: 3 },
- EmberObject.create({ name: 'obj2', foo: 2 }),
- { name: 'obj3', foo: 2 },
- EmberObject.create({ name: 'obj4', foo: 3 }),
- ];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.rejectBy('foo', 3), [ary[1], ary[2]], "rejectBy('foo', 3)')");
- }
-
- '@test should correctly reject null second argument'() {
- let obj, ary;
-
- ary = [
- { name: 'obj1', foo: 3 },
- EmberObject.create({ name: 'obj2', foo: null }),
- { name: 'obj3', foo: null },
- EmberObject.create({ name: 'obj4', foo: 3 }),
- ];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.rejectBy('foo', null), [ary[0], ary[3]], "rejectBy('foo', null)')");
- }
-
- '@test should correctly reject undefined second argument'() {
- let obj, ary;
-
- ary = [{ name: 'obj1', foo: 3 }, EmberObject.create({ name: 'obj2', foo: 2 })];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.rejectBy('bar', undefined), [], "rejectBy('bar', undefined)')");
- }
-
- '@test should correctly reject explicit undefined second argument'() {
- let obj, ary;
-
- ary = [
- { name: 'obj1', foo: 3 },
- EmberObject.create({ name: 'obj2', foo: 3 }),
- { name: 'obj3', foo: undefined },
- EmberObject.create({ name: 'obj4', foo: undefined }),
- { name: 'obj5' },
- EmberObject.create({ name: 'obj6' }),
- ];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(
- obj.rejectBy('foo', undefined),
- ary.slice(0, 2),
- "rejectBy('foo', undefined)')"
- );
- }
-
- '@test should match undefined, null, or false properties without second argument'() {
- let obj, ary;
-
- ary = [
- { name: 'obj1', foo: 3 },
- EmberObject.create({ name: 'obj2', foo: 3 }),
- { name: 'obj3', foo: undefined },
- EmberObject.create({ name: 'obj4', foo: undefined }),
- { name: 'obj5' },
- EmberObject.create({ name: 'obj6' }),
- { name: 'obj7', foo: null },
- EmberObject.create({ name: 'obj8', foo: null }),
- { name: 'obj9', foo: false },
- EmberObject.create({ name: 'obj10', foo: false }),
- ];
-
- obj = this.newObject(ary);
-
- this.assert.deepEqual(obj.rejectBy('foo'), ary.slice(2), "rejectBy('foo')')");
- }
-}
-
-runArrayTests('reject', RejectTest);
-runArrayTests('rejectBy', RejectByTest);
diff --git a/packages/@ember/-internals/runtime/tests/array/sortBy-test.js b/packages/@ember/-internals/runtime/tests/array/sortBy-test.js
deleted file mode 100644
index 2cd4bda7e10..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/sortBy-test.js
+++ /dev/null
@@ -1,26 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class SortByTests extends AbstractTestCase {
- '@test sort by value of property'() {
- let obj = this.newObject([{ a: 2 }, { a: 1 }]);
- let sorted = obj.sortBy('a');
-
- this.assert.equal(get(sorted[0], 'a'), 1);
- this.assert.equal(get(sorted[1], 'a'), 2);
- }
-
- '@test supports multiple propertyNames'() {
- let obj = this.newObject([
- { a: 1, b: 2 },
- { a: 1, b: 1 },
- ]);
- let sorted = obj.sortBy('a', 'b');
-
- this.assert.equal(get(sorted[0], 'b'), 1);
- this.assert.equal(get(sorted[1], 'b'), 2);
- }
-}
-
-runArrayTests('sortBy', SortByTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/toArray-test.js b/packages/@ember/-internals/runtime/tests/array/toArray-test.js
deleted file mode 100644
index df6e0793587..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/toArray-test.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class ToArrayTests extends AbstractTestCase {
- '@test toArray should convert to an array'() {
- let obj = this.newObject();
- this.assert.deepEqual(obj.toArray(), this.toArray(obj));
- }
-}
-
-runArrayTests('toArray', ToArrayTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/uniq-test.js b/packages/@ember/-internals/runtime/tests/array/uniq-test.js
deleted file mode 100644
index 59b43afeef2..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/uniq-test.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class UniqTests extends AbstractTestCase {
- '@test should return new instance with duplicates removed'() {
- let before, after, obj, ret;
-
- after = newFixture(3);
- before = [after[0], after[1], after[2], after[1], after[0]];
- obj = this.newObject(before);
- before = obj.toArray(); // in case of set before will be different...
-
- ret = obj.uniq();
- this.assert.deepEqual(this.toArray(ret), after, 'should have removed item');
- this.assert.deepEqual(this.toArray(obj), before, 'should not have changed original');
- }
-
- '@test should return duplicate of same content if no duplicates found'() {
- let item, obj, ret;
- obj = this.newObject(newFixture(3));
- ret = obj.uniq(item);
- this.assert.ok(ret !== obj, 'should not be same object');
- this.assert.deepEqual(this.toArray(ret), this.toArray(obj), 'should be the same content');
- }
-}
-
-runArrayTests('uniq', UniqTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/uniqBy-test.js b/packages/@ember/-internals/runtime/tests/array/uniqBy-test.js
deleted file mode 100644
index 4c8663f0f3a..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/uniqBy-test.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class UniqByTests extends AbstractTestCase {
- '@test should return new instance with duplicates removed'() {
- let numbers = this.newObject([
- { id: 1, value: 'one' },
- { id: 2, value: 'two' },
- { id: 1, value: 'one' },
- ]);
- this.assert.deepEqual(numbers.uniqBy('id'), [
- { id: 1, value: 'one' },
- { id: 2, value: 'two' },
- ]);
- }
-
- '@test supports function as key'() {
- let numbers = this.newObject([
- { id: 1, value: 'boom' },
- { id: 2, value: 'boom' },
- { id: 1, value: 'doom' },
- ]);
-
- let keyFunction = (val) => {
- this.assert.equal(arguments.length, 1);
- return val.value;
- };
-
- this.assert.deepEqual(numbers.uniqBy(keyFunction), [
- { id: 1, value: 'boom' },
- { id: 1, value: 'doom' },
- ]);
- }
-}
-
-runArrayTests('uniqBy', UniqByTests);
diff --git a/packages/@ember/-internals/runtime/tests/array/without-test.js b/packages/@ember/-internals/runtime/tests/array/without-test.js
deleted file mode 100644
index ce0479234a5..00000000000
--- a/packages/@ember/-internals/runtime/tests/array/without-test.js
+++ /dev/null
@@ -1,39 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class WithoutTests extends AbstractTestCase {
- '@test should return new instance with item removed'() {
- let before, after, obj, ret;
-
- before = newFixture(3);
- after = [before[0], before[2]];
- obj = this.newObject(before);
-
- ret = obj.without(before[1]);
- this.assert.deepEqual(this.toArray(ret), after, 'should have removed item');
- this.assert.deepEqual(this.toArray(obj), before, 'should not have changed original');
- }
-
- '@test should remove NaN value'() {
- let before, after, obj, ret;
-
- before = [...newFixture(2), NaN];
- after = [before[0], before[1]];
- obj = this.newObject(before);
-
- ret = obj.without(NaN);
- this.assert.deepEqual(this.toArray(ret), after, 'should have removed item');
- }
-
- '@test should return same instance if object not found'() {
- let item, obj, ret;
-
- item = newFixture(1)[0];
- obj = this.newObject(newFixture(3));
-
- ret = obj.without(item);
- this.assert.equal(ret, obj, 'should be same instance');
- }
-}
-
-runArrayTests('without', WithoutTests);
diff --git a/packages/@ember/-internals/runtime/tests/core/is_array_test.js b/packages/@ember/-internals/runtime/tests/core/is_array_test.js
index 6416fa4d421..e2a98670353 100644
--- a/packages/@ember/-internals/runtime/tests/core/is_array_test.js
+++ b/packages/@ember/-internals/runtime/tests/core/is_array_test.js
@@ -1,5 +1,4 @@
-import { A as emberA, isArray } from '@ember/array';
-import ArrayProxy from '@ember/array/proxy';
+import { isArray } from '@ember/array';
import EmberObject from '@ember/object';
import { window } from '@ember/-internals/browser-environment';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
@@ -19,7 +18,6 @@ moduleFor(
let strangeLength = { length: 'yes' };
let fn = function () {};
let asyncFn = async function () {};
- let arrayProxy = ArrayProxy.create({ content: emberA() });
assert.equal(isArray(numarray), true, '[1,2,3]');
assert.equal(isArray(number), false, '23');
@@ -31,7 +29,6 @@ moduleFor(
assert.equal(isArray(global), false, 'global');
assert.equal(isArray(fn), false, 'function() {}');
assert.equal(isArray(asyncFn), false, 'async function() {}');
- assert.equal(isArray(arrayProxy), true, '[]');
}
'@test Ember.isArray does not trigger proxy assertion when probing for length GH#16495'(
diff --git a/packages/@ember/-internals/runtime/tests/core/is_empty_test.js b/packages/@ember/-internals/runtime/tests/core/is_empty_test.js
index cb8108de479..0e9cbfa7116 100644
--- a/packages/@ember/-internals/runtime/tests/core/is_empty_test.js
+++ b/packages/@ember/-internals/runtime/tests/core/is_empty_test.js
@@ -1,27 +1,9 @@
-import { isEmpty } from '@ember/utils';
-import ArrayProxy from '@ember/array/proxy';
-import ObjectProxy from '@ember/object/proxy';
-import { A as emberA } from '@ember/array';
+// import { isEmpty } from '@ember/utils';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor(
'Ember.isEmpty',
class extends AbstractTestCase {
- ['@test Ember.isEmpty ArrayProxy'](assert) {
- let arrayProxy = ArrayProxy.create({ content: emberA() });
-
- assert.equal(true, isEmpty(arrayProxy), 'for an ArrayProxy that has empty content');
- }
-
- ['@test Ember.isEmpty ObjectProxy ArrayProxy'](assert) {
- let arrayProxy = ArrayProxy.create({ content: emberA([]) });
- let objectProxy = ObjectProxy.create({ content: arrayProxy });
-
- assert.equal(
- true,
- isEmpty(objectProxy),
- 'for an ArrayProxy inside ObjectProxy that has empty content'
- );
- }
+ // TODO: Add real tests here
}
);
diff --git a/packages/@ember/-internals/runtime/tests/helpers/array.js b/packages/@ember/-internals/runtime/tests/helpers/array.js
index 68e4aa22fad..e645d434122 100644
--- a/packages/@ember/-internals/runtime/tests/helpers/array.js
+++ b/packages/@ember/-internals/runtime/tests/helpers/array.js
@@ -1,14 +1,6 @@
-import ArrayProxy from '@ember/array/proxy';
-import EmberArray, { A as emberA } from '@ember/array';
-import MutableArray from '@ember/array/mutable';
import { generateGuid, guidFor } from '@ember/-internals/utils';
-import {
- addArrayObserver,
- removeArrayObserver,
- arrayContentWillChange,
- arrayContentDidChange,
-} from '@ember/-internals/metal';
-import EmberObject, { get, computed } from '@ember/object';
+import { addArrayObserver, removeArrayObserver } from '@ember/-internals/metal';
+import EmberObject from '@ember/object';
import { moduleFor } from 'internal-test-helpers';
export function newFixture(cnt) {
@@ -142,7 +134,7 @@ class AbstractArrayHelper {
class NativeArrayHelpers extends AbstractArrayHelper {
newObject(ary) {
- return emberA(super.newObject(ary));
+ return super.newObject(ary);
}
mutate(obj) {
@@ -150,124 +142,10 @@ class NativeArrayHelpers extends AbstractArrayHelper {
}
}
-class ArrayProxyHelpers extends AbstractArrayHelper {
- newObject(ary) {
- return ArrayProxy.create({ content: emberA(super.newObject(ary)) });
- }
-
- mutate(obj) {
- obj.pushObject(get(obj, 'length') + 1);
- }
-
- toArray(obj) {
- return obj.toArray ? obj.toArray() : obj.slice();
- }
-}
-
-/*
- Implement a basic fake mutable array. This validates that any non-native
- enumerable can impl this API.
-*/
-const TestArray = EmberObject.extend(EmberArray, {
- _content: null,
-
- init() {
- this._content = this._content || [];
- },
-
- // some methods to modify the array so we can test changes. Note that
- // arrays can be modified even if they don't implement MutableArray. The
- // MutableArray is just a standard API for mutation but not required.
- addObject(obj) {
- let idx = this._content.length;
- arrayContentWillChange(this, idx, 0, 1);
- this._content.push(obj);
- arrayContentDidChange(this, idx, 0, 1);
- },
-
- removeFirst() {
- arrayContentWillChange(this, 0, 1, 0);
- this._content.shift();
- arrayContentDidChange(this, 0, 1, 0);
- },
-
- objectAt(idx) {
- return this._content[idx];
- },
-
- length: computed(function () {
- return this._content.length;
- }),
-});
-
-/*
- Implement a basic fake mutable array. This validates that any non-native
- enumerable can impl this API.
-*/
-const TestMutableArray = EmberObject.extend(MutableArray, {
- _content: null,
-
- init(ary = []) {
- this._content = emberA(ary);
- },
-
- replace(idx, amt, objects) {
- let args = objects ? objects.slice() : [];
- let removeAmt = amt;
- let addAmt = args.length;
-
- arrayContentWillChange(this, idx, removeAmt, addAmt);
-
- args.unshift(amt);
- args.unshift(idx);
- this._content.splice.apply(this._content, args);
- arrayContentDidChange(this, idx, removeAmt, addAmt);
- return this;
- },
-
- objectAt(idx) {
- return this._content[idx];
- },
-
- length: computed(function () {
- return this._content.length;
- }),
-
- slice() {
- return this._content.slice();
- },
-});
-
-class MutableArrayHelpers extends NativeArrayHelpers {
- newObject(ary) {
- return TestMutableArray.create(super.newObject(ary));
- }
-
- // allows for testing of the basic enumerable after an internal mutation
- mutate(obj) {
- obj.addObject(this.getFixture(1)[0]);
- }
-}
-
-class EmberArrayHelpers extends MutableArrayHelpers {
- newObject(ary) {
- return TestArray.create(super.newObject(ary));
- }
-}
-
export function runArrayTests(name, Tests, ...types) {
if (types.length > 0) {
types.forEach((type) => {
switch (type) {
- case 'ArrayProxy':
- moduleFor(`ArrayProxy: ${name}`, Tests, ArrayProxyHelpers);
- break;
- case 'EmberArray':
- moduleFor(`EmberArray: ${name}`, Tests, EmberArrayHelpers);
- break;
- case 'MutableArray':
- moduleFor(`MutableArray: ${name}`, Tests, MutableArrayHelpers);
- break;
case 'NativeArray':
moduleFor(`NativeArray: ${name}`, Tests, NativeArrayHelpers);
break;
@@ -276,9 +154,6 @@ export function runArrayTests(name, Tests, ...types) {
}
});
} else {
- moduleFor(`ArrayProxy: ${name}`, Tests, ArrayProxyHelpers);
- moduleFor(`EmberArray: ${name}`, Tests, EmberArrayHelpers);
- moduleFor(`MutableArray: ${name}`, Tests, MutableArrayHelpers);
moduleFor(`NativeArray: ${name}`, Tests, NativeArrayHelpers);
}
}
diff --git a/packages/@ember/-internals/runtime/tests/legacy_1x/mixins/observable/chained_test.js b/packages/@ember/-internals/runtime/tests/legacy_1x/mixins/observable/chained_test.js
deleted file mode 100644
index a650428eee4..00000000000
--- a/packages/@ember/-internals/runtime/tests/legacy_1x/mixins/observable/chained_test.js
+++ /dev/null
@@ -1,80 +0,0 @@
-import { addObserver } from '@ember/-internals/metal';
-import EmberObject, { get, set } from '@ember/object';
-import { A as emberA } from '@ember/array';
-import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-
-/*
- NOTE: This test is adapted from the 1.x series of unit tests. The tests
- are the same except for places where we intend to break the API we instead
- validate that we warn the developer appropriately.
-
- CHANGES FROM 1.6:
-
- * changed obj.set() and obj.get() to Ember.set() and Ember.get()
- * changed obj.addObserver() to addObserver()
-*/
-
-moduleFor(
- 'Ember.Observable - Observing with @each',
- class extends AbstractTestCase {
- async ['@test chained observers on enumerable properties are triggered when the observed property of any item changes'](
- assert
- ) {
- let family = EmberObject.create({ momma: null });
- let momma = EmberObject.create({ children: [] });
-
- let child1 = EmberObject.create({ name: 'Bartholomew' });
- let child2 = EmberObject.create({ name: 'Agnes' });
- let child3 = EmberObject.create({ name: 'Dan' });
- let child4 = EmberObject.create({ name: 'Nancy' });
-
- set(family, 'momma', momma);
- set(momma, 'children', emberA([child1, child2, child3]));
-
- let observerFiredCount = 0;
- addObserver(family, 'momma.children.@each.name', this, function () {
- observerFiredCount++;
- });
-
- observerFiredCount = 0;
-
- for (let i = 0; i < momma.children.length; i++) {
- momma.children[i].set('name', 'Juan');
- await runLoopSettled();
- }
- assert.equal(observerFiredCount, 3, 'observer fired after changing child names');
-
- observerFiredCount = 0;
- get(momma, 'children').pushObject(child4);
- await runLoopSettled();
-
- assert.equal(observerFiredCount, 1, 'observer fired after adding a new item');
-
- observerFiredCount = 0;
- set(child4, 'name', 'Herbert');
- await runLoopSettled();
-
- assert.equal(observerFiredCount, 1, 'observer fired after changing property on new object');
-
- set(momma, 'children', []);
- await runLoopSettled();
-
- observerFiredCount = 0;
- set(child1, 'name', 'Hanna');
- await runLoopSettled();
-
- assert.equal(
- observerFiredCount,
- 0,
- 'observer did not fire after removing changing property on a removed object'
- );
-
- family.destroy();
- momma.destroy();
- child1.destroy();
- child2.destroy();
- child3.destroy();
- child4.destroy();
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/legacy_1x/system/object/base_test.js b/packages/@ember/-internals/runtime/tests/legacy_1x/system/object/base_test.js
deleted file mode 100644
index 46744e51137..00000000000
--- a/packages/@ember/-internals/runtime/tests/legacy_1x/system/object/base_test.js
+++ /dev/null
@@ -1,97 +0,0 @@
-import EmberObject, { get, set } from '@ember/object';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-/*
- NOTE: This test is adapted from the 1.x series of unit tests. The tests
- are the same except for places where we intend to break the API we instead
- validate that we warn the developer appropriately.
-
- CHANGES FROM 1.6:
-
- * Changed get(obj, ) and set(obj, ) to Ember.get() and Ember.set()
- * Removed obj.instanceOf() and obj.kindOf() tests. use obj instanceof Foo
- instead
- * Removed respondsTo() and tryToPerform() tests. Can be brought back in a
- utils package.
- * Removed destroy() test. You can impl yourself but not built in
- * Changed Class.subclassOf() test to Class.detect()
- * Remove broken test for 'superclass' property.
- * Removed obj.didChangeFor()
-*/
-
-// ========================================================================
-// EmberObject Base Tests
-// ========================================================================
-
-let obj, obj1; // global variables
-
-moduleFor(
- 'A new EmberObject instance',
- class extends AbstractTestCase {
- beforeEach() {
- obj = EmberObject.create({
- foo: 'bar',
- total: 12345,
- aMethodThatExists() {},
- aMethodThatReturnsTrue() {
- return true;
- },
- aMethodThatReturnsFoobar() {
- return 'Foobar';
- },
- aMethodThatReturnsFalse() {
- return false;
- },
- });
- }
-
- afterEach() {
- obj = undefined;
- }
-
- ['@test Should return its properties when requested using EmberObject#get'](assert) {
- assert.equal(get(obj, 'foo'), 'bar');
- assert.equal(get(obj, 'total'), 12345);
- }
-
- ['@test Should allow changing of those properties by calling EmberObject#set'](assert) {
- assert.equal(get(obj, 'foo'), 'bar');
- assert.equal(get(obj, 'total'), 12345);
-
- set(obj, 'foo', 'Chunky Bacon');
- set(obj, 'total', 12);
-
- assert.equal(get(obj, 'foo'), 'Chunky Bacon');
- assert.equal(get(obj, 'total'), 12);
- }
- }
-);
-
-moduleFor(
- 'EmberObject superclass and subclasses',
- class extends AbstractTestCase {
- beforeEach() {
- obj = class extends EmberObject {
- method1() {
- return 'hello';
- }
- };
- obj1 = class extends obj {};
- }
-
- afterEach() {
- obj = undefined;
- obj1 = undefined;
- }
-
- ['@test Checking the detect() function on an object and its subclass'](assert) {
- assert.equal(obj.detect(obj1), true);
- assert.equal(obj1.detect(obj), false);
- }
-
- ['@test Checking the detectInstance() function on an object and its subclass'](assert) {
- assert.ok(EmberObject.detectInstance(obj.create()));
- assert.ok(obj.detectInstance(obj.create()));
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/legacy_1x/system/object/concatenated_test.js b/packages/@ember/-internals/runtime/tests/legacy_1x/system/object/concatenated_test.js
deleted file mode 100644
index b20600f4be2..00000000000
--- a/packages/@ember/-internals/runtime/tests/legacy_1x/system/object/concatenated_test.js
+++ /dev/null
@@ -1,130 +0,0 @@
-import EmberObject, { get } from '@ember/object';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-/*
- NOTE: This test is adapted from the 1.x series of unit tests. The tests
- are the same except for places where we intend to break the API we instead
- validate that we warn the developer appropriately.
-
- CHANGES FROM 1.6:
-
- * changed get(obj, ) and set(obj, ) to Ember.get() and Ember.set()
- * converted uses of obj.isEqual() to use deepEqual() test since isEqual is not
- always defined
-*/
-
-function K() {
- return this;
-}
-
-let klass;
-
-moduleFor(
- 'EmberObject Concatenated Properties',
- class extends AbstractTestCase {
- beforeEach() {
- klass = EmberObject.extend({
- concatenatedProperties: ['values', 'functions'],
- values: ['a', 'b', 'c'],
- functions: [K],
- });
- }
-
- ['@test concatenates instances'](assert) {
- let obj = klass.create({
- values: ['d', 'e', 'f'],
- });
-
- let values = get(obj, 'values');
- let expected = ['a', 'b', 'c', 'd', 'e', 'f'];
-
- assert.deepEqual(
- values,
- expected,
- `should concatenate values property (expected: ${expected}, got: ${values})`
- );
- }
-
- ['@test concatenates subclasses'](assert) {
- let subKlass = klass.extend({
- values: ['d', 'e', 'f'],
- });
- let obj = subKlass.create();
-
- let values = get(obj, 'values');
- let expected = ['a', 'b', 'c', 'd', 'e', 'f'];
-
- assert.deepEqual(
- values,
- expected,
- `should concatenate values property (expected: ${expected}, got: ${values})`
- );
- }
-
- ['@test concatenates reopen'](assert) {
- klass.reopen({
- values: ['d', 'e', 'f'],
- });
- let obj = klass.create();
-
- let values = get(obj, 'values');
- let expected = ['a', 'b', 'c', 'd', 'e', 'f'];
-
- assert.deepEqual(
- values,
- expected,
- `should concatenate values property (expected: ${expected}, got: ${values})`
- );
- }
-
- ['@test concatenates mixin'](assert) {
- let mixin = {
- values: ['d', 'e'],
- };
- let subKlass = klass.extend(mixin, {
- values: ['f'],
- });
- let obj = subKlass.create();
-
- let values = get(obj, 'values');
- let expected = ['a', 'b', 'c', 'd', 'e', 'f'];
-
- assert.deepEqual(
- values,
- expected,
- `should concatenate values property (expected: ${expected}, got: ${values})`
- );
- }
-
- ['@test concatenates reopen, subclass, and instance'](assert) {
- klass.reopen({ values: ['d'] });
- let subKlass = klass.extend({ values: ['e'] });
- let obj = subKlass.create({ values: ['f'] });
-
- let values = get(obj, 'values');
- let expected = ['a', 'b', 'c', 'd', 'e', 'f'];
-
- assert.deepEqual(
- values,
- expected,
- `should concatenate values property (expected: ${expected}, got: ${values})`
- );
- }
-
- ['@test concatenates subclasses when the values are functions'](assert) {
- let subKlass = klass.extend({
- functions: K,
- });
- let obj = subKlass.create();
-
- let values = get(obj, 'functions');
- let expected = [K, K];
-
- assert.deepEqual(
- values,
- expected,
- `should concatenate functions property (expected: ${expected}, got: ${values})`
- );
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/mixins/array_test.js b/packages/@ember/-internals/runtime/tests/mixins/array_test.js
deleted file mode 100644
index bf05aa13c7d..00000000000
--- a/packages/@ember/-internals/runtime/tests/mixins/array_test.js
+++ /dev/null
@@ -1,392 +0,0 @@
-import {
- objectAt,
- addObserver,
- addArrayObserver,
- removeArrayObserver,
- arrayContentDidChange,
- arrayContentWillChange,
-} from '@ember/-internals/metal';
-import EmberObject, { get, set, computed, observer as emberObserver } from '@ember/object';
-import EmberArray, { A as emberA } from '@ember/array';
-import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-
-/*
- Implement a basic fake mutable array. This validates that any non-native
- enumerable can impl this API.
-*/
-const TestArray = class extends EmberObject.extend(EmberArray) {
- _content = null;
-
- init() {
- this._content = this._content || [];
- }
-
- // some methods to modify the array so we can test changes. Note that
- // arrays can be modified even if they don't implement MutableArray. The
- // MutableArray is just a standard API for mutation but not required.
- addObject(obj) {
- let idx = this._content.length;
- arrayContentWillChange(this, idx, 0, 1);
- this._content.push(obj);
- arrayContentDidChange(this, idx, 0, 1);
- }
-
- removeFirst() {
- arrayContentWillChange(this, 0, 1, 0);
- this._content.shift();
- arrayContentDidChange(this, 0, 1, 0);
- }
-
- objectAt(idx) {
- return this._content[idx];
- }
-
- get length() {
- return this._content.length;
- }
-};
-
-moduleFor(
- 'Ember.Array',
- class extends AbstractTestCase {
- ['@test the return value of slice has Ember.Array applied'](assert) {
- let x = EmberObject.extend(EmberArray).create({
- length: 0,
- });
- let y = x.slice(1);
- assert.equal(EmberArray.detect(y), true, 'mixin should be applied');
- }
-
- ['@test slice supports negative index arguments'](assert) {
- let testArray = TestArray.create({ _content: [1, 2, 3, 4] });
-
- assert.deepEqual(testArray.slice(-2), [3, 4], 'slice(-2)');
- assert.deepEqual(testArray.slice(-2, -1), [3], 'slice(-2, -1');
- assert.deepEqual(testArray.slice(-2, -2), [], 'slice(-2, -2)');
- assert.deepEqual(testArray.slice(-1, -2), [], 'slice(-1, -2)');
-
- assert.deepEqual(testArray.slice(-4, 1), [1], 'slice(-4, 1)');
- assert.deepEqual(testArray.slice(-4, 5), [1, 2, 3, 4], 'slice(-4, 5)');
- assert.deepEqual(testArray.slice(-4), [1, 2, 3, 4], 'slice(-4)');
-
- assert.deepEqual(testArray.slice(0, -1), [1, 2, 3], 'slice(0, -1)');
- assert.deepEqual(testArray.slice(0, -4), [], 'slice(0, -4)');
- assert.deepEqual(testArray.slice(0, -3), [1], 'slice(0, -3)');
- }
- }
-);
-
-// ..........................................................
-// CONTENT DID CHANGE
-//
-
-class DummyArray extends EmberObject.extend(EmberArray) {
- length = 0;
- objectAt(idx) {
- return 'ITEM-' + idx;
- }
-}
-
-let obj, observer;
-
-// ..........................................................
-// NOTIFY ARRAY OBSERVERS
-//
-
-moduleFor(
- 'mixins/array/arrayContent[Will|Did]Change',
- class extends AbstractTestCase {
- async ['@test should notify observers of []'](assert) {
- obj = DummyArray.extend({
- enumerablePropertyDidChange: emberObserver('[]', function () {
- this._count++;
- }),
- }).create({
- _count: 0,
- });
-
- assert.equal(obj._count, 0, 'should not have invoked yet');
-
- arrayContentWillChange(obj, 0, 1, 1);
- arrayContentDidChange(obj, 0, 1, 1);
- await runLoopSettled();
-
- assert.equal(obj._count, 1, 'should have invoked');
- }
-
- afterEach() {
- obj.destroy();
- obj = undefined;
- }
- }
-);
-
-// ..........................................................
-// NOTIFY CHANGES TO LENGTH
-//
-
-moduleFor(
- 'notify observers of length',
- class extends AbstractTestCase {
- beforeEach(assert) {
- obj = DummyArray.extend({
- lengthDidChange: emberObserver('length', function () {
- this._after++;
- }),
- }).create({
- _after: 0,
- });
-
- assert.equal(obj._after, 0, 'should not have fired yet');
- }
-
- afterEach() {
- obj.destroy();
- obj = undefined;
- }
-
- async ['@test should notify observers when call with no params'](assert) {
- arrayContentWillChange(obj);
- await runLoopSettled();
-
- assert.equal(obj._after, 0);
-
- arrayContentDidChange(obj);
- await runLoopSettled();
-
- assert.equal(obj._after, 1);
- }
-
- // API variation that included items only
- async ['@test should not notify when passed lengths are same'](assert) {
- arrayContentWillChange(obj, 0, 1, 1);
- await runLoopSettled();
-
- assert.equal(obj._after, 0);
-
- arrayContentDidChange(obj, 0, 1, 1);
- await runLoopSettled();
-
- assert.equal(obj._after, 0);
- }
-
- async ['@test should notify when passed lengths are different'](assert) {
- arrayContentWillChange(obj, 0, 1, 2);
- await runLoopSettled();
-
- assert.equal(obj._after, 0);
-
- arrayContentDidChange(obj, 0, 1, 2);
- await runLoopSettled();
-
- assert.equal(obj._after, 1);
- }
- }
-);
-
-// ..........................................................
-// NOTIFY ARRAY OBSERVER
-//
-
-moduleFor(
- 'notify array observers (internal)',
- class extends AbstractTestCase {
- beforeEach(assert) {
- obj = DummyArray.create();
-
- observer = class extends EmberObject {
- arrayWillChange() {
- assert.equal(this._before, null); // should only call once
- this._before = Array.prototype.slice.call(arguments);
- }
-
- arrayDidChange() {
- assert.equal(this._after, null); // should only call once
- this._after = Array.prototype.slice.call(arguments);
- }
- }.create({
- _before: null,
- _after: null,
- });
-
- addArrayObserver(obj, observer, {
- willChange: 'arrayWillChange',
- didChange: 'arrayDidChange',
- });
- }
-
- afterEach() {
- obj = observer = null;
- }
-
- ['@test should notify array observers when called with no params'](assert) {
- arrayContentWillChange(obj);
- assert.deepEqual(observer._before, [obj, 0, -1, -1]);
-
- arrayContentDidChange(obj);
- assert.deepEqual(observer._after, [obj, 0, -1, -1]);
- }
-
- // API variation that included items only
- ['@test should notify when called with same length items'](assert) {
- arrayContentWillChange(obj, 0, 1, 1);
- assert.deepEqual(observer._before, [obj, 0, 1, 1]);
-
- arrayContentDidChange(obj, 0, 1, 1);
- assert.deepEqual(observer._after, [obj, 0, 1, 1]);
- }
-
- ['@test should notify when called with diff length items'](assert) {
- arrayContentWillChange(obj, 0, 2, 1);
- assert.deepEqual(observer._before, [obj, 0, 2, 1]);
-
- arrayContentDidChange(obj, 0, 2, 1);
- assert.deepEqual(observer._after, [obj, 0, 2, 1]);
- }
-
- ['@test removing array observer should disable'](assert) {
- removeArrayObserver(obj, observer, {
- willChange: 'arrayWillChange',
- didChange: 'arrayDidChange',
- });
- arrayContentWillChange(obj);
- assert.deepEqual(observer._before, null);
-
- arrayContentDidChange(obj);
- assert.deepEqual(observer._after, null);
- }
- }
-);
-
-// ..........................................................
-// @each
-//
-
-let ary;
-
-moduleFor(
- 'EmberArray.@each support',
- class extends AbstractTestCase {
- beforeEach() {
- ary = TestArray.create({
- _content: [
- { isDone: true, desc: 'Todo 1' },
- { isDone: false, desc: 'Todo 2' },
- { isDone: true, desc: 'Todo 3' },
- { isDone: false, desc: 'Todo 4' },
- ],
- });
- }
-
- afterEach() {
- ary.destroy();
- ary = null;
- }
-
- async ['@test adding an object should notify (@each.isDone)'](assert) {
- let called = 0;
-
- let observerObject = EmberObject.create({
- wasCalled() {
- called++;
- },
- });
-
- addObserver(ary, '@each.isDone', observerObject, 'wasCalled');
-
- ary.addObject(
- EmberObject.create({
- desc: 'foo',
- isDone: false,
- })
- );
-
- await runLoopSettled();
- assert.equal(called, 1, 'calls observer when object is pushed');
- }
-
- async ['@test using @each to observe arrays that does not return objects raise error'](assert) {
- let called = 0;
-
- let observerObject = EmberObject.create({
- wasCalled() {
- called++;
- },
- });
-
- ary = TestArray.create({
- objectAt(idx) {
- return get(this._content[idx], 'desc');
- },
- });
-
- ary.addObject({
- desc: 'foo',
- isDone: false,
- });
-
- assert.throwsAssertion(() => {
- addObserver(ary, '@each.isDone', observerObject, 'wasCalled');
- }, /When using @each to observe the array/);
-
- await runLoopSettled();
- assert.equal(called, 0, 'not calls observer when object is pushed');
- }
-
- ['@test `objectAt` returns correct object'](assert) {
- let arr = ['first', 'second', 'third', 'fourth'];
- assert.equal(objectAt(arr, 2), 'third');
- assert.equal(objectAt(arr, 4), undefined);
- }
-
- ['@test should be clear caches for computed properties that have dependent keys on arrays that are changed after object initialization'](
- assert
- ) {
- let obj = class extends EmberObject {
- init() {
- super.init(...arguments);
- set(this, 'resources', emberA());
- }
-
- @computed('resources.@each.common')
- get common() {
- return get(objectAt(get(this, 'resources'), 0), 'common');
- }
- }.create();
-
- get(obj, 'resources').pushObject(EmberObject.create({ common: 'HI!' }));
- assert.equal('HI!', get(obj, 'common'));
-
- set(objectAt(get(obj, 'resources'), 0), 'common', 'BYE!');
- assert.equal('BYE!', get(obj, 'common'));
- }
-
- async ['@test observers that contain @each in the path should fire only once the first time they are accessed'](
- assert
- ) {
- let count = 0;
-
- let obj = EmberObject.extend({
- init() {
- this._super(...arguments);
- // Observer does not fire on init
- set(this, 'resources', emberA());
- },
-
- commonDidChange: emberObserver('resources.@each.common', () => count++),
- }).create();
-
- // Observer fires first time when new object is added
- get(obj, 'resources').pushObject(EmberObject.create({ common: 'HI!' }));
- await runLoopSettled();
-
- // Observer fires second time when property on an object is changed
- set(objectAt(get(obj, 'resources'), 0), 'common', 'BYE!');
- await runLoopSettled();
-
- assert.equal(count, 2, 'observers should be called twice');
-
- obj.destroy();
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/mixins/comparable_test.js b/packages/@ember/-internals/runtime/tests/mixins/comparable_test.js
deleted file mode 100644
index 14920e423b2..00000000000
--- a/packages/@ember/-internals/runtime/tests/mixins/comparable_test.js
+++ /dev/null
@@ -1,36 +0,0 @@
-import EmberObject, { get } from '@ember/object';
-import { compare } from '@ember/utils';
-import Comparable from '../../lib/mixins/comparable';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-class Rectangle extends EmberObject.extend(Comparable) {
- length = 0;
- width = 0;
-
- area() {
- return get(this, 'length') * get(this, 'width');
- }
-
- compare(a, b) {
- return compare(a.area(), b.area());
- }
-}
-
-let r1, r2;
-
-moduleFor(
- 'Comparable',
- class extends AbstractTestCase {
- beforeEach() {
- r1 = Rectangle.create({ length: 6, width: 12 });
- r2 = Rectangle.create({ length: 6, width: 13 });
- }
-
- ['@test should be comparable and return the correct result'](assert) {
- assert.equal(Comparable.detect(r1), true);
- assert.equal(compare(r1, r1), 0);
- assert.equal(compare(r1, r2), -1);
- assert.equal(compare(r2, r1), 1);
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/mixins/container_proxy_test.js b/packages/@ember/-internals/runtime/tests/mixins/container_proxy_test.js
deleted file mode 100644
index 1f9cbcfa175..00000000000
--- a/packages/@ember/-internals/runtime/tests/mixins/container_proxy_test.js
+++ /dev/null
@@ -1,70 +0,0 @@
-import { getOwner } from '@ember/-internals/owner';
-import { Container, Registry } from '@ember/-internals/container';
-import ContainerProxy from '../../lib/mixins/container_proxy';
-import EmberObject from '@ember/object';
-import { run, schedule } from '@ember/runloop';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-import { destroy } from '@glimmer/destroyable';
-
-moduleFor(
- '@ember/-internals/runtime/mixins/container_proxy',
- class extends AbstractTestCase {
- beforeEach() {
- this.Owner = EmberObject.extend(ContainerProxy);
- this.instance = this.Owner.create();
-
- this.registry = new Registry();
-
- this.instance.__container__ = new Container(this.registry, {
- owner: this.instance,
- });
- }
-
- ['@test provides ownerInjection helper method'](assert) {
- let result = this.instance.ownerInjection();
-
- assert.equal(getOwner(result), this.instance, 'returns an object with an associated owner');
- }
-
- ['@test actions queue completes before destruction'](assert) {
- assert.expect(1);
-
- this.registry.register(
- 'service:auth',
- class extends EmberObject {
- willDestroy() {
- assert.ok(getOwner(this).lookup('service:auth'), 'can still lookup');
- }
- }
- );
-
- let service = this.instance.lookup('service:auth');
-
- run(() => {
- schedule('actions', service, 'destroy');
- this.instance.destroy();
- });
- }
-
- '@test being destroyed by @ember/destroyable properly destroys the container and created instances'(
- assert
- ) {
- assert.expect(1);
-
- this.registry.register(
- 'service:foo',
- class FooService extends EmberObject {
- willDestroy() {
- assert.ok(true, 'is properly destroyed');
- }
- }
- );
-
- this.instance.lookup('service:foo');
-
- run(() => {
- destroy(this.instance);
- });
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/mixins/mutable_enumerable_test.js b/packages/@ember/-internals/runtime/tests/mixins/mutable_enumerable_test.js
deleted file mode 100644
index 0a8af297f24..00000000000
--- a/packages/@ember/-internals/runtime/tests/mixins/mutable_enumerable_test.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import MutableEnumerable from '@ember/enumerable/mutable';
-import ArrayProxy from '@ember/array/proxy';
-import { A } from '@ember/array';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-moduleFor(
- 'MutableEnumerable',
- class extends AbstractTestCase {
- ['@test should be mixed into A()'](assert) {
- assert.ok(MutableEnumerable.detect(A()));
- }
-
- ['@test should be mixed into ArrayProxy'](assert) {
- assert.ok(MutableEnumerable.detect(ArrayProxy.create()));
- }
- }
-);
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/mixins/promise_proxy_test.js b/packages/@ember/-internals/runtime/tests/mixins/promise_proxy_test.js
deleted file mode 100644
index 99822d559fd..00000000000
--- a/packages/@ember/-internals/runtime/tests/mixins/promise_proxy_test.js
+++ /dev/null
@@ -1,610 +0,0 @@
-import { run } from '@ember/runloop';
-import { get } from '@ember/object';
-import ObjectProxy from '@ember/object/proxy';
-import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
-import EmberRSVP from '../../lib/ext/rsvp';
-import { onerrorDefault } from '../../lib/ext/rsvp';
-import * as RSVP from 'rsvp';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-let ObjectPromiseProxy, proxy;
-
-moduleFor(
- 'Ember.PromiseProxy - ObjectProxy',
- class extends AbstractTestCase {
- beforeEach() {
- ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin);
- }
-
- afterEach() {
- RSVP.on('error', onerrorDefault);
- if (proxy) proxy.destroy();
- proxy = undefined;
- }
-
- ['@test present on ember namespace'](assert) {
- assert.ok(PromiseProxyMixin, 'expected PromiseProxyMixin to exist');
- }
-
- ['@test no promise, invoking then should raise'](assert) {
- proxy = ObjectPromiseProxy.create();
-
- assert.throws(function () {
- proxy.then(
- function () {
- return this;
- },
- function () {
- return this;
- }
- );
- }, new RegExp("PromiseProxy's promise must be set"));
- }
-
- ['@test fulfillment'](assert) {
- let value = {
- firstName: 'stef',
- lastName: 'penner',
- };
-
- let deferred = RSVP.defer();
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- let didFulfillCount = 0;
- let didRejectCount = 0;
-
- proxy.then(
- () => didFulfillCount++,
- () => didRejectCount++
- );
-
- assert.equal(get(proxy, 'content'), undefined, 'expects the proxy to have no content');
- assert.equal(get(proxy, 'reason'), undefined, 'expects the proxy to have no reason');
- assert.equal(
- get(proxy, 'isPending'),
- true,
- 'expects the proxy to indicate that it is loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- false,
- 'expects the proxy to indicate that it is not settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- false,
- 'expects the proxy to indicate that it is not rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
-
- assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
- assert.equal(didRejectCount, 0, 'should not yet have been rejected');
-
- run(deferred, 'resolve', value);
-
- assert.equal(didFulfillCount, 1, 'should have been fulfilled');
- assert.equal(didRejectCount, 0, 'should not have been rejected');
-
- assert.equal(get(proxy, 'content'), value, 'expects the proxy to have content');
- assert.equal(get(proxy, 'reason'), undefined, 'expects the proxy to still have no reason');
- assert.equal(
- get(proxy, 'isPending'),
- false,
- 'expects the proxy to indicate that it is no longer loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- true,
- 'expects the proxy to indicate that it is settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- false,
- 'expects the proxy to indicate that it is not rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- true,
- 'expects the proxy to indicate that it is fulfilled'
- );
-
- run(deferred, 'resolve', value);
-
- assert.equal(didFulfillCount, 1, 'should still have been only fulfilled once');
- assert.equal(didRejectCount, 0, 'should still not have been rejected');
-
- run(deferred, 'reject', value);
-
- assert.equal(didFulfillCount, 1, 'should still have been only fulfilled once');
- assert.equal(didRejectCount, 0, 'should still not have been rejected');
-
- assert.equal(
- get(proxy, 'content'),
- value,
- 'expects the proxy to have still have same content'
- );
- assert.equal(get(proxy, 'reason'), undefined, 'expects the proxy still to have no reason');
- assert.equal(
- get(proxy, 'isPending'),
- false,
- 'expects the proxy to indicate that it is no longer loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- true,
- 'expects the proxy to indicate that it is settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- false,
- 'expects the proxy to indicate that it is not rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- true,
- 'expects the proxy to indicate that it is fulfilled'
- );
-
- // rest of the promise semantics are tested in directly in RSVP
- }
-
- ['@test rejection'](assert) {
- let reason = new Error('failure');
- let deferred = RSVP.defer();
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- let didFulfillCount = 0;
- let didRejectCount = 0;
-
- proxy.then(
- () => didFulfillCount++,
- () => didRejectCount++
- );
-
- assert.equal(get(proxy, 'content'), undefined, 'expects the proxy to have no content');
- assert.equal(get(proxy, 'reason'), undefined, 'expects the proxy to have no reason');
- assert.equal(
- get(proxy, 'isPending'),
- true,
- 'expects the proxy to indicate that it is loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- false,
- 'expects the proxy to indicate that it is not settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- false,
- 'expects the proxy to indicate that it is not rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
-
- assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
- assert.equal(didRejectCount, 0, 'should not yet have been rejected');
-
- run(deferred, 'reject', reason);
-
- assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
- assert.equal(didRejectCount, 1, 'should have been rejected');
-
- assert.equal(get(proxy, 'content'), undefined, 'expects the proxy to have no content');
- assert.equal(get(proxy, 'reason'), reason, 'expects the proxy to have a reason');
- assert.equal(
- get(proxy, 'isPending'),
- false,
- 'expects the proxy to indicate that it is not longer loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- true,
- 'expects the proxy to indicate that it is settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- true,
- 'expects the proxy to indicate that it is rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
-
- run(deferred, 'reject', reason);
-
- assert.equal(didFulfillCount, 0, 'should stll not yet have been fulfilled');
- assert.equal(didRejectCount, 1, 'should still remain rejected');
-
- run(deferred, 'resolve', 1);
-
- assert.equal(didFulfillCount, 0, 'should stll not yet have been fulfilled');
- assert.equal(didRejectCount, 1, 'should still remain rejected');
-
- assert.equal(get(proxy, 'content'), undefined, 'expects the proxy to have no content');
- assert.equal(get(proxy, 'reason'), reason, 'expects the proxy to have a reason');
- assert.equal(
- get(proxy, 'isPending'),
- false,
- 'expects the proxy to indicate that it is not longer loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- true,
- 'expects the proxy to indicate that it is settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- true,
- 'expects the proxy to indicate that it is rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
- }
-
- // https://github.com/emberjs/ember.js/issues/15694
- ['@test rejection without specifying reason'](assert) {
- let deferred = RSVP.defer();
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- let didFulfillCount = 0;
- let didRejectCount = 0;
-
- proxy.then(
- () => didFulfillCount++,
- () => didRejectCount++
- );
-
- assert.equal(get(proxy, 'content'), undefined, 'expects the proxy to have no content');
- assert.equal(get(proxy, 'reason'), undefined, 'expects the proxy to have no reason');
- assert.equal(
- get(proxy, 'isPending'),
- true,
- 'expects the proxy to indicate that it is loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- false,
- 'expects the proxy to indicate that it is not settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- false,
- 'expects the proxy to indicate that it is not rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
-
- assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
- assert.equal(didRejectCount, 0, 'should not yet have been rejected');
-
- run(deferred, 'reject');
-
- assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
- assert.equal(didRejectCount, 1, 'should have been rejected');
-
- assert.equal(get(proxy, 'content'), undefined, 'expects the proxy to have no content');
- assert.equal(get(proxy, 'reason'), undefined, 'expects the proxy to have a reason');
- assert.equal(
- get(proxy, 'isPending'),
- false,
- 'expects the proxy to indicate that it is not longer loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- true,
- 'expects the proxy to indicate that it is settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- true,
- 'expects the proxy to indicate that it is rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
- }
-
- ["@test unhandled rejects still propagate to RSVP.on('error', ...) "](assert) {
- assert.expect(1);
-
- RSVP.on('error', onerror);
- RSVP.off('error', onerrorDefault);
-
- let expectedReason = new Error('failure');
- let deferred = RSVP.defer();
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- proxy.get('promise');
-
- function onerror(reason) {
- assert.equal(reason, expectedReason, 'expected reason');
- }
-
- RSVP.on('error', onerror);
- RSVP.off('error', onerrorDefault);
-
- run(deferred, 'reject', expectedReason);
-
- RSVP.on('error', onerrorDefault);
- RSVP.off('error', onerror);
-
- run(deferred, 'reject', expectedReason);
-
- RSVP.on('error', onerrorDefault);
- RSVP.off('error', onerror);
- }
-
- ['@test should work with promise inheritance'](assert) {
- class PromiseSubclass extends RSVP.Promise {}
-
- proxy = ObjectPromiseProxy.create({
- promise: new PromiseSubclass(() => {}),
- });
-
- assert.ok(proxy.then() instanceof PromiseSubclass, 'promise proxy respected inheritance');
- }
-
- ['@test should reset isFulfilled and isRejected when promise is reset'](assert) {
- let deferred = EmberRSVP.defer();
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- assert.equal(
- get(proxy, 'isPending'),
- true,
- 'expects the proxy to indicate that it is loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- false,
- 'expects the proxy to indicate that it is not settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- false,
- 'expects the proxy to indicate that it is not rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
-
- run(deferred, 'resolve');
-
- assert.equal(
- get(proxy, 'isPending'),
- false,
- 'expects the proxy to indicate that it is no longer loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- true,
- 'expects the proxy to indicate that it is settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- false,
- 'expects the proxy to indicate that it is not rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- true,
- 'expects the proxy to indicate that it is fulfilled'
- );
-
- let anotherDeferred = EmberRSVP.defer();
- proxy.set('promise', anotherDeferred.promise);
-
- assert.equal(
- get(proxy, 'isPending'),
- true,
- 'expects the proxy to indicate that it is loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- false,
- 'expects the proxy to indicate that it is not settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- false,
- 'expects the proxy to indicate that it is not rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
-
- run(anotherDeferred, 'reject');
-
- assert.equal(
- get(proxy, 'isPending'),
- false,
- 'expects the proxy to indicate that it is not longer loading'
- );
- assert.equal(
- get(proxy, 'isSettled'),
- true,
- 'expects the proxy to indicate that it is settled'
- );
- assert.equal(
- get(proxy, 'isRejected'),
- true,
- 'expects the proxy to indicate that it is rejected'
- );
- assert.equal(
- get(proxy, 'isFulfilled'),
- false,
- 'expects the proxy to indicate that it is not fulfilled'
- );
- }
-
- ['@test should have content when isFulfilled is set'](assert) {
- let deferred = EmberRSVP.defer();
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- proxy.addObserver('isFulfilled', () => assert.equal(get(proxy, 'content'), true));
-
- run(deferred, 'resolve', true);
- }
-
- ['@test should have reason when isRejected is set'](assert) {
- let error = new Error('Y U REJECT?!?');
- let deferred = EmberRSVP.defer();
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- proxy.addObserver('isRejected', () => assert.equal(get(proxy, 'reason'), error));
-
- try {
- run(deferred, 'reject', error);
- } catch (e) {
- assert.equal(e, error);
- }
- }
-
- ['@test should not error if promise is resolved after proxy has been destroyed'](assert) {
- let deferred = EmberRSVP.defer();
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- proxy.then(
- () => {},
- () => {}
- );
-
- run(proxy, 'destroy');
-
- run(deferred, 'resolve', true);
-
- assert.ok(
- true,
- 'resolving the promise after the proxy has been destroyed does not raise an error'
- );
- }
-
- ['@test should not error if promise is rejected after proxy has been destroyed'](assert) {
- let deferred = EmberRSVP.defer();
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- proxy.then(
- () => {},
- () => {}
- );
-
- run(proxy, 'destroy');
-
- run(deferred, 'reject', 'some reason');
-
- assert.ok(
- true,
- 'rejecting the promise after the proxy has been destroyed does not raise an error'
- );
- }
-
- ['@test promise chain is not broken if promised is resolved after proxy has been destroyed'](
- assert
- ) {
- let deferred = EmberRSVP.defer();
- let expectedValue = {};
- let receivedValue;
- let didResolveCount = 0;
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- proxy.then(
- (value) => {
- receivedValue = value;
- didResolveCount++;
- },
- () => {}
- );
-
- run(proxy, 'destroy');
-
- run(deferred, 'resolve', expectedValue);
-
- assert.equal(didResolveCount, 1, 'callback called');
- assert.equal(
- receivedValue,
- expectedValue,
- 'passed value is the value the promise was resolved with'
- );
- }
-
- ['@test promise chain is not broken if promised is rejected after proxy has been destroyed'](
- assert
- ) {
- let deferred = EmberRSVP.defer();
- let expectedReason = 'some reason';
- let receivedReason;
- let didRejectCount = 0;
-
- proxy = ObjectPromiseProxy.create({
- promise: deferred.promise,
- });
-
- proxy.then(
- () => {},
- (reason) => {
- receivedReason = reason;
- didRejectCount++;
- }
- );
-
- run(proxy, 'destroy');
-
- run(deferred, 'reject', expectedReason);
-
- assert.equal(didRejectCount, 1, 'callback called');
- assert.equal(
- receivedReason,
- expectedReason,
- 'passed reason is the reason the promise was rejected for'
- );
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/mixins/target_action_support_test.js b/packages/@ember/-internals/runtime/tests/mixins/target_action_support_test.js
deleted file mode 100644
index be9eb69ea7b..00000000000
--- a/packages/@ember/-internals/runtime/tests/mixins/target_action_support_test.js
+++ /dev/null
@@ -1,211 +0,0 @@
-import { context } from '@ember/-internals/environment';
-import EmberObject from '@ember/object';
-import TargetActionSupport from '../../lib/mixins/target_action_support';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-let originalLookup = context.lookup;
-let lookup;
-
-moduleFor(
- 'TargetActionSupport',
- class extends AbstractTestCase {
- beforeEach() {
- context.lookup = lookup = {};
- }
-
- afterEach() {
- context.lookup = originalLookup;
- }
-
- ['@test it should return false if no target or action are specified'](assert) {
- assert.expect(1);
-
- let obj = EmberObject.extend(TargetActionSupport).create();
-
- assert.ok(false === obj.triggerAction(), 'no target or action was specified');
- }
-
- ['@test it should support actions specified as strings'](assert) {
- assert.expect(2);
-
- let obj = EmberObject.extend(TargetActionSupport).create({
- target: EmberObject.create({
- anEvent() {
- assert.ok(true, 'anEvent method was called');
- },
- }),
-
- action: 'anEvent',
- });
-
- assert.ok(true === obj.triggerAction(), 'a valid target and action were specified');
- }
-
- ['@test it should invoke the send() method on objects that implement it'](assert) {
- assert.expect(3);
-
- let obj = EmberObject.extend(TargetActionSupport).create({
- target: EmberObject.create({
- send(evt, context) {
- assert.equal(evt, 'anEvent', 'send() method was invoked with correct event name');
- assert.equal(context, obj, 'send() method was invoked with correct context');
- },
- }),
-
- action: 'anEvent',
- });
-
- assert.ok(true === obj.triggerAction(), 'a valid target and action were specified');
- }
-
- ['@test it should find targets specified using a property path'](assert) {
- assert.expect(2);
-
- let Test = {};
- lookup.Test = Test;
-
- Test.targetObj = EmberObject.create({
- anEvent() {
- assert.ok(true, 'anEvent method was called on global object');
- },
- });
-
- let myObj = EmberObject.extend(TargetActionSupport).create({
- target: 'Test.targetObj',
- action: 'anEvent',
- });
-
- assert.ok(true === myObj.triggerAction(), 'a valid target and action were specified');
- }
-
- ['@test it should use an actionContext object specified as a property on the object'](assert) {
- assert.expect(2);
- let obj = EmberObject.extend(TargetActionSupport).create({
- action: 'anEvent',
- actionContext: {},
- target: EmberObject.create({
- anEvent(ctx) {
- assert.ok(
- obj.actionContext === ctx,
- 'anEvent method was called with the expected context'
- );
- },
- }),
- });
- assert.ok(true === obj.triggerAction(), 'a valid target and action were specified');
- }
-
- ['@test it should find an actionContext specified as a property path'](assert) {
- assert.expect(2);
-
- let Test = {};
- lookup.Test = Test;
- Test.aContext = {};
-
- let obj = EmberObject.extend(TargetActionSupport).create({
- action: 'anEvent',
- actionContext: 'Test.aContext',
- target: EmberObject.create({
- anEvent(ctx) {
- assert.ok(Test.aContext === ctx, 'anEvent method was called with the expected context');
- },
- }),
- });
-
- assert.ok(true === obj.triggerAction(), 'a valid target and action were specified');
- }
-
- ['@test it should use the target specified in the argument'](assert) {
- assert.expect(2);
- let targetObj = EmberObject.create({
- anEvent() {
- assert.ok(true, 'anEvent method was called');
- },
- });
- let obj = EmberObject.extend(TargetActionSupport).create({
- action: 'anEvent',
- });
-
- assert.ok(
- true === obj.triggerAction({ target: targetObj }),
- 'a valid target and action were specified'
- );
- }
-
- ['@test it should use the action specified in the argument'](assert) {
- assert.expect(2);
-
- let obj = EmberObject.extend(TargetActionSupport).create({
- target: EmberObject.create({
- anEvent() {
- assert.ok(true, 'anEvent method was called');
- },
- }),
- });
- assert.ok(
- true === obj.triggerAction({ action: 'anEvent' }),
- 'a valid target and action were specified'
- );
- }
-
- ['@test it should use the actionContext specified in the argument'](assert) {
- assert.expect(2);
- let context = {};
- let obj = EmberObject.extend(TargetActionSupport).create({
- target: EmberObject.create({
- anEvent(ctx) {
- assert.ok(context === ctx, 'anEvent method was called with the expected context');
- },
- }),
- action: 'anEvent',
- });
-
- assert.ok(
- true === obj.triggerAction({ actionContext: context }),
- 'a valid target and action were specified'
- );
- }
-
- ['@test it should allow multiple arguments from actionContext'](assert) {
- assert.expect(3);
- let param1 = 'someParam';
- let param2 = 'someOtherParam';
- let obj = EmberObject.extend(TargetActionSupport).create({
- target: EmberObject.create({
- anEvent(first, second) {
- assert.ok(
- first === param1,
- 'anEvent method was called with the expected first argument'
- );
- assert.ok(
- second === param2,
- 'anEvent method was called with the expected second argument'
- );
- },
- }),
- action: 'anEvent',
- });
-
- assert.ok(
- true === obj.triggerAction({ actionContext: [param1, param2] }),
- 'a valid target and action were specified'
- );
- }
-
- ['@test it should use a null value specified in the actionContext argument'](assert) {
- assert.expect(2);
- let obj = EmberObject.extend(TargetActionSupport).create({
- target: EmberObject.create({
- anEvent(ctx) {
- assert.ok(null === ctx, 'anEvent method was called with the expected context (null)');
- },
- }),
- action: 'anEvent',
- });
- assert.ok(
- true === obj.triggerAction({ actionContext: null }),
- 'a valid target and action were specified'
- );
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/addObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/addObject-test.js
deleted file mode 100644
index 383e15d654b..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/addObject-test.js
+++ /dev/null
@@ -1,86 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class AddObjectTest extends AbstractTestCase {
- '@test should return receiver'() {
- let before = newFixture(3);
- let obj = this.newObject(before);
- this.assert.equal(obj.addObject(before[1]), obj, 'should return receiver');
- }
-
- async '@test [A,B].addObject(C) => [A,B,C] + notify'() {
- let before = newFixture(2);
- let item = newFixture(1)[0];
- let after = [before[0], before[1], item];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.addObject(item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- }
-
- obj.destroy();
- }
-
- async '@test [A,B,C].addObject(A) => [A,B,C] + NO notify'() {
- let before = newFixture(3);
- let after = before;
- let item = before[0];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.addObject(item); // note: item in set
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.validate('[]'), false, 'should NOT have notified []');
- this.assert.equal(observer.validate('@each'), false, 'should NOT have notified @each');
- this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
- }
-
- obj.destroy();
- }
-}
-
-runArrayTests('addObject', AddObjectTest, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/clear-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/clear-test.js
deleted file mode 100644
index 3b9726d8b00..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/clear-test.js
+++ /dev/null
@@ -1,74 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class ClearTests extends AbstractTestCase {
- async '@test [].clear() => [] + notify'() {
- let before = [];
- let after = [];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- // flush observers
- await runLoopSettled();
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.clear(), obj, 'return self');
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.validate('[]'), false, 'should NOT have notified [] once');
- this.assert.equal(observer.validate('@each'), false, 'should NOT have notified @each once');
- this.assert.equal(observer.validate('length'), false, 'should NOT have notified length once');
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [X].clear() => [] + notify'() {
- let obj, before, after, observer;
-
- before = newFixture(1);
- after = [];
- obj = this.newObject(before);
- observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.clear(), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('clear', ClearTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/insertAt-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/insertAt-test.js
deleted file mode 100644
index 1182812c2ab..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/insertAt-test.js
+++ /dev/null
@@ -1,245 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class InsertAtTests extends AbstractTestCase {
- async '@test [].insertAt(0, X) => [X] + notify'() {
- let after = newFixture(1);
- let obj = this.newObject([]);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.insertAt(0, after[0]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] did change once');
- this.assert.equal(
- observer.timesCalled('@each'),
- 0,
- 'should not have notified @each did change once'
- );
- this.assert.equal(
- observer.timesCalled('length'),
- 1,
- 'should have notified length did change once'
- );
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject did change once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject did change once'
- );
-
- obj.destroy();
- }
-
- '@test [].insertAt(200,X) => OUT_OF_RANGE_EXCEPTION exception'() {
- let obj = this.newObject([]);
- let item = newFixture(1)[0];
- expectAssertion(() => obj.insertAt(200, item), /`insertAt` index provided is out of range/);
- }
-
- async '@test [A].insertAt(0, X) => [X,A] + notify'() {
- let item = newFixture(1)[0];
- let before = newFixture(1);
- let after = [item, before[0]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.insertAt(0, item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
-
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-
- async '@test [A].insertAt(1, X) => [A,X] + notify'() {
- let item = newFixture(1)[0];
- let before = newFixture(1);
- let after = [before[0], item];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.insertAt(1, item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
-
- obj.destroy();
- }
-
- '@test [A].insertAt(200,X) => OUT_OF_RANGE exception'() {
- let obj = this.newObject(newFixture(1));
- let that = this;
-
- this.assert.throws(() => obj.insertAt(200, that.newFixture(1)[0]), Error);
- }
-
- async '@test [A,B,C].insertAt(0,X) => [X,A,B,C] + notify'() {
- let item = newFixture(1)[0];
- let before = newFixture(3);
- let after = [item, before[0], before[1], before[2]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.insertAt(0, item);
-
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
-
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].insertAt(1,X) => [A,X,B,C] + notify'() {
- let item = newFixture(1)[0];
- let before = newFixture(3);
- let after = [before[0], item, before[1], before[2]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
- let objectAtCalls = [];
-
- let objectAt = obj.objectAt;
- obj.objectAt = (ix) => {
- objectAtCalls.push(ix);
- return objectAt.call(obj, ix);
- };
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- objectAtCalls.splice(0, objectAtCalls.length);
-
- obj.insertAt(1, item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(objectAtCalls, [], 'objectAt is not called when only inserting items');
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].insertAt(3,X) => [A,B,C,X] + notify'() {
- let item = newFixture(1)[0];
- let before = newFixture(3);
- let after = [before[0], before[1], before[2], item];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.insertAt(3, item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('instertAt', InsertAtTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/popObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/popObject-test.js
deleted file mode 100644
index c5d463b6ff0..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/popObject-test.js
+++ /dev/null
@@ -1,106 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class PopObjectTests extends AbstractTestCase {
- async '@test [].popObject() => [] + returns undefined + NO notify'() {
- let obj = this.newObject([]);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.popObject(), undefined, 'popObject results');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), [], 'post item results');
-
- this.assert.equal(observer.validate('[]'), false, 'should NOT have notified []');
- this.assert.equal(observer.validate('@each'), false, 'should NOT have notified @each');
- this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-
- async '@test [X].popObject() => [] + notify'() {
- let before = newFixture(1);
- let after = [];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- let ret = obj.popObject();
-
- // flush observers
- await runLoopSettled();
-
- this.assert.equal(ret, before[0], 'return object');
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].popObject() => [A,B] + notify'() {
- let before = newFixture(3);
- let after = [before[0], before[1]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- let ret = obj.popObject();
-
- // flush observers
- await runLoopSettled();
-
- this.assert.equal(ret, before[2], 'return object');
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('popObject', PopObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/pushObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/pushObject-test.js
deleted file mode 100644
index b8b55554ff0..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/pushObject-test.js
+++ /dev/null
@@ -1,113 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class PushObjectTests extends AbstractTestCase {
- '@test returns pushed object'() {
- let exp = newFixture(1)[0];
- let obj = this.newObject([]);
-
- this.assert.equal(obj.pushObject(exp), exp, 'should return pushed object');
- }
-
- async '@test [].pushObject(X) => [X] + notify'() {
- let before = [];
- let after = newFixture(1);
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.pushObject(after[0]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].pushObject(X) => [A,B,C,X] + notify'() {
- let before = newFixture(3);
- let item = newFixture(1)[0];
- let after = [before[0], before[1], before[2], item];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.pushObject(item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C,C].pushObject(A) => [A,B,C,C] + notify'() {
- let before = newFixture(3);
- let item = before[2]; // note same object as current tail. should end up twice
- let after = [before[0], before[1], before[2], item];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.pushObject(item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
- this.assert.equal(observer.validate('lastObject'), true, 'should have notified lastObject');
-
- obj.destroy();
- }
-}
-
-runArrayTests('pushObject', PushObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/pushObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/pushObjects-test.js
deleted file mode 100644
index 55a67b4139e..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/pushObjects-test.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import { AbstractTestCase } from 'internal-test-helpers';
-import { runArrayTests } from '../helpers/array';
-
-class PushObjectsTests extends AbstractTestCase {
- '@test should raise exception if not Ember.Enumerable is passed to pushObjects'() {
- let obj = this.newObject([]);
-
- expectAssertion(() => obj.pushObjects('string'));
- }
-}
-
-runArrayTests('pushObjects', PushObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/removeAt-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/removeAt-test.js
deleted file mode 100644
index fedf2195d05..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/removeAt-test.js
+++ /dev/null
@@ -1,217 +0,0 @@
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-import { removeAt } from '@ember/array';
-import { get } from '@ember/object';
-
-class RemoveAtTests extends AbstractTestCase {
- async '@test removeAt([X], 0) => [] + notify'() {
- let before = newFixture(1);
- let after = [];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(removeAt(obj, 0), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- '@test removeAt([], 200) => OUT_OF_RANGE_EXCEPTION exception'() {
- let obj = this.newObject([]);
- expectAssertion(() => removeAt(obj, 200), /`removeAt` index provided is out of range/);
- }
-
- async '@test removeAt([A,B], 0) => [B] + notify'() {
- let before = newFixture(2);
- let after = [before[1]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(removeAt(obj, 0), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
-
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-
- async '@test removeAt([A,B], 1) => [A] + notify'() {
- let before = newFixture(2);
- let after = [before[0]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(removeAt(obj, 1), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
-
- obj.destroy();
- }
-
- async '@test removeAt([A,B,C], 1) => [A,C] + notify'() {
- let before = newFixture(3);
- let after = [before[0], before[2]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(removeAt(obj, 1), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test removeAt([A,B,C,D], 1,2) => [A,D] + notify'() {
- let before = newFixture(4);
- let after = [before[0], before[3]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(removeAt(obj, 1, 2), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C,D].removeAt(1,2) => [A,D] + notify'() {
- let obj, before, after, observer;
-
- before = newFixture(4);
- after = [before[0], before[3]];
- obj = this.newObject(before);
- observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.removeAt(1, 2), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('removeAt', RemoveAtTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/removeObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/removeObject-test.js
deleted file mode 100644
index 86e828e2b09..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/removeObject-test.js
+++ /dev/null
@@ -1,89 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class RemoveObjectTests extends AbstractTestCase {
- '@test should return receiver'() {
- let before = newFixture(3);
- let obj = this.newObject(before);
-
- this.assert.equal(obj.removeObject(before[1]), obj, 'should return receiver');
-
- obj.destroy();
- }
-
- async '@test [A,B,C].removeObject(B) => [A,C] + notify'() {
- let before = newFixture(3);
- let after = [before[0], before[2]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.removeObject(before[1]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
- }
-
- obj.destroy();
- }
-
- async '@test [A,B,C].removeObject(D) => [A,B,C]'() {
- let before = newFixture(3);
- let after = before;
- let item = newFixture(1)[0];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.removeObject(item); // note: item not in set
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.validate('[]'), false, 'should NOT have notified []');
- this.assert.equal(observer.validate('@each'), false, 'should NOT have notified @each');
- this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
- }
-
- obj.destroy();
- }
-}
-
-runArrayTests('removeObject', RemoveObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/removeObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/removeObjects-test.js
deleted file mode 100644
index 13d71267781..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/removeObjects-test.js
+++ /dev/null
@@ -1,238 +0,0 @@
-import { get } from '@ember/object';
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture, newObjectsFixture } from '../helpers/array';
-import { A as emberA } from '@ember/array';
-import { destroy } from '@glimmer/destroyable';
-
-class RemoveObjectsTests extends AbstractTestCase {
- '@test should return receiver'() {
- let before = emberA(newFixture(3));
- let obj = before;
-
- this.assert.equal(obj.removeObjects(before[1]), obj, 'should return receiver');
- }
-
- async '@test [A,B,C].removeObjects([B]) => [A,C] + notify'() {
- let before = emberA(newFixture(3));
- let after = [before[0], before[2]];
- let obj = before;
- let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); // Prime the cache
-
- obj.removeObjects([before[1]]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
- }
-
- destroy(obj);
- }
-
- async '@test [{A},{B},{C}].removeObjects([{B}]) => [{A},{C}] + notify'() {
- let before = emberA(newObjectsFixture(3));
- let after = [before[0], before[2]];
- let obj = before;
- let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); // Prime the cache
-
- obj.removeObjects([before[1]]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
- }
-
- destroy(obj);
- }
-
- async '@test [A,B,C].removeObjects([A,B]) => [C] + notify'() {
- let before = emberA(newFixture(3));
- let after = [before[2]];
- let obj = before;
- let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); // Prime the cache
-
- obj.removeObjects([before[0], before[1]]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
- }
-
- destroy(obj);
- }
-
- async '@test [{A},{B},{C}].removeObjects([{A},{B}]) => [{C}] + notify'() {
- let before = emberA(newObjectsFixture(3));
- let after = [before[2]];
- let obj = before;
- let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); // Prime the cache
-
- obj.removeObjects([before[0], before[1]]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
- }
-
- destroy(obj);
- }
-
- async '@test [A,B,C].removeObjects([A,B,C]) => [] + notify'() {
- let before = emberA(newFixture(3));
- let after = [];
- let obj = before;
- let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); // Prime the cache
-
- obj.removeObjects([before[0], before[1], before[2]]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
- this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject');
- }
-
- destroy(obj);
- }
-
- async '@test [{A},{B},{C}].removeObjects([{A},{B},{C}]) => [] + notify'() {
- let before = emberA(newObjectsFixture(3));
- let after = [];
- let obj = before;
- let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); // Prime the cache
-
- obj.removeObjects(before);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
- this.assert.equal(observer.validate('lastObject'), 1, 'should have notified lastObject');
- }
-
- destroy(obj);
- }
-
- async '@test [A,B,C].removeObjects([D]) => [A,B,C]'() {
- let before = emberA(newFixture(3));
- let after = before;
- let item = newFixture(1)[0];
- let obj = before;
- let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); // Prime the cache
-
- obj.removeObjects([item]); // Note: item not in set
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- if (observer.isEnabled) {
- this.assert.equal(observer.validate('[]'), false, 'should NOT have notified []');
- this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
- }
-
- destroy(obj);
- }
-}
-
-runArrayTests('removeObjects', RemoveObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/replace-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/replace-test.js
deleted file mode 100644
index 7b72f9591ba..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/replace-test.js
+++ /dev/null
@@ -1,261 +0,0 @@
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class ReplaceTests extends AbstractTestCase {
- async "@test [].replace(0,0,'X') => ['X'] + notify"() {
- let exp = newFixture(1);
- let obj = this.newObject([]);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.replace(0, 0, exp);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), exp, 'post item results');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [].replace(0,0,"X") => ["X"] + avoid calling objectAt and notifying fistObject/lastObject when not in cache'() {
- let obj, exp, observer;
- let called = 0;
- exp = newFixture(1);
- obj = this.newObject([]);
- obj.objectAt = function () {
- called++;
- };
- observer = this.newObserver(obj, 'firstObject', 'lastObject');
-
- obj.replace(0, 0, exp);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.equal(
- called,
- 0,
- 'should NOT have called objectAt upon replace when firstObject/lastObject are not cached'
- );
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject since not cached'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject since not cached'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C,D].replace(1,2,X) => [A,X,D] + notify'() {
- let before = newFixture(4);
- let replace = newFixture(1);
- let after = [before[0], replace[0], before[3]];
-
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.replace(1, 2, replace);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C,D].replace(1,2,[X,Y]) => [A,X,Y,D] + notify'() {
- let before = newFixture(4);
- let replace = newFixture(2);
- let after = [before[0], replace[0], replace[1], before[3]];
-
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.replace(1, 2, replace);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B].replace(1,0,[X,Y]) => [A,X,Y,B] + notify'() {
- let before = newFixture(2);
- let replace = newFixture(2);
- let after = [before[0], replace[0], replace[1], before[1]];
-
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.replace(1, 0, replace);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C,D].replace(2,2) => [A,B] + notify'() {
- let before = newFixture(4);
- let after = [before[0], before[1]];
-
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.replace(2, 2);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C,D].replace(-1,1) => [A,B,C] + notify'() {
- let before = newFixture(4);
- let after = [before[0], before[1], before[2]];
-
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.replace(-1, 1);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
-
- obj.destroy();
- }
-
- async '@test Adding object should notify array observer (internal)'() {
- let fixtures = newFixture(4);
- let obj = this.newObject(fixtures);
- let observer = this.newObserver(obj).observeArray(obj);
- let item = newFixture(1)[0];
-
- obj.replace(2, 2, [item]);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(observer._before, [obj, 2, 2, 1], 'before');
- this.assert.deepEqual(observer._after, [obj, 2, 2, 1], 'after');
-
- obj.destroy();
- }
-}
-
-runArrayTests('replace', ReplaceTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/reverseObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/reverseObjects-test.js
deleted file mode 100644
index ee16585bd5b..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/reverseObjects-test.js
+++ /dev/null
@@ -1,40 +0,0 @@
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-import { get } from '@ember/object';
-
-class ReverseObjectsTests extends AbstractTestCase {
- async '@test [A,B,C].reverseObjects() => [] + notify'() {
- let before = newFixture(3);
- let after = [before[2], before[1], before[0]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.reverseObjects(), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 0, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('reverseObjects', ReverseObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/setObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/setObjects-test.js
deleted file mode 100644
index 91385a04737..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/setObjects-test.js
+++ /dev/null
@@ -1,73 +0,0 @@
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-import { get } from '@ember/object';
-
-class SetObjectsTests extends AbstractTestCase {
- async '@test [A,B,C].setObjects([]) = > [] + notify'() {
- let before = newFixture(3);
- let after = [];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.setObjects(after), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].setObjects([D, E, F, G]) = > [D, E, F, G] + notify'() {
- let before = newFixture(3);
- let after = newFixture(4);
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.setObjects(after), obj, 'return self');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('setObjects', SetObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/shiftObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/shiftObject-test.js
deleted file mode 100644
index 39217ecae91..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/shiftObject-test.js
+++ /dev/null
@@ -1,120 +0,0 @@
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { runArrayTests, newFixture } from '../helpers/array';
-import { get } from '@ember/object';
-
-class ShiftObjectTests extends AbstractTestCase {
- async '@test [].shiftObject() => [] + returns undefined + NO notify'() {
- let before = [];
- let after = [];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.shiftObject(), undefined);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(
- observer.validate('[]', undefined, 1),
- false,
- 'should NOT have notified [] once'
- );
- this.assert.equal(
- observer.validate('@each', undefined, 1),
- false,
- 'should NOT have notified @each once'
- );
- this.assert.equal(
- observer.validate('length', undefined, 1),
- false,
- 'should NOT have notified length once'
- );
-
- this.assert.equal(
- observer.validate('firstObject'),
- false,
- 'should NOT have notified firstObject once'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [X].shiftObject() => [] + notify'() {
- let before = newFixture(1);
- let after = [];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.shiftObject(), before[0], 'should return object');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].shiftObject() => [B,C] + notify'() {
- let before = newFixture(3);
- let after = [before[1], before[2]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- this.assert.equal(obj.shiftObject(), before[0], 'should return object');
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
-
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject once'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('shiftObject', ShiftObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObject-test.js
deleted file mode 100644
index 2e94387e2b5..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObject-test.js
+++ /dev/null
@@ -1,114 +0,0 @@
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { get } from '@ember/object';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class UnshiftObjectTests extends AbstractTestCase {
- '@test returns unshifted object'() {
- let obj = this.newObject([]);
- let item = newFixture(1)[0];
-
- this.assert.equal(obj.unshiftObject(item), item, 'should return unshifted object');
- }
-
- async '@test [].unshiftObject(X) => [X] + notify'() {
- let before = [];
- let item = newFixture(1)[0];
- let after = [item];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.unshiftObject(item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].unshiftObject(X) => [X,A,B,C] + notify'() {
- let before = newFixture(3);
- let item = newFixture(1)[0];
- let after = [item, before[0], before[1], before[2]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.unshiftObject(item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
-
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].unshiftObject(A) => [A,A,B,C] + notify'() {
- let before = newFixture(3);
- let item = before[0]; // note same object as current head. should end up twice
- let after = [item, before[0], before[1], before[2]];
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.unshiftObject(item);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(observer.validate('firstObject'), true, 'should have notified firstObject');
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('unshiftObject', UnshiftObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObjects-test.js
deleted file mode 100644
index 44b92473ad3..00000000000
--- a/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObjects-test.js
+++ /dev/null
@@ -1,117 +0,0 @@
-import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-import { get } from '@ember/object';
-import { runArrayTests, newFixture } from '../helpers/array';
-
-class UnshiftObjectsTests extends AbstractTestCase {
- '@test returns receiver'() {
- let obj = this.newObject([]);
- let items = newFixture(3);
-
- this.assert.equal(obj.unshiftObjects(items), obj, 'should return receiver');
- }
-
- async '@test [].unshiftObjects([A,B,C]) => [A,B,C] + notify'() {
- let before = [];
- let items = newFixture(3);
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.unshiftObjects(items);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), items, 'post item results');
- this.assert.equal(get(obj, 'length'), items.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
- this.assert.equal(
- observer.timesCalled('lastObject'),
- 1,
- 'should have notified lastObject once'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].unshiftObjects([X,Y]) => [X,Y,A,B,C] + notify'() {
- let before = newFixture(3);
- let items = newFixture(2);
- let after = items.concat(before);
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.unshiftObjects(items);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
- this.assert.equal(
- observer.timesCalled('firstObject'),
- 1,
- 'should have notified firstObject once'
- );
-
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-
- async '@test [A,B,C].unshiftObjects([A,B]) => [A,B,A,B,C] + notify'() {
- let before = newFixture(3);
- let items = [before[0], before[1]]; // note same object as current head. should end up twice
- let after = items.concat(before);
- let obj = this.newObject(before);
- let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
-
- obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
-
- obj.unshiftObjects(items);
-
- // flush observers
- await runLoopSettled();
-
- this.assert.deepEqual(this.toArray(obj), after, 'post item results');
- this.assert.equal(get(obj, 'length'), after.length, 'length');
-
- this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
- this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
- this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
-
- this.assert.equal(
- observer.validate('firstObject'),
- true,
- 'should NOT have notified firstObject'
- );
- this.assert.equal(
- observer.validate('lastObject'),
- false,
- 'should NOT have notified lastObject'
- );
-
- obj.destroy();
- }
-}
-
-runArrayTests('unshiftObjects', UnshiftObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
diff --git a/packages/@ember/-internals/runtime/tests/system/array_proxy/arranged_content_test.js b/packages/@ember/-internals/runtime/tests/system/array_proxy/arranged_content_test.js
deleted file mode 100644
index fbdfefb902f..00000000000
--- a/packages/@ember/-internals/runtime/tests/system/array_proxy/arranged_content_test.js
+++ /dev/null
@@ -1,278 +0,0 @@
-import { run } from '@ember/runloop';
-import { objectAt } from '@ember/-internals/metal';
-import { computed } from '@ember/object';
-import ArrayProxy from '@ember/array/proxy';
-import { A as emberA } from '@ember/array';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-let array;
-
-moduleFor(
- 'ArrayProxy - arrangedContent',
- class extends AbstractTestCase {
- beforeEach() {
- run(() => {
- array = class extends ArrayProxy {
- @computed('content.[]')
- get arrangedContent() {
- let content = this.get('content');
- return (
- content &&
- emberA(
- content.slice().sort((a, b) => {
- if (a == null) {
- a = -1;
- }
- if (b == null) {
- b = -1;
- }
- return b - a;
- })
- )
- );
- }
- }.create({
- content: emberA([1, 2, 4, 5]),
- });
- });
- }
-
- afterEach() {
- run(() => array.destroy());
- }
-
- ['@test compact - returns arrangedContent without nulls and undefined'](assert) {
- run(() => array.set('content', emberA([1, 3, null, 2, undefined])));
-
- assert.deepEqual(array.compact(), [3, 2, 1]);
- }
-
- ['@test indexOf - returns index of object in arrangedContent'](assert) {
- assert.equal(array.indexOf(4), 1, 'returns arranged index');
- }
-
- ['@test lastIndexOf - returns last index of object in arrangedContent'](assert) {
- array.get('content').pushObject(4);
- assert.equal(array.lastIndexOf(4), 2, 'returns last arranged index');
- }
-
- ['@test objectAt - returns object at index in arrangedContent'](assert) {
- assert.equal(objectAt(array, 1), 4, 'returns object at index');
- }
-
- // Not sure if we need a specific test for it, since it's internal
- ['@test objectAtContent - returns object at index in arrangedContent'](assert) {
- assert.equal(array.objectAtContent(1), 4, 'returns object at index');
- }
-
- ['@test objectsAt - returns objects at indices in arrangedContent'](assert) {
- assert.deepEqual(array.objectsAt([0, 2, 4]), [5, 2, undefined], 'returns objects at indices');
- }
-
- ['@test replace - mutating an arranged ArrayProxy is not allowed']() {
- expectAssertion(() => {
- array.replace(0, 0, [3]);
- }, /Mutating an arranged ArrayProxy is not allowed/);
- }
-
- ['@test replaceContent - does a standard array replace on content'](assert) {
- run(() => array.replaceContent(1, 2, [3]));
- assert.deepEqual(array.get('content'), [1, 3, 5]);
- }
-
- ['@test slice - returns a slice of the arrangedContent'](assert) {
- assert.deepEqual(array.slice(1, 3), [4, 2], 'returns sliced arrangedContent');
- }
-
- ['@test toArray - returns copy of arrangedContent'](assert) {
- assert.deepEqual(array.toArray(), [5, 4, 2, 1]);
- }
-
- ['@test without - returns arrangedContent without object'](assert) {
- assert.deepEqual(array.without(2), [5, 4, 1], 'returns arranged without object');
- }
-
- ['@test lastObject - returns last arranged object'](assert) {
- assert.equal(array.get('lastObject'), 1, 'returns last arranged object');
- }
-
- ['@test firstObject - returns first arranged object'](assert) {
- assert.equal(array.get('firstObject'), 5, 'returns first arranged object');
- }
- }
-);
-
-moduleFor(
- 'ArrayProxy - arrangedContent matching content',
- class extends AbstractTestCase {
- beforeEach() {
- run(function () {
- array = ArrayProxy.create({
- content: emberA([1, 2, 4, 5]),
- });
- });
- }
-
- afterEach() {
- run(function () {
- array.destroy();
- });
- }
-
- ['@test insertAt - inserts object at specified index'](assert) {
- run(function () {
- array.insertAt(2, 3);
- });
- assert.deepEqual(array.get('content'), [1, 2, 3, 4, 5]);
- }
-
- ['@test replace - does a standard array replace'](assert) {
- run(function () {
- array.replace(1, 2, [3]);
- });
- assert.deepEqual(array.get('content'), [1, 3, 5]);
- }
-
- ['@test reverseObjects - reverses content'](assert) {
- run(function () {
- array.reverseObjects();
- });
- assert.deepEqual(array.get('content'), [5, 4, 2, 1]);
- }
- }
-);
-
-moduleFor(
- 'ArrayProxy - arrangedContent with transforms',
- class extends AbstractTestCase {
- beforeEach() {
- run(function () {
- array = class extends ArrayProxy {
- @computed('content.[]')
- get arrangedContent() {
- let content = this.get('content');
- return (
- content &&
- emberA(
- content.slice().sort(function (a, b) {
- if (a == null) {
- a = -1;
- }
- if (b == null) {
- b = -1;
- }
- return b - a;
- })
- )
- );
- }
-
- objectAtContent(idx) {
- let obj = objectAt(this.get('arrangedContent'), idx);
- return obj && obj.toString();
- }
- }.create({
- content: emberA([1, 2, 4, 5]),
- });
- });
- }
-
- afterEach() {
- run(function () {
- array.destroy();
- });
- }
-
- ['@test indexOf - returns index of object in arrangedContent'](assert) {
- assert.equal(array.indexOf('4'), 1, 'returns arranged index');
- }
-
- ['@test lastIndexOf - returns last index of object in arrangedContent'](assert) {
- array.get('content').pushObject(4);
- assert.equal(array.lastIndexOf('4'), 2, 'returns last arranged index');
- }
-
- ['@test objectAt - returns object at index in arrangedContent'](assert) {
- assert.equal(objectAt(array, 1), '4', 'returns object at index');
- }
-
- // Not sure if we need a specific test for it, since it's internal
- ['@test objectAtContent - returns object at index in arrangedContent'](assert) {
- assert.equal(array.objectAtContent(1), '4', 'returns object at index');
- }
-
- ['@test objectsAt - returns objects at indices in arrangedContent'](assert) {
- assert.deepEqual(
- array.objectsAt([0, 2, 4]),
- ['5', '2', undefined],
- 'returns objects at indices'
- );
- }
-
- ['@test slice - returns a slice of the arrangedContent'](assert) {
- assert.deepEqual(array.slice(1, 3), ['4', '2'], 'returns sliced arrangedContent');
- }
-
- ['@test toArray - returns copy of arrangedContent'](assert) {
- assert.deepEqual(array.toArray(), ['5', '4', '2', '1']);
- }
-
- ['@test without - returns arrangedContent without object'](assert) {
- assert.deepEqual(array.without('2'), ['5', '4', '1'], 'returns arranged without object');
- }
-
- ['@test lastObject - returns last arranged object'](assert) {
- assert.equal(array.get('lastObject'), '1', 'returns last arranged object');
- }
-
- ['@test firstObject - returns first arranged object'](assert) {
- assert.equal(array.get('firstObject'), '5', 'returns first arranged object');
- }
- }
-);
-
-moduleFor(
- 'ArrayProxy - with transforms',
- class extends AbstractTestCase {
- beforeEach() {
- run(function () {
- array = class extends ArrayProxy {
- objectAtContent(idx) {
- let obj = objectAt(this.get('arrangedContent'), idx);
- return obj && obj.toString();
- }
- }.create({
- content: emberA([1, 2, 4, 5]),
- });
- });
- }
-
- afterEach() {
- run(function () {
- array.destroy();
- });
- }
-
- ['@test popObject - removes last object in arrangedContent'](assert) {
- let popped = array.popObject();
- assert.equal(popped, '5', 'returns last object');
- assert.deepEqual(array.toArray(), ['1', '2', '4'], 'removes from content');
- }
-
- ['@test removeObject - removes object from content'](assert) {
- array.removeObject('2');
- assert.deepEqual(array.toArray(), ['1', '4', '5']);
- }
-
- ['@test removeObjects - removes objects from content'](assert) {
- array.removeObjects(['2', '4', '6']);
- assert.deepEqual(array.toArray(), ['1', '5']);
- }
-
- ['@test shiftObject - removes from start of arrangedContent'](assert) {
- let shifted = array.shiftObject();
- assert.equal(shifted, '1', 'returns first object');
- assert.deepEqual(array.toArray(), ['2', '4', '5'], 'removes object from content');
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/system/array_proxy/content_change_test.js b/packages/@ember/-internals/runtime/tests/system/array_proxy/content_change_test.js
deleted file mode 100644
index e3af74e2cfb..00000000000
--- a/packages/@ember/-internals/runtime/tests/system/array_proxy/content_change_test.js
+++ /dev/null
@@ -1,86 +0,0 @@
-import { run } from '@ember/runloop';
-import { changeProperties } from '@ember/-internals/metal';
-import { set } from '@ember/object';
-import ArrayProxy from '@ember/array/proxy';
-import { A as emberA } from '@ember/array';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-moduleFor(
- 'ArrayProxy - content change',
- class extends AbstractTestCase {
- ["@test The ArrayProxy doesn't explode when assigned a destroyed object"](assert) {
- let proxy1 = ArrayProxy.create();
- let proxy2 = ArrayProxy.create();
-
- run(() => proxy1.destroy());
-
- set(proxy2, 'content', proxy1);
-
- assert.ok(true, 'No exception was raised');
- }
-
- ['@test should update if content changes while change events are deferred'](assert) {
- let proxy = ArrayProxy.create();
-
- assert.deepEqual(proxy.toArray(), []);
-
- changeProperties(() => {
- proxy.set('content', emberA([1, 2, 3]));
- assert.deepEqual(proxy.toArray(), [1, 2, 3]);
- });
- }
-
- ['@test objectAt recomputes the object cache correctly'](assert) {
- let indexes = [];
-
- let proxy = class extends ArrayProxy {
- objectAtContent(index) {
- indexes.push(index);
- return this.content[index];
- }
- }.create({
- content: emberA([1, 2, 3, 4, 5]),
- });
-
- assert.deepEqual(indexes, []);
- assert.deepEqual(proxy.objectAt(0), 1);
- assert.deepEqual(indexes, [0, 1, 2, 3, 4]);
-
- indexes.length = 0;
- proxy.set('content', emberA([1, 2, 3]));
- assert.deepEqual(proxy.objectAt(0), 1);
- assert.deepEqual(indexes, [0, 1, 2]);
-
- indexes.length = 0;
- proxy.content.replace(2, 0, [4, 5]);
- assert.deepEqual(proxy.objectAt(0), 1);
- assert.deepEqual(proxy.objectAt(1), 2);
- assert.deepEqual(indexes, []);
- assert.deepEqual(proxy.objectAt(2), 4);
- assert.deepEqual(indexes, [2, 3, 4]);
- }
-
- ['@test negative indexes are handled correctly'](assert) {
- let indexes = [];
-
- let proxy = class extends ArrayProxy {
- objectAtContent(index) {
- indexes.push(index);
- return this.content[index];
- }
- }.create({
- content: emberA([1, 2, 3, 4, 5]),
- });
-
- assert.deepEqual(proxy.toArray(), [1, 2, 3, 4, 5]);
-
- indexes.length = 0;
-
- proxy.content.replace(-1, 0, [7]);
- proxy.content.replace(-2, 0, [6]);
-
- assert.deepEqual(proxy.toArray(), [1, 2, 3, 4, 6, 7, 5]);
- assert.deepEqual(indexes, [4, 5, 6]);
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/system/array_proxy/length_test.js b/packages/@ember/-internals/runtime/tests/system/array_proxy/length_test.js
deleted file mode 100644
index 41ce4894f9e..00000000000
--- a/packages/@ember/-internals/runtime/tests/system/array_proxy/length_test.js
+++ /dev/null
@@ -1,254 +0,0 @@
-import ArrayProxy from '@ember/array/proxy';
-import EmberObject, { observer } from '@ember/object';
-import { oneWay as reads, not } from '@ember/object/computed';
-import { A as a } from '@ember/array';
-import { moduleFor, AbstractTestCase, runTask, runLoopSettled } from 'internal-test-helpers';
-import { set, get } from '@ember/object';
-import { createCache, getValue } from '@glimmer/validator';
-
-moduleFor(
- 'Ember.ArrayProxy - content change (length)',
- class extends AbstractTestCase {
- ['@test should update length for null content'](assert) {
- let proxy = ArrayProxy.create({
- content: a([1, 2, 3]),
- });
-
- assert.equal(proxy.get('length'), 3, 'precond - length is 3');
-
- proxy.set('content', null);
-
- assert.equal(proxy.get('length'), 0, 'length updates');
- }
-
- ['@test should update length for null content when there is a computed property watching length'](
- assert
- ) {
- let proxy = class extends ArrayProxy {
- @not('length')
- isEmpty;
- }.create({
- content: a([1, 2, 3]),
- });
-
- assert.equal(proxy.get('length'), 3, 'precond - length is 3');
-
- // Consume computed property that depends on length
- proxy.get('isEmpty');
-
- // update content
- proxy.set('content', null);
-
- assert.equal(proxy.get('length'), 0, 'length updates');
- }
-
- ['@test getting length does not recompute the object cache'](assert) {
- let indexes = [];
-
- let proxy = class extends ArrayProxy {
- objectAtContent(index) {
- indexes.push(index);
- return this.content[index];
- }
- }.create({
- content: a([1, 2, 3, 4, 5]),
- });
-
- assert.equal(get(proxy, 'length'), 5);
- assert.deepEqual(indexes, []);
-
- indexes.length = 0;
- proxy.set('content', a([6, 7, 8]));
- assert.equal(get(proxy, 'length'), 3);
- assert.deepEqual(indexes, []);
-
- indexes.length = 0;
- proxy.content.replace(1, 0, [1, 2, 3]);
- assert.equal(get(proxy, 'length'), 6);
- assert.deepEqual(indexes, []);
- }
-
- '@test accessing length after content set to null'(assert) {
- let obj = ArrayProxy.create({ content: ['foo', 'bar'] });
-
- assert.equal(obj.length, 2, 'precond');
-
- set(obj, 'content', null);
-
- assert.equal(obj.length, 0, 'length is 0 without content');
- assert.deepEqual(obj.content, null, 'content was updated');
- }
-
- '@test accessing length after content set to null in willDestroy'(assert) {
- let obj = class extends ArrayProxy {
- willDestroy() {
- this.set('content', null);
- this._super(...arguments);
- }
- }.create({
- content: ['foo', 'bar'],
- });
-
- assert.equal(obj.length, 2, 'precond');
-
- runTask(() => obj.destroy());
-
- assert.equal(obj.length, 0, 'length is 0 without content');
- assert.deepEqual(obj.content, null, 'content was updated');
- }
-
- '@test setting length to 0'(assert) {
- let obj = ArrayProxy.create({ content: ['foo', 'bar'] });
-
- assert.equal(obj.length, 2, 'precond');
-
- set(obj, 'length', 0);
-
- assert.equal(obj.length, 0, 'length was updated');
- assert.deepEqual(obj.content, [], 'content length was truncated');
- }
-
- '@test setting length to smaller value'(assert) {
- let obj = ArrayProxy.create({ content: ['foo', 'bar'] });
-
- assert.equal(obj.length, 2, 'precond');
-
- set(obj, 'length', 1);
-
- assert.equal(obj.length, 1, 'length was updated');
- assert.deepEqual(obj.content, ['foo'], 'content length was truncated');
- }
-
- '@test setting length to larger value'(assert) {
- let obj = ArrayProxy.create({ content: ['foo', 'bar'] });
-
- assert.equal(obj.length, 2, 'precond');
-
- set(obj, 'length', 3);
-
- assert.equal(obj.length, 3, 'length was updated');
- assert.deepEqual(obj.content, ['foo', 'bar', undefined], 'content length was updated');
- }
-
- '@test setting length after content set to null'(assert) {
- let obj = ArrayProxy.create({ content: ['foo', 'bar'] });
-
- assert.equal(obj.length, 2, 'precond');
-
- set(obj, 'content', null);
- assert.equal(obj.length, 0, 'length was updated');
-
- set(obj, 'length', 0);
- assert.equal(obj.length, 0, 'length is still updated');
- }
-
- '@test setting length to greater than zero'(assert) {
- let obj = ArrayProxy.create({ content: ['foo', 'bar'] });
-
- assert.equal(obj.length, 2, 'precond');
-
- set(obj, 'length', 1);
-
- assert.equal(obj.length, 1, 'length was updated');
- assert.deepEqual(obj.content, ['foo'], 'content length was truncated');
- }
-
- async ['@test array proxy + aliasedProperty complex test'](assert) {
- let aCalled, bCalled, cCalled, dCalled, eCalled;
-
- aCalled = bCalled = cCalled = dCalled = eCalled = 0;
-
- let obj = EmberObject.extend({
- colors: reads('model'),
- length: reads('colors.length'),
-
- a: observer('length', () => aCalled++),
- b: observer('colors.length', () => bCalled++),
- c: observer('colors.content.length', () => cCalled++),
- d: observer('colors.[]', () => dCalled++),
- e: observer('colors.content.[]', () => eCalled++),
- }).create();
-
- // bootstrap aliases
- obj.length;
-
- obj.set(
- 'model',
- ArrayProxy.create({
- content: a(['red', 'yellow', 'blue']),
- })
- );
-
- await runLoopSettled();
-
- assert.equal(obj.get('colors.content.length'), 3);
- assert.equal(obj.get('colors.length'), 3);
- assert.equal(obj.get('length'), 3);
-
- assert.equal(aCalled, 1, 'expected observer `length` to be called ONCE');
- assert.equal(bCalled, 1, 'expected observer `colors.length` to be called ONCE');
- assert.equal(cCalled, 1, 'expected observer `colors.content.length` to be called ONCE');
- assert.equal(dCalled, 1, 'expected observer `colors.[]` to be called ONCE');
- assert.equal(eCalled, 1, 'expected observer `colors.content.[]` to be called ONCE');
-
- obj.get('colors').pushObjects(['green', 'red']);
- await runLoopSettled();
-
- assert.equal(obj.get('colors.content.length'), 5);
- assert.equal(obj.get('colors.length'), 5);
- assert.equal(obj.get('length'), 5);
-
- assert.equal(aCalled, 2, 'expected observer `length` to be called TWICE');
- assert.equal(bCalled, 2, 'expected observer `colors.length` to be called TWICE');
- assert.equal(cCalled, 2, 'expected observer `colors.content.length` to be called TWICE');
- assert.equal(dCalled, 2, 'expected observer `colors.[]` to be called TWICE');
- assert.equal(eCalled, 2, 'expected observer `colors.content.[]` to be called TWICE');
-
- obj.destroy();
- }
-
- async ['@test array proxy length is reactive when accessed normally'](assert) {
- let proxy = ArrayProxy.create({
- content: a([1, 2, 3]),
- });
-
- let lengthCache = createCache(() => proxy.length);
-
- assert.equal(getValue(lengthCache), 3, 'length is correct');
-
- proxy.pushObject(4);
-
- assert.equal(getValue(lengthCache), 4, 'length is correct');
-
- proxy.removeObject(1);
-
- assert.equal(getValue(lengthCache), 3, 'length is correct');
-
- proxy.set('content', []);
-
- assert.equal(getValue(lengthCache), 0, 'length is correct');
- }
-
- async ['@test array proxy length is reactive when accessed using get'](assert) {
- let proxy = ArrayProxy.create({
- content: a([1, 2, 3]),
- });
-
- let lengthCache = createCache(() => get(proxy, 'length'));
-
- assert.equal(getValue(lengthCache), 3, 'length is correct');
-
- proxy.pushObject(4);
-
- assert.equal(getValue(lengthCache), 4, 'length is correct');
-
- proxy.removeObject(1);
-
- assert.equal(getValue(lengthCache), 3, 'length is correct');
-
- proxy.set('content', []);
-
- assert.equal(getValue(lengthCache), 0, 'length is correct');
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/system/array_proxy/watching_and_listening_test.js b/packages/@ember/-internals/runtime/tests/system/array_proxy/watching_and_listening_test.js
deleted file mode 100644
index 8ff87454e2b..00000000000
--- a/packages/@ember/-internals/runtime/tests/system/array_proxy/watching_and_listening_test.js
+++ /dev/null
@@ -1,66 +0,0 @@
-import { peekMeta } from '@ember/-internals/meta';
-import ArrayProxy from '@ember/array/proxy';
-import { A } from '@ember/array';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-function sortedListenersFor(obj, eventName) {
- let listeners = peekMeta(obj).matchingListeners(eventName) || [];
-
- let keys = [];
- for (let i = 0; i < listeners.length; i += 3) {
- keys.push(listeners[i + 1]);
- }
- return keys.sort();
-}
-
-moduleFor(
- 'ArrayProxy - watching and listening',
- class extends AbstractTestCase {
- [`@test setting 'content' adds listeners correctly`](assert) {
- let content = A();
- let proxy = ArrayProxy.create();
-
- assert.deepEqual(sortedListenersFor(content, '@array:before'), []);
- assert.deepEqual(sortedListenersFor(content, '@array:change'), []);
-
- proxy.set('content', content);
-
- assert.deepEqual(sortedListenersFor(content, '@array:before'), [
- '_arrangedContentArrayWillChange',
- ]);
- assert.deepEqual(sortedListenersFor(content, '@array:change'), [
- '_arrangedContentArrayDidChange',
- ]);
- }
-
- [`@test changing 'content' adds and removes listeners correctly`](assert) {
- let content1 = A();
- let content2 = A();
- let proxy = ArrayProxy.create({ content: content1 });
-
- assert.deepEqual(sortedListenersFor(content1, '@array:before'), []);
- assert.deepEqual(sortedListenersFor(content1, '@array:change'), []);
-
- // setup proxy
- proxy.length;
-
- assert.deepEqual(sortedListenersFor(content1, '@array:before'), [
- '_arrangedContentArrayWillChange',
- ]);
- assert.deepEqual(sortedListenersFor(content1, '@array:change'), [
- '_arrangedContentArrayDidChange',
- ]);
-
- proxy.set('content', content2);
-
- assert.deepEqual(sortedListenersFor(content1, '@array:before'), []);
- assert.deepEqual(sortedListenersFor(content1, '@array:change'), []);
- assert.deepEqual(sortedListenersFor(content2, '@array:before'), [
- '_arrangedContentArrayWillChange',
- ]);
- assert.deepEqual(sortedListenersFor(content2, '@array:change'), [
- '_arrangedContentArrayDidChange',
- ]);
- }
- }
-);
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/runtime/tests/system/native_array/a_test.js b/packages/@ember/-internals/runtime/tests/system/native_array/a_test.js
deleted file mode 100644
index e9b72d65d1a..00000000000
--- a/packages/@ember/-internals/runtime/tests/system/native_array/a_test.js
+++ /dev/null
@@ -1,26 +0,0 @@
-import EmberArray from '@ember/array';
-import { A } from '@ember/array';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-moduleFor(
- 'Ember.A',
- class extends AbstractTestCase {
- ['@test Ember.A'](assert) {
- assert.deepEqual(A([1, 2]), [1, 2], 'array values were not be modified');
- assert.deepEqual(A(), [], 'returned an array with no arguments');
- assert.deepEqual(A(null), [], 'returned an array with a null argument');
- assert.ok(EmberArray.detect(A()), 'returned an ember array');
- assert.ok(EmberArray.detect(A([1, 2])), 'returned an ember array');
- }
-
- ['@test new Ember.A'](assert) {
- expectAssertion(() => {
- assert.deepEqual(new A([1, 2]), [1, 2], 'array values were not be modified');
- assert.deepEqual(new A(), [], 'returned an array with no arguments');
- assert.deepEqual(new A(null), [], 'returned an array with a null argument');
- assert.ok(EmberArray.detect(new A()), 'returned an ember array');
- assert.ok(EmberArray.detect(new A([1, 2])), 'returned an ember array');
- });
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/system/native_array/replace_test.js b/packages/@ember/-internals/runtime/tests/system/native_array/replace_test.js
deleted file mode 100644
index dbcdba82f50..00000000000
--- a/packages/@ember/-internals/runtime/tests/system/native_array/replace_test.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import { A } from '@ember/array';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-moduleFor(
- 'NativeArray.replace',
- class extends AbstractTestCase {
- ['@test raises assertion if third argument is not an array']() {
- expectAssertion(function () {
- A([1, 2, 3]).replace(1, 1, '');
- }, 'The third argument to replace needs to be an array.');
- }
-
- ['@test it does not raise an assertion if third parameter is not passed'](assert) {
- assert.deepEqual(A([1, 2, 3]).replace(1, 2), A([1]), 'no assertion raised');
- }
- }
-);
diff --git a/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js b/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js
deleted file mode 100644
index c5279308e64..00000000000
--- a/packages/@ember/-internals/runtime/tests/system/object_proxy_test.js
+++ /dev/null
@@ -1,377 +0,0 @@
-import { DEBUG } from '@glimmer/env';
-import { addObserver, removeObserver } from '@ember/-internals/metal';
-import { computed, get, set, observer } from '@ember/object';
-import ObjectProxy from '@ember/object/proxy';
-import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
-
-moduleFor(
- 'ObjectProxy',
- class extends AbstractTestCase {
- ['@test should not proxy properties passed to create'](assert) {
- let Proxy = class extends ObjectProxy {
- get cp() {
- return this._cp;
- }
- set cp(value) {
- this._cp = value;
- }
- };
- let proxy = Proxy.create({
- prop: 'Foo',
- cp: 'Bar',
- });
-
- assert.equal(get(proxy, 'prop'), 'Foo', 'should not have tried to proxy set');
- assert.equal(proxy._cp, 'Bar', 'should use CP setter');
- }
-
- ['@test should proxy properties to content'](assert) {
- let content = {
- firstName: 'Tom',
- lastName: 'Dale',
- unknownProperty(key) {
- return key + ' unknown';
- },
- };
- let proxy = ObjectProxy.create();
-
- assert.equal(
- get(proxy, 'firstName'),
- undefined,
- 'get on proxy without content should return undefined'
- );
- expectAssertion(() => {
- set(proxy, 'firstName', 'Foo');
- }, /Cannot delegate set\('firstName', Foo\) to the 'content'/i);
-
- set(proxy, 'content', content);
-
- assert.equal(
- get(proxy, 'firstName'),
- 'Tom',
- 'get on proxy with content should forward to content'
- );
- assert.equal(
- get(proxy, 'lastName'),
- 'Dale',
- 'get on proxy with content should forward to content'
- );
- assert.equal(
- get(proxy, 'foo'),
- 'foo unknown',
- 'get on proxy with content should forward to content'
- );
-
- set(proxy, 'lastName', 'Huda');
-
- assert.equal(
- get(content, 'lastName'),
- 'Huda',
- 'content should have new value from set on proxy'
- );
- assert.equal(get(proxy, 'lastName'), 'Huda', 'proxy should have new value from set on proxy');
-
- set(proxy, 'content', { firstName: 'Yehuda', lastName: 'Katz' });
-
- assert.equal(get(proxy, 'firstName'), 'Yehuda', 'proxy should reflect updated content');
- assert.equal(get(proxy, 'lastName'), 'Katz', 'proxy should reflect updated content');
- }
-
- ['@test getting proxied properties with Ember.get should work'](assert) {
- let proxy = ObjectProxy.create({
- content: {
- foo: 'FOO',
- },
- });
-
- assert.equal(get(proxy, 'foo'), 'FOO');
- }
-
- [`@test JSON.stringify doens't assert`](assert) {
- let proxy = ObjectProxy.create({
- content: {
- foo: 'FOO',
- },
- });
-
- assert.equal(JSON.stringify(proxy), JSON.stringify({ content: { foo: 'FOO' } }));
- }
-
- ['@test calling a function on the proxy avoids the assertion'](assert) {
- if (DEBUG) {
- let proxy = class extends ObjectProxy {
- init() {
- super.init();
- if (!this.foobar) {
- this.foobar = function () {
- let content = get(this, 'content');
- return content.foobar.apply(content, []);
- };
- }
- }
- }.create({
- content: {
- foobar() {
- return 'xoxo';
- },
- },
- });
-
- assert.equal(proxy.foobar(), 'xoxo', 'should be able to use a function from a proxy');
- } else {
- assert.expect(0);
- }
- }
-
- [`@test setting a property on the proxy avoids the assertion`](assert) {
- let proxy = ObjectProxy.create({
- toJSON: undefined,
- content: {
- toJSON() {
- return 'hello';
- },
- },
- });
-
- assert.equal(JSON.stringify(proxy), JSON.stringify({ content: 'hello' }));
- }
-
- [`@test setting a property on the proxy's prototype avoids the assertion`](assert) {
- let proxy = ObjectProxy.extend({
- toJSON: null,
- }).create({
- content: {
- toJSON() {
- return 'hello';
- },
- },
- });
-
- assert.equal(JSON.stringify(proxy), JSON.stringify({ content: 'hello' }));
- }
-
- ['@test getting proxied properties with [] should be an error'](assert) {
- if (DEBUG) {
- let proxy = ObjectProxy.create({
- content: {
- foo: 'FOO',
- },
- });
-
- expectAssertion(() => proxy.foo, /\.get\('foo'\)/);
- } else {
- assert.expect(0);
- }
- }
-
- async ['@test should work with watched properties'](assert) {
- let content1 = { firstName: 'Tom', lastName: 'Dale' };
- let content2 = { firstName: 'Yehuda', lastName: 'Katz' };
- let count = 0;
- let last;
-
- let Proxy = class extends ObjectProxy {
- @computed('firstName', 'lastName')
- get fullName() {
- let firstName = this.get('firstName');
- let lastName = this.get('lastName');
-
- if (firstName && lastName) {
- return firstName + ' ' + lastName;
- }
- return firstName || lastName;
- }
- };
-
- let proxy = Proxy.create();
-
- addObserver(proxy, 'fullName', () => {
- last = get(proxy, 'fullName');
- });
-
- // We need separate observers for each property for async observers
- addObserver(proxy, 'firstName', function () {
- count++;
- });
-
- addObserver(proxy, 'lastName', function () {
- count++;
- });
-
- // proxy without content returns undefined
- assert.equal(get(proxy, 'fullName'), undefined);
-
- // setting content causes all watched properties to change
- set(proxy, 'content', content1);
- await runLoopSettled();
-
- // both dependent keys changed
- assert.equal(count, 2);
- assert.equal(last, 'Tom Dale');
-
- // setting property in content causes proxy property to change
- set(content1, 'lastName', 'Huda');
- await runLoopSettled();
-
- assert.equal(count, 3);
- assert.equal(last, 'Tom Huda');
-
- // replacing content causes all watched properties to change
- set(proxy, 'content', content2);
- await runLoopSettled();
-
- // both dependent keys changed
- assert.equal(count, 5);
- assert.equal(last, 'Yehuda Katz');
-
- // setting property in new content
- set(content2, 'firstName', 'Tomhuda');
- await runLoopSettled();
-
- assert.equal(last, 'Tomhuda Katz');
- assert.equal(count, 6);
-
- // setting property in proxy syncs with new content
- set(proxy, 'lastName', 'Katzdale');
- await runLoopSettled();
-
- assert.equal(count, 7);
- assert.equal(last, 'Tomhuda Katzdale');
- assert.equal(get(content2, 'firstName'), 'Tomhuda');
- assert.equal(get(content2, 'lastName'), 'Katzdale');
-
- proxy.destroy();
- }
-
- async ['@test set and get should work with paths'](assert) {
- let content = { foo: { bar: 'baz' } };
- let proxy = ObjectProxy.create({ content });
- let count = 0;
-
- proxy.set('foo.bar', 'hello');
- assert.equal(proxy.get('foo.bar'), 'hello');
- assert.equal(proxy.get('content.foo.bar'), 'hello');
-
- proxy.addObserver('foo.bar', function () {
- count++;
- });
-
- proxy.set('foo.bar', 'bye');
- await runLoopSettled();
-
- assert.equal(count, 1);
- assert.equal(proxy.get('foo.bar'), 'bye');
- assert.equal(proxy.get('content.foo.bar'), 'bye');
-
- proxy.destroy();
- }
-
- async ['@test should transition between watched and unwatched strategies'](assert) {
- let content = { foo: 'foo' };
- let proxy = ObjectProxy.create({ content: content });
- let count = 0;
-
- function observer() {
- count++;
- }
-
- assert.equal(get(proxy, 'foo'), 'foo');
-
- set(content, 'foo', 'bar');
-
- assert.equal(get(proxy, 'foo'), 'bar');
-
- set(proxy, 'foo', 'foo');
-
- assert.equal(get(content, 'foo'), 'foo');
- assert.equal(get(proxy, 'foo'), 'foo');
-
- addObserver(proxy, 'foo', observer);
-
- assert.equal(count, 0);
- assert.equal(get(proxy, 'foo'), 'foo');
-
- set(content, 'foo', 'bar');
- await runLoopSettled();
-
- assert.equal(count, 1);
- assert.equal(get(proxy, 'foo'), 'bar');
-
- set(proxy, 'foo', 'foo');
- await runLoopSettled();
-
- assert.equal(count, 2);
- assert.equal(get(content, 'foo'), 'foo');
- assert.equal(get(proxy, 'foo'), 'foo');
-
- removeObserver(proxy, 'foo', observer);
-
- set(content, 'foo', 'bar');
-
- assert.equal(get(proxy, 'foo'), 'bar');
-
- set(proxy, 'foo', 'foo');
-
- assert.equal(get(content, 'foo'), 'foo');
- assert.equal(get(proxy, 'foo'), 'foo');
- }
-
- ['@test setting `undefined` to a proxied content property should override its existing value'](
- assert
- ) {
- let proxyObject = ObjectProxy.create({
- content: {
- prop: 'emberjs',
- },
- });
- set(proxyObject, 'prop', undefined);
- assert.equal(
- get(proxyObject, 'prop'),
- undefined,
- 'sets the `undefined` value to the proxied content'
- );
- }
-
- ['@test should not throw or deprecate when adding an observer to an ObjectProxy based class'](
- assert
- ) {
- assert.expect(0);
-
- let obj = ObjectProxy.extend({
- observe: observer('foo', function () {}),
- }).create();
-
- obj.destroy();
- }
-
- async '@test custom proxies should be able to notify property changes manually'(assert) {
- let proxy = class extends ObjectProxy {
- locals = { foo: 123 };
-
- unknownProperty(key) {
- return this.locals[key];
- }
-
- setUnknownProperty(key, value) {
- this.locals[key] = value;
- this.notifyPropertyChange(key);
- }
- }.create();
-
- let count = 0;
-
- proxy.addObserver('foo', function () {
- count++;
- });
-
- proxy.set('foo', 456);
- await runLoopSettled();
-
- assert.equal(count, 1);
- assert.equal(proxy.get('foo'), 456);
- assert.equal(proxy.get('locals.foo'), 456);
-
- proxy.destroy();
- }
- }
-);
diff --git a/packages/@ember/-internals/utils/index.ts b/packages/@ember/-internals/utils/index.ts
index 329a6f7e793..54ad627b32c 100644
--- a/packages/@ember/-internals/utils/index.ts
+++ b/packages/@ember/-internals/utils/index.ts
@@ -26,7 +26,6 @@ export { canInvoke } from './lib/invoke';
export { getName, setName } from './lib/name';
export { default as toString } from './lib/to-string';
export { isObject } from './lib/spec';
-export { isProxy, setProxy } from './lib/is_proxy';
export { default as Cache } from './lib/cache';
export {
setupMandatorySetter,
diff --git a/packages/@ember/-internals/utils/lib/is_proxy.ts b/packages/@ember/-internals/utils/lib/is_proxy.ts
deleted file mode 100644
index 443e4c805b0..00000000000
--- a/packages/@ember/-internals/utils/lib/is_proxy.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import type ProxyMixin from '@ember/-internals/runtime/lib/mixins/-proxy';
-import { isObject } from './spec';
-
-const PROXIES = new WeakSet();
-
-export function isProxy(value: unknown): value is ProxyMixin {
- if (isObject(value)) {
- return PROXIES.has(value);
- }
- return false;
-}
-
-export function setProxy(object: ProxyMixin): void {
- if (isObject(object)) {
- PROXIES.add(object);
- }
-}
diff --git a/packages/@ember/-internals/utils/tests/is_proxy_test.js b/packages/@ember/-internals/utils/tests/is_proxy_test.js
deleted file mode 100644
index b367b418ec3..00000000000
--- a/packages/@ember/-internals/utils/tests/is_proxy_test.js
+++ /dev/null
@@ -1,18 +0,0 @@
-import { isProxy, setProxy } from '..';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-moduleFor(
- '@ember/-internals/utils isProxy',
- class extends AbstractTestCase {
- ['@test basic'](assert) {
- let proxy = {};
- setProxy(proxy);
-
- assert.equal(isProxy(proxy), true);
-
- assert.equal(isProxy({}), false);
- assert.equal(isProxy(undefined), false);
- assert.equal(isProxy(null), false);
- }
- }
-);
diff --git a/packages/@ember/-internals/views/index.ts b/packages/@ember/-internals/views/index.ts
index 71a23252628..35e90736704 100644
--- a/packages/@ember/-internals/views/index.ts
+++ b/packages/@ember/-internals/views/index.ts
@@ -18,7 +18,6 @@ export {
export { default as EventDispatcher } from './lib/system/event_dispatcher';
export { default as ComponentLookup } from './lib/component_lookup';
export { default as CoreView } from './lib/views/core_view';
-export { default as ActionSupport } from './lib/mixins/action_support';
export { MUTABLE_CELL } from './lib/compat/attrs';
export { default as ActionManager } from './lib/system/action_manager';
export { default as ViewStates } from './lib/views/states';
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/mixins/action_support.ts b/packages/@ember/-internals/views/lib/mixins/action_support.ts
deleted file mode 100644
index f7d79862587..00000000000
--- a/packages/@ember/-internals/views/lib/mixins/action_support.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- @module ember
-*/
-import { get } from '@ember/-internals/metal';
-import Mixin from '@ember/object/mixin';
-import { assert, inspect } from '@ember/debug';
-
-/**
- @class ActionSupport
- @namespace Ember
- @private
-*/
-interface ActionSupport {
- send(actionName: string, ...args: unknown[]): void;
-}
-const ActionSupport = Mixin.create({
- send(actionName: string, ...args: unknown[]) {
- assert(
- `Attempted to call .send() with the action '${actionName}' on the destroyed object '${this}'.`,
- !this.isDestroying && !this.isDestroyed
- );
-
- let action = this.actions && this.actions[actionName];
-
- if (action) {
- let shouldBubble = action.apply(this, args) === true;
- if (!shouldBubble) {
- return;
- }
- }
-
- let target = get(this, 'target');
- if (target) {
- assert(
- `The \`target\` for ${this} (${target}) does not have a \`send\` method`,
- typeof target.send === 'function'
- );
- target.send(...arguments);
- } else {
- assert(`${inspect(this)} had no action handler for: ${actionName}`, action);
- }
- },
-});
-
-export default ActionSupport;
diff --git a/packages/@ember/-internals/views/lib/system/event_dispatcher.ts b/packages/@ember/-internals/views/lib/system/event_dispatcher.ts
index db3512393fc..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
@@ -350,13 +350,13 @@ export default class EventDispatcher extends EmberObject {
destroy() {
if (this._didSetup === false) {
- return;
+ return this;
}
let rootElement = this._sanitizedRootElement;
if (!rootElement) {
- return;
+ return this;
}
for (let event in this._eventHandlers) {
@@ -365,7 +365,7 @@ export default class EventDispatcher extends EmberObject {
rootElement.classList.remove(ROOT_ELEMENT_CLASS);
- return this._super(...arguments);
+ return super.destroy();
}
toString() {
diff --git a/packages/@ember/-internals/views/lib/views/core_view.ts b/packages/@ember/-internals/views/lib/views/core_view.ts
index c6a7529cf44..3564b84cade 100644
--- a/packages/@ember/-internals/views/lib/views/core_view.ts
+++ b/packages/@ember/-internals/views/lib/views/core_view.ts
@@ -1,7 +1,6 @@
import type { Renderer, View } from '@ember/-internals/glimmer/lib/renderer';
+import { getFactoryFor } from '@ember/-internals/container';
import { inject } from '@ember/-internals/metal';
-import { ActionHandler } from '@ember/-internals/runtime';
-import Evented from '@ember/object/evented';
import { FrameworkObject } from '@ember/object/-internals';
import type { ViewState } from './states';
import states from './states';
@@ -18,13 +17,12 @@ import states from './states';
@namespace Ember
@extends EmberObject
@deprecated Use `Component` instead.
- @uses Evented
- @uses Ember.ActionHandler
@private
*/
-interface CoreView extends Evented, ActionHandler, View {}
-class CoreView extends FrameworkObject.extend(Evented, ActionHandler) {
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type
+interface CoreView extends View {}
+class CoreView extends FrameworkObject {
isView = true;
declare _states: typeof states;
@@ -32,9 +30,6 @@ class CoreView extends FrameworkObject.extend(Evented, ActionHandler) {
declare _state: keyof typeof states;
declare _currentState: ViewState;
- _superTrigger?: Evented['trigger'];
- _superHas?: Evented['has'];
-
/**
If the view is currently inserted into the DOM of a parent view, this
property will point to the parent of the view.
@@ -49,21 +44,17 @@ class CoreView extends FrameworkObject.extend(Evented, ActionHandler) {
init(properties: object | undefined) {
super.init(properties);
- // Handle methods from Evented
- // The native class inheritance will not work for mixins. To work around this,
- // we copy the existing trigger and has methods provided by the mixin and swap in the
- // new ones from our class.
- this._superTrigger = this.trigger;
- this.trigger = this._trigger;
- this._superHas = this.has;
- this.has = this._has;
-
this.parentView ??= null;
this._state = 'preRender';
this._currentState = this._states.preRender;
}
+ get _debugContainerKey() {
+ let factory = getFactoryFor(this);
+ return factory !== undefined && factory.fullName;
+ }
+
@inject('renderer', '-dom')
declare renderer: Renderer;
@@ -82,20 +73,13 @@ class CoreView extends FrameworkObject.extend(Evented, ActionHandler) {
@param name {String}
@private
*/
- // Changed to `trigger` on init
- _trigger(name: string, ...args: any[]) {
- this._superTrigger!(name, ...args);
+ trigger(name: string, ...args: any[]) {
let method = (this as any)[name];
if (typeof method === 'function') {
return method.apply(this, args);
}
}
- // Changed to `has` on init
- _has(name: string) {
- return typeof (this as any)[name] === 'function' || this._superHas!(name);
- }
-
static isViewFactory = true;
}
diff --git a/packages/@ember/-internals/views/lib/views/states.ts b/packages/@ember/-internals/views/lib/views/states.ts
index c9480ffbdf4..0efa46055e9 100644
--- a/packages/@ember/-internals/views/lib/views/states.ts
+++ b/packages/@ember/-internals/views/lib/views/states.ts
@@ -45,7 +45,7 @@ const HAS_ELEMENT: Readonly = Object.freeze({
// Handle events from `Ember.EventDispatcher`
handleEvent(view: Component, eventName: string, event: Event) {
- if (view.has(eventName)) {
+ if (eventName in view) {
// Handler should be able to re-dispatch events, so we don't
// preventDefault or stopPropagation.
return flaggedInstrument(`interaction.${eventName}`, { event, view }, () => {
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/array/-internals.ts b/packages/@ember/array/-internals.ts
deleted file mode 100644
index e25e288d641..00000000000
--- a/packages/@ember/array/-internals.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import type { EmberArrayLike } from '@ember/array';
-
-const EMBER_ARRAYS = new WeakSet();
-
-export function setEmberArray(obj: object) {
- EMBER_ARRAYS.add(obj);
-}
-
-export function isEmberArray(obj: unknown): obj is EmberArrayLike {
- return EMBER_ARRAYS.has(obj as object);
-}
diff --git a/packages/@ember/array/index.ts b/packages/@ember/array/index.ts
index 80e6acda66a..22307c06cb6 100644
--- a/packages/@ember/array/index.ts
+++ b/packages/@ember/array/index.ts
@@ -3,40 +3,24 @@
*/
import { DEBUG } from '@glimmer/env';
import { PROXY_CONTENT } from '@ember/-internals/metal';
-import {
- objectAt,
- replaceInNativeArray,
- replace,
- computed,
- beginPropertyChanges,
- endPropertyChanges,
-} from '@ember/-internals/metal';
-import { get, set } from '@ember/object';
-import Mixin from '@ember/object/mixin';
+import { replace } from '@ember/-internals/metal';
+import { get } from '@ember/object';
import { assert } from '@ember/debug';
-import Enumerable from '@ember/enumerable';
-import MutableEnumerable from '@ember/enumerable/mutable';
-import { compare, typeOf } from '@ember/utils';
-import Observable from '@ember/object/observable';
-import type { MethodNamesOf, MethodParams, MethodReturns } from '@ember/-internals/utility-types';
-import type { ComputedPropertyCallback } from '@ember/-internals/metal';
-import { isEmberArray, setEmberArray } from '@ember/array/-internals';
+import { typeOf } from '@ember/utils';
export { default as makeArray } from './make';
-export type EmberArrayLike = EmberArray | NativeArray;
-
const EMPTY_ARRAY = Object.freeze([] as const);
const identityFunction = (item: T) => item;
export function uniqBy(
- array: T[] | EmberArray,
+ array: T[],
keyOrFunc: string | ((item: T) => unknown) = identityFunction
-): T[] | EmberArray {
+): T[] {
assert(`first argument passed to \`uniqBy\` should be array`, isArray(array));
- let ret = A();
+ let ret: T[] = [];
let seen = new Set();
let getter = typeof keyOrFunc === 'function' ? keyOrFunc : (item: T) => get(item, keyOrFunc);
@@ -51,91 +35,12 @@ export function uniqBy(
return ret;
}
-function iter(key: string): (item: T) => boolean;
-function iter(key: string, value: unknown): (item: T) => boolean;
-function iter(...args: [key: string] | [key: string, value: unknown]) {
- let valueProvided = args.length === 2;
- let [key, value] = args;
-
- return valueProvided
- ? (item: T) => value === get(item, key)
- : (item: T) => Boolean(get(item, key));
-}
-
-function findIndex(
- array: EmberArray,
- predicate: (item: T, index: number, arr: EmberArray) => unknown,
- startAt: number
-): number {
- let len = array.length;
- for (let index = startAt; index < len; index++) {
- // SAFETY: Because we're checking the index this value should always be set.
- let item = objectAt(array, index)!;
- if (predicate(item, index, array)) {
- return index;
- }
- }
- return -1;
-}
-
-function find(
- array: EmberArray,
- callback: (this: Target | null, item: T, index: number, arr: EmberArray) => unknown,
- target: Target | null = null
-) {
- let predicate = callback.bind(target);
- let index = findIndex(array, predicate, 0);
- return index === -1 ? undefined : objectAt(array, index);
-}
-
-function any(
- array: EmberArray,
- callback: (this: Target | null, item: T, index: number, arr: EmberArray) => unknown,
- target: Target | null = null
-) {
- let predicate = callback.bind(target);
- return findIndex(array, predicate, 0) !== -1;
-}
-
-function every(
- array: EmberArray,
- callback: (this: Target | null | void, item: T, index: number, arr: EmberArray) => unknown,
- target: Target | null = null
-) {
- let cb = callback.bind(target);
- let predicate = (item: T, index: number, array: EmberArray) => !cb(item, index, array);
- return findIndex(array, predicate, 0) === -1;
-}
-
-function indexOf(array: EmberArray, val: T, startAt = 0, withNaNCheck: boolean) {
- let len = array.length;
-
- if (startAt < 0) {
- startAt += len;
- }
-
- // SameValueZero comparison (NaN !== NaN)
- let predicate =
- withNaNCheck && val !== val ? (item: T) => item !== item : (item: T) => item === val;
- return findIndex(array, predicate, startAt);
-}
-
-export function removeAt>(
- array: A,
- index: number,
- len?: number
-): A {
+export function removeAt(array: A, index: number, len?: number): A {
assert(`\`removeAt\` index provided is out of range`, index > -1 && index < array.length);
replace(array, index, len ?? 1, EMPTY_ARRAY);
return array;
}
-function insertAt(array: MutableArray, index: number, item: T) {
- assert(`\`insertAt\` index provided is out of range`, index > -1 && index <= array.length);
- replace(array, index, 0, [item]);
- return item;
-}
-
/**
Returns true if the passed object is an array or Array-like.
@@ -150,11 +55,9 @@ function insertAt(array: MutableArray, index: number, item: T) {
```javascript
import { isArray } from '@ember/array';
- import ArrayProxy from '@ember/array/proxy';
isArray(); // false
isArray([]); // true
- isArray(ArrayProxy.create({ content: [] })); // true
```
@method isArray
@@ -164,7 +67,7 @@ function insertAt(array: MutableArray, index: number, item: T) {
@return {Boolean} true if the passed object is an array or Array-like
@public
*/
-export function isArray(obj: unknown): obj is ArrayLike | EmberArray {
+export function isArray(obj: unknown): obj is ArrayLike {
if (DEBUG && typeof obj === 'object' && obj !== null) {
// SAFETY: Property read checks are safe if it's an object
let possibleProxyContent = (obj as any)[PROXY_CONTENT];
@@ -178,7 +81,7 @@ export function isArray(obj: unknown): obj is ArrayLike | EmberArray | EmberArray(this: EmberArray, key: string) {
- return this.map((next) => get(next, key));
-}
-
-// ..........................................................
-// ARRAY
-//
-/**
- This mixin implements Observer-friendly Array-like behavior. It is not a
- concrete implementation, but it can be used up by other classes that want
- to appear like arrays.
-
- For example, ArrayProxy is a concrete class that can be instantiated to
- implement array-like behavior. This class uses the Array Mixin by way of
- the MutableArray mixin, which allows observable changes to be made to the
- underlying array.
-
- This mixin defines methods specifically for collections that provide
- index-ordered access to their contents. When you are designing code that
- needs to accept any kind of Array-like object, you should use these methods
- instead of Array primitives because these will properly notify observers of
- changes to the array.
-
- Although these methods are efficient, they do add a layer of indirection to
- your application so it is a good idea to use them only when you need the
- flexibility of using both true JavaScript arrays and "virtual" arrays such
- as controllers and collections.
-
- You can use the methods defined in this module to access and modify array
- contents in an observable-friendly way. You can also be notified whenever
- the membership of an array changes by using `.observes('myArray.[]')`.
-
- To support `EmberArray` in your own class, you must override two
- primitives to use it: `length()` and `objectAt()`.
-
- @class EmberArray
- @uses Enumerable
- @since Ember 0.9.0
- @public
-*/
-interface EmberArray extends Enumerable {
- /**
- __Required.__ You must implement this method to apply this mixin.
-
- Your array must support the `length` property. Your replace methods should
- set this property whenever it changes.
-
- @property {Number} length
- @public
- */
- length: number;
- /**
- Returns the object at the given `index`. If the given `index` is negative
- or is greater or equal than the array length, returns `undefined`.
-
- This is one of the primitives you must implement to support `EmberArray`.
- If your object supports retrieving the value of an array item using `get()`
- (i.e. `myArray.get(0)`), then you do not need to implement this method
- yourself.
-
- ```javascript
- let arr = ['a', 'b', 'c', 'd'];
-
- arr.objectAt(0); // 'a'
- arr.objectAt(3); // 'd'
- arr.objectAt(-1); // undefined
- arr.objectAt(4); // undefined
- arr.objectAt(5); // undefined
- ```
-
- @method objectAt
- @param {Number} idx The index of the item to return.
- @return {*} item at index or undefined
- @public
- */
- objectAt(idx: number): T | undefined;
- /**
- This returns the objects at the specified indexes, using `objectAt`.
-
- ```javascript
- let arr = ['a', 'b', 'c', 'd'];
-
- arr.objectsAt([0, 1, 2]); // ['a', 'b', 'c']
- arr.objectsAt([2, 3, 4]); // ['c', 'd', undefined]
- ```
-
- @method objectsAt
- @param {Array} indexes An array of indexes of items to return.
- @return {Array}
- @public
- */
- objectsAt(indexes: number[]): Array;
- /**
- This is the handler for the special array content property. If you get
- this property, it will return this. If you set this property to a new
- array, it will replace the current content.
-
- ```javascript
- let peopleToMoon = ['Armstrong', 'Aldrin'];
-
- peopleToMoon.get('[]'); // ['Armstrong', 'Aldrin']
-
- peopleToMoon.set('[]', ['Collins']); // ['Collins']
- peopleToMoon.get('[]'); // ['Collins']
- ```
-
- @property []
- @return this
- @public
- */
- get '[]'(): this;
- set '[]'(newValue: T[] | EmberArray);
- /**
- The first object in the array, or `undefined` if the array is empty.
-
- ```javascript
- let vowels = ['a', 'e', 'i', 'o', 'u'];
- vowels.firstObject; // 'a'
-
- vowels.shiftObject();
- vowels.firstObject; // 'e'
-
- vowels.reverseObjects();
- vowels.firstObject; // 'u'
-
- vowels.clear();
- vowels.firstObject; // undefined
- ```
-
- @property firstObject
- @return {Object | undefined} The first object in the array
- @public
- */
- firstObject: T | undefined;
- /**
- The last object in the array, or `undefined` if the array is empty.
-
- @property lastObject
- @return {Object | undefined} The last object in the array
- @public
- */
- lastObject: T | undefined;
- /**
- Returns a new array that is a slice of the receiver. This implementation
- uses the observable array methods to retrieve the objects for the new
- slice.
-
- ```javascript
- let arr = ['red', 'green', 'blue'];
-
- arr.slice(0); // ['red', 'green', 'blue']
- arr.slice(0, 2); // ['red', 'green']
- arr.slice(1, 100); // ['green', 'blue']
- ```
-
- @method slice
- @param {Number} beginIndex (Optional) index to begin slicing from.
- @param {Number} endIndex (Optional) index to end the slice at (but not included).
- @return {Array} New array with specified slice
- @public
- */
- slice(beginIndex?: number, endIndex?: number): NativeArray;
- /**
- Used to determine the passed object's first occurrence in the array.
- Returns the index if found, -1 if no match is found.
-
- The optional `startAt` argument can be used to pass a starting
- index to search from, effectively slicing the searchable portion
- of the array. If it's negative it will add the array length to
- the startAt value passed in as the index to search from. If less
- than or equal to `-1 * array.length` the entire array is searched.
-
- ```javascript
- let arr = ['a', 'b', 'c', 'd', 'a'];
-
- arr.indexOf('a'); // 0
- arr.indexOf('z'); // -1
- arr.indexOf('a', 2); // 4
- arr.indexOf('a', -1); // 4, equivalent to indexOf('a', 4)
- arr.indexOf('a', -100); // 0, searches entire array
- arr.indexOf('b', 3); // -1
- arr.indexOf('a', 100); // -1
-
- let people = [{ name: 'Zoey' }, { name: 'Bob' }]
- let newPerson = { name: 'Tom' };
- people = [newPerson, ...people, newPerson];
-
- people.indexOf(newPerson); // 0
- people.indexOf(newPerson, 1); // 3
- people.indexOf(newPerson, -4); // 0
- people.indexOf(newPerson, 10); // -1
- ```
-
- @method indexOf
- @param {Object} object the item to search for
- @param {Number} startAt optional starting location to search, default 0
- @return {Number} index or -1 if not found
- @public
- */
- indexOf(object: T, startAt?: number): number;
- /**
- Returns the index of the given `object`'s last occurrence.
-
- - If no `startAt` argument is given, the search starts from
- the last position.
- - If it's greater than or equal to the length of the array,
- the search starts from the last position.
- - If it's negative, it is taken as the offset from the end
- of the array i.e. `startAt + array.length`.
- - If it's any other positive number, will search backwards
- from that index of the array.
-
- Returns -1 if no match is found.
-
- ```javascript
- let arr = ['a', 'b', 'c', 'd', 'a'];
-
- arr.lastIndexOf('a'); // 4
- arr.lastIndexOf('z'); // -1
- arr.lastIndexOf('a', 2); // 0
- arr.lastIndexOf('a', -1); // 4
- arr.lastIndexOf('a', -3); // 0
- arr.lastIndexOf('b', 3); // 1
- arr.lastIndexOf('a', 100); // 4
- ```
-
- @method lastIndexOf
- @param {Object} object the item to search for
- @param {Number} startAt optional starting location to search from
- backwards, defaults to `(array.length - 1)`
- @return {Number} The last index of the `object` in the array or -1
- if not found
- @public
- */
- lastIndexOf(object: T, startAt?: number): number;
- /**
- Iterates through the array, calling the passed function on each
- item. This method corresponds to the `forEach()` method defined in
- JavaScript 1.6.
-
- The callback method you provide should have the following signature (all
- parameters are optional):
-
- ```javascript
- function(item, index, array);
- ```
-
- - `item` is the current item in the iteration.
- - `index` is the current index in the iteration.
- - `array` is the array itself.
-
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as `this` on the context. This is a good way
- to give your iterator function access to the current object.
-
- Example Usage:
-
- ```javascript
- let foods = [
- { name: 'apple', eaten: false },
- { name: 'banana', eaten: false },
- { name: 'carrot', eaten: false }
- ];
-
- foods.forEach((food) => food.eaten = true);
-
- let output = '';
- foods.forEach((item, index, array) =>
- output += `${index + 1}/${array.length} ${item.name}\n`;
- );
- console.log(output);
- // 1/3 apple
- // 2/3 banana
- // 3/3 carrot
- ```
-
- @method forEach
- @param {Function} callback The callback to execute
- @param {Object} [target] The target object to use
- @return {Object} receiver
- @public
- */
- forEach(
- callback: (this: Target, item: T, index: number, arr: this) => void,
- target?: Target
- ): this;
- /**
- Alias for `mapBy`.
-
- Returns the value of the named
- property on all items in the enumeration.
-
- ```javascript
- let people = [{name: 'Joe'}, {name: 'Matt'}];
-
- people.getEach('name');
- // ['Joe', 'Matt'];
-
- people.getEach('nonexistentProperty');
- // [undefined, undefined];
- ```
-
- @method getEach
- @param {String} key name of the property
- @return {Array} The mapped array.
- @public
- */
- getEach(key: K): NativeArray;
- /**
- Sets the value on the named property for each member. This is more
- ergonomic than using other methods defined on this helper. If the object
- implements Observable, the value will be changed to `set(),` otherwise
- it will be set directly. `null` objects are skipped.
-
- ```javascript
- let people = [{name: 'Joe'}, {name: 'Matt'}];
-
- people.setEach('zipCode', '10011');
- // [{name: 'Joe', zipCode: '10011'}, {name: 'Matt', zipCode: '10011'}];
- ```
-
- @method setEach
- @param {String} key The key to set
- @param {Object} value The object to set
- @return {Object} receiver
- @public
- */
- setEach(key: K, value: T[K]): this;
- /**
- Maps all of the items in the enumeration to another value, returning
- a new array. This method corresponds to `map()` defined in JavaScript 1.6.
-
- The callback method you provide should have the following signature (all
- parameters are optional):
-
- ```javascript
- function(item, index, array);
- let arr = [1, 2, 3, 4, 5, 6];
-
- arr.map(element => element * element);
- // [1, 4, 9, 16, 25, 36];
-
- arr.map((element, index) => element + index);
- // [1, 3, 5, 7, 9, 11];
- ```
-
- - `item` is the current item in the iteration.
- - `index` is the current index in the iteration.
- - `array` is the array itself.
-
- It should return the mapped value.
-
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as `this` on the context. This is a good way
- to give your iterator function access to the current object.
-
- @method map
- @param {Function} callback The callback to execute
- @param {Object} [target] The target object to use
- @return {Array} The mapped array.
- @public
- */
- map(
- callback: (this: Target, item: T, index: number, arr: this) => U,
- target?: Target
- ): NativeArray;
- /**
- Similar to map, this specialized function returns the value of the named
- property on all items in the enumeration.
-
- ```javascript
- let people = [{name: 'Joe'}, {name: 'Matt'}];
-
- people.mapBy('name');
- // ['Joe', 'Matt'];
-
- people.mapBy('unknownProperty');
- // [undefined, undefined];
- ```
-
- @method mapBy
- @param {String} key name of the property
- @return {Array} The mapped array.
- @public
- */
- mapBy(key: K): NativeArray;
- mapBy(key: string): NativeArray;
- /**
- Returns a new array with all of the items in the enumeration that the provided
- callback function returns true for. This method corresponds to [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).
-
- The callback method should have the following signature:
-
- ```javascript
- function(item, index, array);
- ```
-
- - `item` is the current item in the iteration.
- - `index` is the current index in the iteration.
- - `array` is the array itself.
-
- All parameters are optional. The function should return `true` to include the item
- in the results, and `false` otherwise.
-
- Example:
-
- ```javascript
- function isAdult(person) {
- return person.age > 18;
- };
-
- let people = Ember.A([{ name: 'John', age: 14 }, { name: 'Joan', age: 45 }]);
-
- people.filter(isAdult); // returns [{ name: 'Joan', age: 45 }];
- ```
-
- Note that in addition to a callback, you can pass an optional target object
- that will be set as `this` on the context. This is a good way to give your
- iterator function access to the current object. For example:
-
- ```javascript
- function isAdultAndEngineer(person) {
- return person.age > 18 && this.engineering;
- }
-
- class AdultsCollection {
- engineering = false;
-
- constructor(opts = {}) {
- super(...arguments);
-
- this.engineering = opts.engineering;
- this.people = Ember.A([{ name: 'John', age: 14 }, { name: 'Joan', age: 45 }]);
- }
- }
-
- let collection = new AdultsCollection({ engineering: true });
- collection.people.filter(isAdultAndEngineer, { target: collection });
- ```
-
- @method filter
- @param {Function} callback The callback to execute
- @param {Object} [target] The target object to use
- @return {Array} A filtered array.
- @public
- */
- filter(
- callback: (this: Target, item: T, index: number, arr: this) => unknown,
- target?: Target
- ): NativeArray;
- /**
- Returns an array with all of the items in the enumeration where the passed
- function returns false. This method is the inverse of filter().
-
- The callback method you provide should have the following signature (all
- parameters are optional):
-
- ```javascript
- function(item, index, array);
- ```
-
- - *item* is the current item in the iteration.
- - *index* is the current index in the iteration
- - *array* is the array itself.
-
- It should return a falsey value to include the item in the results.
-
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as "this" on the context. This is a good way
- to give your iterator function access to the current object.
-
- Example Usage:
-
- ```javascript
- const food = [
- { food: 'apple', isFruit: true },
- { food: 'bread', isFruit: false },
- { food: 'banana', isFruit: true }
- ];
- const nonFruits = food.reject(function(thing) {
- return thing.isFruit;
- }); // [{food: 'bread', isFruit: false}]
- ```
-
- @method reject
- @param {Function} callback The callback to execute
- @param {Object} [target] The target object to use
- @return {Array} A rejected array.
- @public
- */
- reject(
- callback: (this: Target, item: T, index: number, arr: this) => unknown,
- target?: Target
- ): NativeArray;
- /**
- Filters the array by the property and an optional value. If a value is given, it returns
- the items that have said value for the property. If not, it returns all the items that
- have a truthy value for the property.
-
- Example Usage:
-
- ```javascript
- let things = Ember.A([{ food: 'apple', isFruit: true }, { food: 'beans', isFruit: false }]);
-
- things.filterBy('food', 'beans'); // [{ food: 'beans', isFruit: false }]
- things.filterBy('isFruit'); // [{ food: 'apple', isFruit: true }]
- ```
-
- @method filterBy
- @param {String} key the property to test
- @param {*} [value] optional value to test against.
- @return {Array} filtered array
- @public
- */
- filterBy(key: string, value?: unknown): NativeArray;
- /**
- Returns an array with the items that do not have truthy values for the provided key.
- You can pass an optional second argument with a target value to reject for the key.
- Otherwise this will reject objects where the provided property evaluates to false.
-
- Example Usage:
-
- ```javascript
- let food = [
- { name: "apple", isFruit: true },
- { name: "carrot", isFruit: false },
- { name: "bread", isFruit: false },
- ];
- food.rejectBy('isFruit'); // [{ name: "carrot", isFruit: false }, { name: "bread", isFruit: false }]
- food.rejectBy('name', 'carrot'); // [{ name: "apple", isFruit: true }}, { name: "bread", isFruit: false }]
- ```
-
- @method rejectBy
- @param {String} key the property to test
- @param {*} [value] optional value to test against.
- @return {Array} rejected array
- @public
- */
- rejectBy(key: string, value?: unknown): NativeArray;
- /**
- Returns the first item in the array for which the callback returns true.
- This method is similar to the `find()` method defined in ECMAScript 2015.
-
- The callback method you provide should have the following signature (all
- parameters are optional):
-
- ```javascript
- function(item, index, array);
- ```
-
- - `item` is the current item in the iteration.
- - `index` is the current index in the iteration.
- - `array` is the array itself.
-
- It should return the `true` to include the item in the results, `false`
- otherwise.
-
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as `this` on the context. This is a good way
- to give your iterator function access to the current object.
-
- Example Usage:
-
- ```javascript
- let users = [
- { id: 1, name: 'Yehuda' },
- { id: 2, name: 'Tom' },
- { id: 3, name: 'Melanie' },
- { id: 4, name: 'Leah' }
- ];
-
- users.find((user) => user.name == 'Tom'); // [{ id: 2, name: 'Tom' }]
- users.find(({ id }) => id == 3); // [{ id: 3, name: 'Melanie' }]
- ```
-
- @method find
- @param {Function} callback The callback to execute
- @param {Object} [target] The target object to use
- @return {Object} Found item or `undefined`.
- @public
- */
- find(
- predicate: (this: void, value: T, index: number, obj: T[]) => value is S,
- thisArg?: Target
- ): S | undefined;
- find(
- callback: (this: Target, item: T, index: number, arr: this) => unknown,
- target?: Target
- ): T | undefined;
- /**
- Returns the first item with a property matching the passed value. You
- can pass an optional second argument with the target value. Otherwise
- this will match any property that evaluates to `true`.
-
- This method works much like the more generic `find()` method.
-
- Usage Example:
-
- ```javascript
- let users = [
- { id: 1, name: 'Yehuda', isTom: false },
- { id: 2, name: 'Tom', isTom: true },
- { id: 3, name: 'Melanie', isTom: false },
- { id: 4, name: 'Leah', isTom: false }
- ];
-
- users.findBy('id', 4); // { id: 4, name: 'Leah', isTom: false }
- users.findBy('name', 'Melanie'); // { id: 3, name: 'Melanie', isTom: false }
- users.findBy('isTom'); // { id: 2, name: 'Tom', isTom: true }
- ```
-
- @method findBy
- @param {String} key the property to test
- @param {String} [value] optional value to test against.
- @return {Object} found item or `undefined`
- @public
- */
- findBy(key: K, value?: T[K]): T | undefined;
- findBy(key: string, value?: unknown): T | undefined;
- /**
- Returns `true` if the passed function returns true for every item in the
- enumeration. This corresponds with the `Array.prototype.every()` method defined in ES5.
-
- The callback method should have the following signature:
-
- ```javascript
- function(item, index, array);
- ```
-
- - `item` is the current item in the iteration.
- - `index` is the current index in the iteration.
- - `array` is the array itself.
-
- All params are optional. The method should return `true` or `false`.
-
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as `this` on the context. This is a good way
- to give your iterator function access to the current object.
-
- Usage example:
-
- ```javascript
- function isAdult(person) {
- return person.age > 18;
- };
-
- const people = Ember.A([{ name: 'John', age: 24 }, { name: 'Joan', age: 45 }]);
- const areAllAdults = people.every(isAdult);
- ```
-
- @method every
- @param {Function} callback The callback to execute
- @param {Object} [target] The target object to use
- @return {Boolean}
- @public
- */
- every(
- callback: (this: Target, item: T, index: number, arr: this) => unknown,
- target?: Target
- ): boolean;
- /**
- Returns `true` if the passed property resolves to the value of the second
- argument for all items in the array. This method is often simpler/faster
- than using a callback.
-
- Note that like the native `Array.every`, `isEvery` will return true when called
- on any empty array.
- ```javascript
- class Language {
- constructor(name, isProgrammingLanguage) {
- this.name = name;
- this.programmingLanguage = isProgrammingLanguage;
- }
- }
-
- const compiledLanguages = [
- new Language('Java', true),
- new Language('Go', true),
- new Language('Rust', true)
- ]
-
- const languagesKnownByMe = [
- new Language('Javascript', true),
- new Language('English', false),
- new Language('Ruby', true)
- ]
-
- compiledLanguages.isEvery('programmingLanguage'); // true
- languagesKnownByMe.isEvery('programmingLanguage'); // false
- ```
-
- @method isEvery
- @param {String} key the property to test
- @param {String} [value] optional value to test against. Defaults to `true`
- @return {Boolean}
- @since 1.3.0
- @public
- */
- isEvery(key: K, value?: T[K]): boolean;
- isEvery(key: string, value?: unknown): boolean;
- /**
- The any() method executes the callback function once for each element
- present in the array until it finds the one where callback returns a truthy
- value (i.e. `true`). If such an element is found, any() immediately returns
- true. Otherwise, any() returns false.
-
- ```javascript
- function(item, index, array);
- ```
-
- - `item` is the current item in the iteration.
- - `index` is the current index in the iteration.
- - `array` is the array object itself.
-
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as `this` on the context. It can be a good way
- to give your iterator function access to an object in cases where an ES6
- arrow function would not be appropriate.
-
- Usage Example:
-
- ```javascript
- let includesManager = people.any(this.findPersonInManagersList, this);
-
- let includesStockHolder = people.any(person => {
- return this.findPersonInStockHoldersList(person)
- });
-
- if (includesManager || includesStockHolder) {
- Paychecks.addBiggerBonus();
- }
- ```
-
- @method any
- @param {Function} callback The callback to execute
- @param {Object} [target] The target object to use
- @return {Boolean} `true` if the passed function returns `true` for any item
- @public
- */
- any(
- callback: (this: Target, item: T, index: number, arr: this) => unknown,
- target?: Target
- ): boolean;
- /**
- Returns `true` if the passed property resolves to the value of the second
- argument for any item in the array. This method is often simpler/faster
- than using a callback.
-
- Example usage:
-
- ```javascript
- const food = [
- { food: 'apple', isFruit: true },
- { food: 'bread', isFruit: false },
- { food: 'banana', isFruit: true }
- ];
-
- food.isAny('isFruit'); // true
- ```
-
- @method isAny
- @param {String} key the property to test
- @param {String} [value] optional value to test against. Defaults to `true`
- @return {Boolean}
- @since 1.3.0
- @public
- */
- isAny(key: K, value?: T[K]): boolean;
- isAny(key: string, value?: unknown): boolean;
- /**
- This will combine the values of the array into a single value. It
- is a useful way to collect a summary value from an array. This
- corresponds to the `reduce()` method defined in JavaScript 1.8.
-
- The callback method you provide should have the following signature (all
- parameters are optional):
-
- ```javascript
- function(previousValue, item, index, array);
- ```
-
- - `previousValue` is the value returned by the last call to the iterator.
- - `item` is the current item in the iteration.
- - `index` is the current index in the iteration.
- - `array` is the array itself.
-
- Return the new cumulative value.
-
- In addition to the callback you can also pass an `initialValue`. An error
- will be raised if you do not pass an initial value and the enumerator is
- empty.
-
- Note that unlike the other methods, this method does not allow you to
- pass a target object to set as this for the callback. It's part of the
- spec. Sorry.
-
- Example Usage:
-
- ```javascript
- let numbers = [1, 2, 3, 4, 5];
-
- numbers.reduce(function(summation, current) {
- return summation + current;
- }); // 15 (1 + 2 + 3 + 4 + 5)
-
- numbers.reduce(function(summation, current) {
- return summation + current;
- }, -15); // 0 (-15 + 1 + 2 + 3 + 4 + 5)
-
-
- let binaryValues = [true, false, false];
-
- binaryValues.reduce(function(truthValue, current) {
- return truthValue && current;
- }); // false (true && false && false)
- ```
-
- @method reduce
- @param {Function} callback The callback to execute
- @param {Object} initialValue Initial value for the reduce
- @return {Object} The reduced value.
- @public
- */
- reduce(
- callback: (summation: V, current: T, index: number, arr: this) => V,
- initialValue?: V
- ): V;
- /**
- Invokes the named method on every object in the receiver that
- implements it. This method corresponds to the implementation in
- Prototype 1.6.
-
- ```javascript
- class Person {
- name = null;
-
- constructor(name) {
- this.name = name;
- }
-
- greet(prefix='Hello') {
- return `${prefix} ${this.name}`;
- }
- }
-
- let people = [new Person('Joe'), new Person('Matt')];
-
- people.invoke('greet'); // ['Hello Joe', 'Hello Matt']
- people.invoke('greet', 'Bonjour'); // ['Bonjour Joe', 'Bonjour Matt']
- ```
-
- @method invoke
- @param {String} methodName the name of the method
- @param {Object...} args optional arguments to pass as well.
- @return {Array} return values from calling invoke.
- @public
- */
- invoke>(
- methodName: M,
- ...args: MethodParams
- ): NativeArray>;
- /**
- Simply converts the object into a genuine array. The order is not
- guaranteed. Corresponds to the method implemented by Prototype.
-
- @method toArray
- @return {Array} the object as an array.
- @public
- */
- toArray(): T[];
- /**
- Returns a copy of the array with all `null` and `undefined` elements removed.
-
- ```javascript
- let arr = ['a', null, 'c', undefined];
- arr.compact(); // ['a', 'c']
- ```
-
- @method compact
- @return {Array} the array without null and undefined elements.
- @public
- */
- compact(): NativeArray>;
- /**
- Used to determine if the array contains the passed object.
- Returns `true` if found, `false` otherwise.
-
- The optional `startAt` argument can be used to pass a starting
- index to search from, effectively slicing the searchable portion
- of the array. If it's negative it will add the array length to
- the startAt value passed in as the index to search from. If less
- than or equal to `-1 * array.length` the entire array is searched.
-
- This method has the same behavior of JavaScript's [Array.includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes).
-
- ```javascript
- [1, 2, 3].includes(2); // true
- [1, 2, 3].includes(4); // false
- [1, 2, 3].includes(3, 2); // true
- [1, 2, 3].includes(3, 3); // false
- [1, 2, 3].includes(3, -1); // true
- [1, 2, 3].includes(1, -1); // false
- [1, 2, 3].includes(1, -4); // true
- [1, 2, NaN].includes(NaN); // true
- ```
-
- @method includes
- @param {Object} object The object to search for.
- @param {Number} startAt optional starting location to search, default 0
- @return {Boolean} `true` if object is found in the array.
- @public
- */
- includes(object: T, startAt?: number): boolean;
- /**
- Sorts the array by the keys specified in the argument.
-
- You may provide multiple arguments to sort by multiple properties.
-
- ```javascript
- let colors = [
- { name: 'red', weight: 500 },
- { name: 'green', weight: 600 },
- { name: 'blue', weight: 500 }
- ];
-
- colors.sortBy('name');
- // [{name: 'blue', weight: 500}, {name: 'green', weight: 600}, {name: 'red', weight: 500}]
-
- colors.sortBy('weight', 'name');
- // [{name: 'blue', weight: 500}, {name: 'red', weight: 500}, {name: 'green', weight: 600}]
- ```
- @method sortBy
- @param {String} property name(s) to sort on
- @return {Array} The sorted array.
- @since 1.2.0
- @public
- */
- sortBy(...keys: string[]): T[];
- /**
- Returns a new array that contains only unique values. The default
- implementation returns an array regardless of the receiver type.
-
- ```javascript
- let arr = ['a', 'a', 'b', 'b'];
- arr.uniq(); // ['a', 'b']
- ```
-
- This only works on primitive data types, e.g. Strings, Numbers, etc.
-
- @method uniq
- @return {EmberArray}
- @public
- */
- uniq(): NativeArray;
- /**
- Returns a new array that contains only items containing a unique property value.
- The default implementation returns an array regardless of the receiver type.
-
- ```javascript
- let arr = [{ value: 'a' }, { value: 'a' }, { value: 'b' }, { value: 'b' }];
- arr.uniqBy('value'); // [{ value: 'a' }, { value: 'b' }]
-
- let arr = [2.2, 2.1, 3.2, 3.3];
- arr.uniqBy(Math.floor); // [2.2, 3.2];
- ```
-
- @method uniqBy
- @param {String,Function} key
- @return {EmberArray}
- @public
- */
- uniqBy(key: string): NativeArray;
- uniqBy(callback: (value: T) => unknown): NativeArray;
- /**
- Returns a new array that excludes the passed value. The default
- implementation returns an array regardless of the receiver type.
- If the receiver does not contain the value it returns the original array.
-
- ```javascript
- let arr = ['a', 'b', 'a', 'c'];
- arr.without('a'); // ['b', 'c']
- ```
-
- @method without
- @param {Object} value
- @return {EmberArray}
- @public
- */
- without(value: T): NativeArray;
-}
-const EmberArray = Mixin.create(Enumerable, {
- init() {
- this._super(...arguments);
- setEmberArray(this);
- },
-
- objectsAt(indexes: number[]) {
- return indexes.map((idx) => objectAt(this, idx));
- },
-
- '[]': nonEnumerableComputed({
- get() {
- return this;
- },
- set(_key, value) {
- this.replace(0, this.length, value);
- return this;
- },
- }),
-
- firstObject: nonEnumerableComputed(function () {
- return objectAt(this, 0);
- }).readOnly(),
-
- lastObject: nonEnumerableComputed(function () {
- return objectAt(this, this.length - 1);
- }).readOnly(),
-
- // Add any extra methods to EmberArray that are native to the built-in Array.
- slice(beginIndex = 0, endIndex?: number) {
- let ret = A();
- let length = this.length;
-
- if (beginIndex < 0) {
- beginIndex = length + beginIndex;
- }
-
- let validatedEndIndex: number;
- if (endIndex === undefined || endIndex > length) {
- validatedEndIndex = length;
- } else if (endIndex < 0) {
- validatedEndIndex = length + endIndex;
- } else {
- validatedEndIndex = endIndex;
- }
-
- while (beginIndex < validatedEndIndex) {
- ret[ret.length] = objectAt(this, beginIndex++);
- }
-
- return ret;
- },
-
- indexOf(object: T, startAt?: number) {
- return indexOf(this, object, startAt, false);
- },
-
- lastIndexOf(object: T, startAt?: number) {
- let len = this.length;
-
- if (startAt === undefined || startAt >= len) {
- startAt = len - 1;
- }
-
- if (startAt < 0) {
- startAt += len;
- }
-
- for (let idx = startAt; idx >= 0; idx--) {
- if (objectAt(this, idx) === object) {
- return idx;
- }
- }
-
- return -1;
- },
-
- forEach(callback: (item: T, index: number, arr: EmberArray) => void, target = null) {
- assert('`forEach` expects a function as first argument.', typeof callback === 'function');
-
- let length = this.length;
-
- for (let index = 0; index < length; index++) {
- let item = this.objectAt(index);
- callback.call(target, item, index, this);
- }
-
- return this;
- },
-
- getEach: mapBy,
-
- setEach(key: string, value: unknown) {
- return this.forEach((item: object) => set(item, key, value));
- },
-
- map(
- this: EmberArray,
- callback: (item: T, index: number, arr: EmberArray) => unknown,
- target = null
- ) {
- assert('`map` expects a function as first argument.', typeof callback === 'function');
-
- let ret = A();
-
- this.forEach((x, idx, i) => (ret[idx] = callback.call(target, x, idx, i)));
-
- return ret;
- },
-
- mapBy,
-
- filter(
- this: EmberArray,
- callback: (item: T, index: number, arr: EmberArray) => unknown,
- target = null
- ) {
- assert('`filter` expects a function as first argument.', typeof callback === 'function');
-
- let ret = A();
-
- this.forEach((x, idx, i) => {
- if (callback.call(target, x, idx, i)) {
- ret.push(x);
- }
- });
-
- return ret;
- },
-
- reject(
- this: EmberArray,
- callback: (item: T, index: number, arr: EmberArray) => unknown,
- target = null
- ) {
- assert('`reject` expects a function as first argument.', typeof callback === 'function');
- return this.filter(function () {
- // @ts-expect-error TS doesn't like us using arguments like this
- return !callback.apply(target, arguments);
- });
- },
-
- filterBy() {
- // @ts-expect-error TS doesn't like the ...arguments spread here.
- return this.filter(iter(...arguments));
- },
-
- rejectBy() {
- // @ts-expect-error TS doesn't like the ...arguments spread here.
- return this.reject(iter(...arguments));
- },
-
- find(callback: (item: T, index: number, arr: EmberArray) => unknown, target = null) {
- assert('`find` expects a function as first argument.', typeof callback === 'function');
- return find(this, callback, target);
- },
-
- findBy() {
- // @ts-expect-error TS doesn't like the ...arguments spread here.
- let callback = iter(...arguments);
- return find(this, callback);
- },
-
- every(callback: (item: T, index: number, arr: EmberArray) => unknown, target = null) {
- assert('`every` expects a function as first argument.', typeof callback === 'function');
- return every(this, callback, target);
- },
-
- isEvery() {
- // @ts-expect-error TS doesn't like the ...arguments spread here.
- let callback = iter(...arguments);
- return every(this, callback);
- },
-
- any(callback: (item: T, index: number, arr: EmberArray) => unknown, target = null) {
- assert('`any` expects a function as first argument.', typeof callback === 'function');
- return any(this, callback, target);
- },
-
- isAny() {
- // @ts-expect-error TS doesn't like us using arguments like this
- let callback = iter(...arguments);
- return any(this, callback);
- },
-
- // FIXME: When called without initialValue, behavior does not match native behavior
- reduce(
- this: EmberArray,
- callback: (summation: V, current: T, index: number, arr: EmberArray) => V,
- initialValue: V
- ) {
- assert('`reduce` expects a function as first argument.', typeof callback === 'function');
-
- let ret = initialValue;
-
- this.forEach(function (item, i) {
- ret = callback(ret, item, i, this);
- }, this);
-
- return ret;
- },
-
- invoke(this: EmberArray, methodName: string, ...args: unknown[]) {
- let ret = A();
-
- // SAFETY: This is not entirely safe and the code will not work with Ember proxies
- this.forEach((item: T) => ret.push((item as any)[methodName]?.(...args)));
-
- return ret;
- },
-
- toArray(this: EmberArray) {
- return this.map((item: T) => item);
- },
-
- compact(this: EmberArray) {
- return this.filter((value: T) => value != null);
- },
-
- includes(this: EmberArray, object: T, startAt?: number) {
- return indexOf(this, object, startAt, true) !== -1;
- },
-
- sortBy(this: EmberArray) {
- let sortKeys = arguments;
-
- return this.toArray().sort((a: T, b: T) => {
- for (let i = 0; i < sortKeys.length; i++) {
- let key = sortKeys[i];
- let propA = get(a, key);
- let propB = get(b, key);
- // return 1 or -1 else continue to the next sortKey
- let compareValue = compare(propA, propB);
-
- if (compareValue) {
- return compareValue;
- }
- }
- return 0;
- });
- },
-
- uniq() {
- return uniqBy(this);
- },
-
- uniqBy(key: string) {
- return uniqBy(this, key);
- },
-
- without(this: EmberArray, value: T) {
- if (!this.includes(value)) {
- return this; // nothing to do
- }
-
- // SameValueZero comparison (NaN !== NaN)
- let predicate = value === value ? (item: T) => item !== value : (item: T) => item === item;
- return this.filter(predicate);
- },
-});
-
-/**
- This mixin defines the API for modifying array-like objects. These methods
- can be applied only to a collection that keeps its items in an ordered set.
- It builds upon the Array mixin and adds methods to modify the array.
- One concrete implementations of this class include ArrayProxy.
-
- It is important to use the methods in this class to modify arrays so that
- changes are observable. This allows the binding system in Ember to function
- correctly.
-
-
- Note that an Array can change even if it does not implement this mixin.
- For example, one might implement a SparseArray that cannot be directly
- modified, but if its underlying enumerable changes, it will change also.
-
- @class MutableArray
- @uses EmberArray
- @uses MutableEnumerable
- @public
-*/
-interface MutableArray extends EmberArray, MutableEnumerable {
- /**
- __Required.__ You must implement this method to apply this mixin.
-
- This is one of the primitives you must implement to support `Array`.
- You should replace amt objects started at idx with the objects in the
- passed array.
-
- Note that this method is expected to validate the type(s) of objects that it expects.
-
- @method replace
- @param {Number} idx Starting index in the array to replace. If
- idx >= length, then append to the end of the array.
- @param {Number} amt Number of elements that should be removed from
- the array, starting at *idx*.
- @param {EmberArray} [objects] An optional array of zero or more objects that should be
- inserted into the array at *idx*
- @public
- */
- replace(idx: number, amt: number, objects?: readonly T[]): void;
- /**
- Remove all elements from the array. This is useful if you
- want to reuse an existing array without having to recreate it.
-
- ```javascript
- let colors = ['red', 'green', 'blue'];
-
- colors.length; // 3
- colors.clear(); // []
- colors.length; // 0
- ```
-
- @method clear
- @return {Array} An empty Array.
- @public
- */
- clear(): this;
- /**
- This will use the primitive `replace()` method to insert an object at the
- specified index.
-
- ```javascript
- let colors = ['red', 'green', 'blue'];
-
- colors.insertAt(2, 'yellow'); // ['red', 'green', 'yellow', 'blue']
- colors.insertAt(5, 'orange'); // Error: Index out of range
- ```
-
- @method insertAt
- @param {Number} idx index of insert the object at.
- @param {Object} object object to insert
- @return {EmberArray} receiver
- @public
- */
- insertAt(idx: number, object: T): this;
- /**
- Remove an object at the specified index using the `replace()` primitive
- method. You can pass either a single index, or a start and a length.
-
- If you pass a start and length that is beyond the
- length this method will throw an assertion.
-
- ```javascript
- let colors = ['red', 'green', 'blue', 'yellow', 'orange'];
-
- colors.removeAt(0); // ['green', 'blue', 'yellow', 'orange']
- colors.removeAt(2, 2); // ['green', 'blue']
- colors.removeAt(4, 2); // Error: Index out of range
- ```
-
- @method removeAt
- @param {Number} start index, start of range
- @param {Number} len length of passing range
- @return {EmberArray} receiver
- @public
- */
- removeAt(start: number, len?: number): this;
- /**
- Push the object onto the end of the array. Works just like `push()` but it
- is KVO-compliant.
-
- ```javascript
- let colors = ['red', 'green'];
-
- colors.pushObject('black'); // ['red', 'green', 'black']
- colors.pushObject(['yellow']); // ['red', 'green', ['yellow']]
- ```
-
- @method pushObject
- @param {*} obj object to push
- @return object same object passed as a param
- @public
- */
- pushObject(obj: T): T;
- /**
- Add the objects in the passed array to the end of the array. Defers
- notifying observers of the change until all objects are added.
-
- ```javascript
- let colors = ['red'];
-
- colors.pushObjects(['yellow', 'orange']); // ['red', 'yellow', 'orange']
- ```
-
- @method pushObjects
- @param {Array} objects the objects to add
- @return {MutableArray} receiver
- @public
- */
- pushObjects(objects: T[]): this;
- /**
- Pop object from array or nil if none are left. Works just like `pop()` but
- it is KVO-compliant.
-
- ```javascript
- let colors = ['red', 'green', 'blue'];
-
- colors.popObject(); // 'blue'
- console.log(colors); // ['red', 'green']
- ```
-
- @method popObject
- @return object
- @public
- */
- popObject(): T | null | undefined;
- /**
- Shift an object from start of array or nil if none are left. Works just
- like `shift()` but it is KVO-compliant.
-
- ```javascript
- let colors = ['red', 'green', 'blue'];
-
- colors.shiftObject(); // 'red'
- console.log(colors); // ['green', 'blue']
- ```
-
- @method shiftObject
- @return object
- @public
- */
- shiftObject(): T | null | undefined;
- /**
- Unshift an object to start of array. Works just like `unshift()` but it is
- KVO-compliant.
-
- ```javascript
- let colors = ['red'];
-
- colors.unshiftObject('yellow'); // ['yellow', 'red']
- colors.unshiftObject(['black']); // [['black'], 'yellow', 'red']
- ```
-
- @method unshiftObject
- @param {*} obj object to unshift
- @return object same object passed as a param
- @public
- */
- unshiftObject(object: T): T;
- /**
- Adds the named objects to the beginning of the array. Defers notifying
- observers until all objects have been added.
-
- ```javascript
- let colors = ['red'];
-
- colors.unshiftObjects(['black', 'white']); // ['black', 'white', 'red']
- colors.unshiftObjects('yellow'); // Type Error: 'undefined' is not a function
- ```
-
- @method unshiftObjects
- @param {Enumerable} objects the objects to add
- @return {EmberArray} receiver
- @public
- */
- unshiftObjects(objects: T[]): this;
- /**
- Reverse objects in the array. Works just like `reverse()` but it is
- KVO-compliant.
-
- @method reverseObjects
- @return {EmberArray} receiver
- @public
- */
- reverseObjects(): this;
- /**
- Replace all the receiver's content with content of the argument.
- If argument is an empty array receiver will be cleared.
-
- ```javascript
- let colors = ['red', 'green', 'blue'];
-
- colors.setObjects(['black', 'white']); // ['black', 'white']
- colors.setObjects([]); // []
- ```
-
- @method setObjects
- @param {EmberArray} objects array whose content will be used for replacing
- the content of the receiver
- @return {EmberArray} receiver with the new content
- @public
- */
- setObjects(object: T[]): this;
- /**
- Remove all occurrences of an object in the array.
-
- ```javascript
- let cities = ['Chicago', 'Berlin', 'Lima', 'Chicago'];
-
- cities.removeObject('Chicago'); // ['Berlin', 'Lima']
- cities.removeObject('Lima'); // ['Berlin']
- cities.removeObject('Tokyo') // ['Berlin']
- ```
-
- @method removeObject
- @param {*} obj object to remove
- @return {EmberArray} receiver
- @public
- */
- removeObject(object: T): this;
- /**
- Removes each object in the passed array from the receiver.
-
- @method removeObjects
- @param {EmberArray} objects the objects to remove
- @return {EmberArray} receiver
- @public
- */
- removeObjects(objects: T[]): this;
- /**
- Push the object onto the end of the array if it is not already
- present in the array.
-
- ```javascript
- let cities = ['Chicago', 'Berlin'];
-
- cities.addObject('Lima'); // ['Chicago', 'Berlin', 'Lima']
- cities.addObject('Berlin'); // ['Chicago', 'Berlin', 'Lima']
- ```
-
- @method addObject
- @param {*} obj object to add, if not already present
- @return {EmberArray} receiver
- @public
- */
- addObject(obj: T): this;
- /**
- Adds each object in the passed array to the receiver.
-
- @method addObjects
- @param {EmberArray} objects the objects to add.
- @return {EmberArray} receiver
- @public
- */
- addObjects(objects: T[]): this;
-}
-const MutableArray = Mixin.create(EmberArray, MutableEnumerable, {
- clear() {
- let len = this.length;
- if (len === 0) {
- return this;
- }
-
- this.replace(0, len, EMPTY_ARRAY);
- return this;
- },
-
- insertAt(idx: number, object: unknown) {
- insertAt(this, idx, object);
- return this;
- },
-
- removeAt(start: number, len?: number) {
- return removeAt(this, start, len);
- },
-
- pushObject(this: MutableArray, obj: T) {
- return insertAt(this, this.length, obj);
- },
-
- pushObjects(this: MutableArray, objects: T[]) {
- this.replace(this.length, 0, objects);
- return this;
- },
-
- popObject() {
- let len = this.length;
- if (len === 0) {
- return null;
- }
-
- let ret = objectAt(this, len - 1);
- this.removeAt(len - 1, 1);
- return ret;
- },
-
- shiftObject() {
- if (this.length === 0) {
- return null;
- }
-
- let ret = objectAt(this, 0);
- this.removeAt(0);
- return ret;
- },
-
- unshiftObject(this: MutableArray, obj: T) {
- return insertAt(this, 0, obj);
- },
-
- unshiftObjects(this: MutableArray, objects: T[]) {
- this.replace(0, 0, objects);
- return this;
- },
-
- reverseObjects() {
- let len = this.length;
- if (len === 0) {
- return this;
- }
-
- let objects = this.toArray().reverse();
- this.replace(0, len, objects);
- return this;
- },
-
- setObjects(this: MutableArray, objects: T[]) {
- if (objects.length === 0) {
- return this.clear();
- }
-
- let len = this.length;
- this.replace(0, len, objects);
- return this;
- },
-
- removeObject(this: MutableArray, obj: T) {
- let loc = this.length || 0;
- while (--loc >= 0) {
- let curObject = objectAt(this, loc);
-
- if (curObject === obj) {
- this.removeAt(loc);
- }
- }
- return this;
- },
-
- removeObjects(this: MutableArray, objects: T[]) {
- beginPropertyChanges();
- for (let i = objects.length - 1; i >= 0; i--) {
- // SAFETY: Due to the loop structure we know this will always exist.
- this.removeObject(objects[i]!);
- }
- endPropertyChanges();
- return this;
- },
-
- addObject(this: MutableArray, obj: T) {
- let included = this.includes(obj);
-
- if (!included) {
- this.pushObject(obj);
- }
-
- return this;
- },
-
- addObjects(this: MutableArray, objects: T[]) {
- beginPropertyChanges();
- objects.forEach((obj) => this.addObject(obj));
- endPropertyChanges();
- return this;
- },
-});
-
-/**
- Creates an `Ember.NativeArray` from an Array-like object.
- Does not modify the original object's contents.
-
- Example
-
- ```app/components/my-component.js
- import Component from '@ember/component';
- import { A } from '@ember/array';
-
- export default Component.extend({
- tagName: 'ul',
- classNames: ['pagination'],
-
- init() {
- this._super(...arguments);
-
- if (!this.get('content')) {
- this.set('content', A());
- this.set('otherContent', A([1,2,3]));
- }
- }
- });
- ```
-
- @method A
- @static
- @for @ember/array
- @return {Ember.NativeArray}
- @public
-*/
-
-// Add Ember.Array to Array.prototype. Remove methods with native
-// implementations and supply some more optimized versions of generic methods
-// because they are so common.
-/**
-@module ember
-*/
-
-type AnyArray = EmberArray | Array | ReadonlyArray;
-
-/**
- * The final definition of NativeArray removes all native methods. This is the list of removed methods
- * when run in Chrome 106.
- */
-type IGNORED_MUTABLE_ARRAY_METHODS =
- | 'length'
- | 'slice'
- | 'indexOf'
- | 'lastIndexOf'
- | 'forEach'
- | 'map'
- | 'filter'
- | 'find'
- | 'every'
- | 'reduce'
- | 'includes';
-
-/**
- * These additional items must be redefined since `Omit` causes methods that return `this` to return the
- * type at the time of the Omit.
- */
-type RETURN_SELF_ARRAY_METHODS =
- | '[]'
- | 'clear'
- | 'insertAt'
- | 'removeAt'
- | 'pushObjects'
- | 'unshiftObjects'
- | 'reverseObjects'
- | 'setObjects'
- | 'removeObject'
- | 'removeObjects'
- | 'addObject'
- | 'addObjects'
- | 'setEach';
-
-// This is the same as MutableArray, but removes the actual native methods that exist on Array.prototype.
-interface MutableArrayWithoutNative
- extends Omit, IGNORED_MUTABLE_ARRAY_METHODS | RETURN_SELF_ARRAY_METHODS> {
- /**
- * Remove all elements from the array. This is useful if you
- * want to reuse an existing array without having to recreate it.
- */
- clear(): this;
- /**
- * This will use the primitive `replace()` method to insert an object at the
- * specified index.
- */
- insertAt(idx: number, object: T): this;
- /**
- * Remove an object at the specified index using the `replace()` primitive
- * method. You can pass either a single index, or a start and a length.
- */
- removeAt(start: number, len?: number): this;
- /**
- * Add the objects in the passed numerable to the end of the array. Defers
- * notifying observers of the change until all objects are added.
- */
- pushObjects(objects: AnyArray): this;
- /**
- * Adds the named objects to the beginning of the array. Defers notifying
- * observers until all objects have been added.
- */
- unshiftObjects(objects: AnyArray): this;
- /**
- * Reverse objects in the array. Works just like `reverse()` but it is
- * KVO-compliant.
- */
- reverseObjects(): this;
- /**
- * Replace all the receiver's content with content of the argument.
- * If argument is an empty array receiver will be cleared.
- */
- setObjects(objects: AnyArray): this;
- /**
- Remove all occurrences of an object in the array.
-
- ```javascript
- let cities = ['Chicago', 'Berlin', 'Lima', 'Chicago'];
-
- cities.removeObject('Chicago'); // ['Berlin', 'Lima']
- cities.removeObject('Lima'); // ['Berlin']
- cities.removeObject('Tokyo') // ['Berlin']
- ```
-
- @method removeObject
- @param {*} obj object to remove
- @return {EmberArray} receiver
- @public
- */
- removeObject(object: T): this;
- /**
- * Removes each object in the passed array from the receiver.
- */
- removeObjects(objects: AnyArray): this;
- /**
- Push the object onto the end of the array if it is not already
- present in the array.
-
- ```javascript
- let cities = ['Chicago', 'Berlin'];
-
- cities.addObject('Lima'); // ['Chicago', 'Berlin', 'Lima']
- cities.addObject('Berlin'); // ['Chicago', 'Berlin', 'Lima']
- ```
-
- @method addObject
- @param {*} obj object to add, if not already present
- @return {EmberArray} receiver
- @public
- */
- addObject(obj: T): this;
- /**
- * Adds each object in the passed enumerable to the receiver.
- */
- addObjects(objects: AnyArray): this;
- /**
- Sets the value on the named property for each member. This is more
- ergonomic than using other methods defined on this helper. If the object
- implements Observable, the value will be changed to `set(),` otherwise
- it will be set directly. `null` objects are skipped.
-
- ```javascript
- let people = [{name: 'Joe'}, {name: 'Matt'}];
-
- people.setEach('zipCode', '10011');
- // [{name: 'Joe', zipCode: '10011'}, {name: 'Matt', zipCode: '10011'}];
- ```
-
- @method setEach
- @param {String} key The key to set
- @param {Object} value The object to set
- @return {Object} receiver
- @public
- */
- setEach(key: K, value: T[K]): this;
- /**
- This is the handler for the special array content property. If you get
- this property, it will return this. If you set this property to a new
- array, it will replace the current content.
-
- ```javascript
- let peopleToMoon = ['Armstrong', 'Aldrin'];
-
- peopleToMoon.get('[]'); // ['Armstrong', 'Aldrin']
-
- peopleToMoon.set('[]', ['Collins']); // ['Collins']
- peopleToMoon.get('[]'); // ['Collins']
- ```
-
- @property []
- @return this
- @public
- */
- get '[]'(): this;
- set '[]'(newValue: T[] | this);
-}
-
-/**
- The NativeArray mixin contains the properties needed to make the native
- Array support MutableArray and all of its dependent APIs.
-
- @class Ember.NativeArray
- @uses MutableArray
- @uses Observable
- @public
-*/
-interface NativeArray extends Array, Observable, MutableArrayWithoutNative {}
-
-let NativeArray = Mixin.create(MutableArray, Observable, {
- objectAt(idx: number) {
- return this[idx];
- },
-
- // primitive for array support.
- replace(start: number, deleteCount: number, items = EMPTY_ARRAY) {
- assert('The third argument to replace needs to be an array.', Array.isArray(items));
-
- replaceInNativeArray(this, start, deleteCount, items);
-
- return this;
- },
-});
-
-// Remove any methods implemented natively so we don't override them
-const ignore = ['length'];
-NativeArray.keys().forEach((methodName) => {
- // SAFETY: It's safe to read unknown properties from an object
- if ((Array.prototype as any)[methodName]) {
- ignore.push(methodName);
- }
-});
-
-NativeArray = NativeArray.without(...ignore);
-
-let A: (arr?: Array) => NativeArray;
-
-A = function (this: unknown, arr?: Array) {
- assert(
- 'You cannot create an Ember Array with `new A()`, please update to calling A as a function: `A()`',
- !(this instanceof A)
- );
-
- if (isEmberArray(arr)) {
- // SAFETY: If it's a true native array and it is also an EmberArray then it should be an Ember NativeArray
- return arr as unknown as NativeArray;
- } else {
- // SAFETY: This will return an NativeArray but TS can't infer that.
- return NativeArray.apply(arr ?? []) as NativeArray;
- }
-};
-
-export { A, NativeArray, MutableArray };
-
-export default EmberArray;
diff --git a/packages/@ember/array/lib/make-array.ts b/packages/@ember/array/lib/make-array.ts
index 12f628eed78..b4c1093fa51 100644
--- a/packages/@ember/array/lib/make-array.ts
+++ b/packages/@ember/array/lib/make-array.ts
@@ -9,17 +9,12 @@ const { isArray } = Array;
```javascript
import { makeArray } from '@ember/array';
- import ArrayProxy from '@ember/array/proxy';
makeArray(); // []
makeArray(null); // []
makeArray(undefined); // []
makeArray('lindsay'); // ['lindsay']
makeArray([1, 2, 42]); // [1, 2, 42]
-
- let proxy = ArrayProxy.create({ content: [] });
-
- makeArray(proxy) === proxy; // false
```
@method makeArray
diff --git a/packages/@ember/array/mutable.ts b/packages/@ember/array/mutable.ts
deleted file mode 100644
index 6f996faf8c0..00000000000
--- a/packages/@ember/array/mutable.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { MutableArray as default } from '@ember/array';
diff --git a/packages/@ember/array/package.json b/packages/@ember/array/package.json
index 49adb707a77..de9b0400387 100644
--- a/packages/@ember/array/package.json
+++ b/packages/@ember/array/package.json
@@ -5,7 +5,6 @@
"exports": {
".": "./index.ts",
"./-internals": "./-internals.ts",
- "./proxy": "./proxy.ts",
"./make": "./make.ts",
"./mutable": "./mutable.ts"
},
@@ -13,7 +12,6 @@
"@ember/-internals": "workspace:*",
"@ember/application": "workspace:*",
"@ember/debug": "workspace:*",
- "@ember/enumerable": "workspace:*",
"@ember/object": "workspace:*",
"@ember/runloop": "workspace:*",
"@ember/utils": "workspace:*",
diff --git a/packages/@ember/array/proxy.ts b/packages/@ember/array/proxy.ts
deleted file mode 100644
index ff72f1990ac..00000000000
--- a/packages/@ember/array/proxy.ts
+++ /dev/null
@@ -1,414 +0,0 @@
-/**
-@module @ember/array/proxy
-*/
-
-import {
- objectAt,
- alias,
- PROPERTY_DID_CHANGE,
- addArrayObserver,
- removeArrayObserver,
- replace,
- arrayContentDidChange,
- arrayContentWillChange,
- tagForProperty,
-} from '@ember/-internals/metal';
-import { get } from '@ember/object';
-import type { PropertyDidChange } from '@ember/-internals/metal';
-import { isObject } from '@ember/-internals/utils';
-import EmberObject from '@ember/object';
-import EmberArray, { type NativeArray } from '@ember/array';
-import MutableArray from '@ember/array/mutable';
-import { assert } from '@ember/debug';
-import { setCustomTagFor } from '@glimmer/manager';
-import {
- combine,
- consumeTag,
- validateTag,
- valueForTag,
- tagFor,
- type Tag,
- type Revision,
-} from '@glimmer/validator';
-
-function isMutable(obj: T[] | EmberArray): obj is T[] | MutableArray {
- return Array.isArray(obj) || typeof (obj as MutableArray).replace === 'function';
-}
-
-const ARRAY_OBSERVER_MAPPING = {
- willChange: '_arrangedContentArrayWillChange',
- didChange: '_arrangedContentArrayDidChange',
-};
-
-function customTagForArrayProxy(proxy: object, key: string) {
- assert('[BUG] Expected a proxy', proxy instanceof ArrayProxy);
-
- if (key === '[]') {
- proxy._revalidate();
-
- return proxy._arrTag!;
- } else if (key === 'length') {
- proxy._revalidate();
-
- return proxy._lengthTag!;
- }
-
- return tagFor(proxy, key);
-}
-
-/**
- An ArrayProxy wraps any other object that implements `Array` and/or
- `MutableArray,` forwarding all requests. This makes it very useful for
- a number of binding use cases or other cases where being able to swap
- out the underlying array is useful.
-
- A simple example of usage:
-
- ```javascript
- import { A } from '@ember/array';
- import ArrayProxy from '@ember/array/proxy';
-
- let pets = ['dog', 'cat', 'fish'];
- let ap = ArrayProxy.create({ content: A(pets) });
-
- ap.get('firstObject'); // 'dog'
- ap.set('content', ['amoeba', 'paramecium']);
- ap.get('firstObject'); // 'amoeba'
- ```
-
- This class can also be useful as a layer to transform the contents of
- an array, as they are accessed. This can be done by overriding
- `objectAtContent`:
-
- ```javascript
- import { A } from '@ember/array';
- import ArrayProxy from '@ember/array/proxy';
-
- let pets = ['dog', 'cat', 'fish'];
- let ap = ArrayProxy.create({
- content: A(pets),
- objectAtContent: function(idx) {
- return this.get('content').objectAt(idx).toUpperCase();
- }
- });
-
- ap.get('firstObject'); // . 'DOG'
- ```
-
- When overriding this class, it is important to place the call to
- `_super` *after* setting `content` so the internal observers have
- a chance to fire properly:
-
- ```javascript
- import { A } from '@ember/array';
- import ArrayProxy from '@ember/array/proxy';
-
- export default ArrayProxy.extend({
- init() {
- this.set('content', A(['dog', 'cat', 'fish']));
- this._super(...arguments);
- }
- });
- ```
-
- @class ArrayProxy
- @extends EmberObject
- @uses MutableArray
- @public
-*/
-interface ArrayProxy extends MutableArray {
- /**
- The content array. Must be an object that implements `Array` and/or
- `MutableArray.`
-
- @property content
- @type EmberArray
- @public
- */
- content: T[] | EmberArray | NativeArray | null;
- /**
- The array that the proxy pretends to be. In the default `ArrayProxy`
- implementation, this and `content` are the same. Subclasses of `ArrayProxy`
- can override this property to provide things like sorting and filtering.
-
- @property arrangedContent
- @public
- */
- arrangedContent: EmberArray | null;
- /**
- Should actually retrieve the object at the specified index from the
- content. You can override this method in subclasses to transform the
- content item to something new.
-
- This method will only be called if content is non-`null`.
-
- @method objectAtContent
- @param {Number} idx The index to retrieve.
- @return {Object} the value or undefined if none found
- @public
- */
- objectAtContent(idx: number): T | undefined;
- /**
- Should actually replace the specified objects on the content array.
- You can override this method in subclasses to transform the content item
- into something new.
-
- This method will only be called if content is non-`null`.
-
- @method replaceContent
- @param {Number} idx The starting index
- @param {Number} amt The number of items to remove from the content.
- @param {Array} objects Optional array of objects to insert.
- @return {void}
- @public
- */
- replaceContent(idx: number, amt: number, objects?: T[]): void;
-
- create(init: { content: Array }): ArrayProxy;
-}
-class ArrayProxy extends EmberObject implements PropertyDidChange {
- /*
- `this._objectsDirtyIndex` determines which indexes in the `this._objects`
- cache are dirty.
-
- If `this._objectsDirtyIndex === -1` then no indexes are dirty.
- Otherwise, an index `i` is dirty if `i >= this._objectsDirtyIndex`.
-
- Calling `objectAt` with a dirty index will cause the `this._objects`
- cache to be recomputed.
- */
- /** @internal */
- _objectsDirtyIndex = 0;
- /** @internal */
- _objects: null | T[] = null;
-
- /** @internal */
- _lengthDirty = true;
- /** @internal */
- _length = 0;
-
- /** @internal */
- _arrangedContent: EmberArray | null = null;
- /** @internal */
- _arrangedContentIsUpdating = false;
- /** @internal */
- _arrangedContentTag: Tag | null = null;
- /** @internal */
- _arrangedContentRevision: Revision | null = null;
- /** @internal */
- _lengthTag: Tag | null = null;
- /** @internal */
- _arrTag: Tag | null = null;
-
- init(props: object | undefined) {
- super.init(props);
-
- setCustomTagFor(this, customTagForArrayProxy);
- }
-
- [PROPERTY_DID_CHANGE]() {
- this._revalidate();
- }
-
- willDestroy() {
- this._removeArrangedContentArrayObserver();
- }
-
- declare content: T[] | EmberArray | NativeArray | null;
-
- declare arrangedContent: EmberArray | null;
-
- objectAtContent(idx: number) {
- let arrangedContent = get(this, 'arrangedContent');
- assert('[BUG] Called objectAtContent without content', arrangedContent);
- return objectAt(arrangedContent, idx);
- }
-
- // See additional docs for `replace` from `MutableArray`:
- // https://api.emberjs.com/ember/release/classes/MutableArray/methods/replace?anchor=replace
- replace(idx: number, amt: number, objects?: T[]) {
- assert(
- 'Mutating an arranged ArrayProxy is not allowed',
- get(this, 'arrangedContent') === get(this, 'content')
- );
- this.replaceContent(idx, amt, objects);
- }
-
- replaceContent(idx: number, amt: number, objects?: T[]) {
- let content = get(this, 'content');
- assert('[BUG] Called replaceContent without content', content);
- assert('Mutating a non-mutable array is not allowed', isMutable(content));
- replace(content, idx, amt, objects);
- }
-
- // Overriding objectAt is not supported.
- objectAt(idx: number) {
- this._revalidate();
-
- if (this._objects === null) {
- this._objects = [];
- }
-
- if (this._objectsDirtyIndex !== -1 && idx >= this._objectsDirtyIndex) {
- let arrangedContent = get(this, 'arrangedContent');
- if (arrangedContent) {
- let length = (this._objects.length = get(arrangedContent, 'length'));
-
- for (let i = this._objectsDirtyIndex; i < length; i++) {
- // SAFETY: This is expected to only ever return an instance of T. In other words, there should
- // be no gaps in the array. Unfortunately, we can't actually assert for it since T could include
- // any types, including null or undefined.
- this._objects[i] = this.objectAtContent(i)!;
- }
- } else {
- this._objects.length = 0;
- }
- this._objectsDirtyIndex = -1;
- }
-
- return this._objects[idx];
- }
-
- // Overriding length is not supported.
- get length() {
- this._revalidate();
-
- if (this._lengthDirty) {
- let arrangedContent = get(this, 'arrangedContent');
- this._length = arrangedContent ? get(arrangedContent, 'length') : 0;
- this._lengthDirty = false;
- }
-
- assert('[BUG] _lengthTag is not set', this._lengthTag);
- consumeTag(this._lengthTag);
-
- return this._length;
- }
-
- set length(value) {
- let length = this.length;
- let removedCount = length - value;
- let added: T[] | undefined;
-
- if (removedCount === 0) {
- return;
- } else if (removedCount < 0) {
- added = new Array(-removedCount);
- removedCount = 0;
- }
-
- let content = get(this, 'content');
- if (content) {
- assert('Mutating a non-mutable array is not allowed', isMutable(content));
- replace(content, value, removedCount, added);
-
- this._invalidate();
- }
- }
-
- _updateArrangedContentArray(arrangedContent: EmberArray | null) {
- let oldLength = this._objects === null ? 0 : this._objects.length;
- let newLength = arrangedContent ? get(arrangedContent, 'length') : 0;
-
- this._removeArrangedContentArrayObserver();
- arrayContentWillChange(this, 0, oldLength, newLength);
-
- this._invalidate();
-
- arrayContentDidChange(this, 0, oldLength, newLength, false);
- this._addArrangedContentArrayObserver(arrangedContent);
- }
-
- _addArrangedContentArrayObserver(arrangedContent: EmberArray | null) {
- if (arrangedContent && !(arrangedContent as any).isDestroyed) {
- assert("Can't set ArrayProxy's content to itself", arrangedContent !== this);
- assert(
- `ArrayProxy expects a native Array, EmberArray, or ArrayProxy, but you passed ${typeof arrangedContent}`,
- (function (arr: unknown): arr is EmberArray {
- return Array.isArray(arr) || EmberArray.detect(arr);
- })(arrangedContent)
- );
- assert(
- 'ArrayProxy expected its contents to not be destroyed',
- !(arrangedContent as any).isDestroyed
- );
-
- addArrayObserver(arrangedContent, this, ARRAY_OBSERVER_MAPPING);
-
- this._arrangedContent = arrangedContent;
- }
- }
-
- _removeArrangedContentArrayObserver() {
- if (this._arrangedContent) {
- removeArrayObserver(this._arrangedContent, this, ARRAY_OBSERVER_MAPPING);
- }
- }
-
- _arrangedContentArrayWillChange() {}
-
- _arrangedContentArrayDidChange(
- _proxy: unknown,
- idx: number,
- removedCnt: number,
- addedCnt: number
- ) {
- arrayContentWillChange(this, idx, removedCnt, addedCnt);
-
- let dirtyIndex = idx;
- if (dirtyIndex < 0) {
- let length = get(this._arrangedContent!, 'length');
- dirtyIndex += length + removedCnt - addedCnt;
- }
-
- if (this._objectsDirtyIndex === -1 || this._objectsDirtyIndex > dirtyIndex) {
- this._objectsDirtyIndex = dirtyIndex;
- }
-
- this._lengthDirty = true;
-
- arrayContentDidChange(this, idx, removedCnt, addedCnt, false);
- }
-
- _invalidate() {
- this._objectsDirtyIndex = 0;
- this._lengthDirty = true;
- }
-
- _revalidate() {
- if (this._arrangedContentIsUpdating === true) return;
-
- if (
- this._arrangedContentTag === null ||
- !validateTag(this._arrangedContentTag, this._arrangedContentRevision!)
- ) {
- let arrangedContent = this.get('arrangedContent');
-
- if (this._arrangedContentTag === null) {
- // This is the first time the proxy has been setup, only add the observer
- // don't trigger any events
- this._addArrangedContentArrayObserver(arrangedContent);
- } else {
- this._arrangedContentIsUpdating = true;
- this._updateArrangedContentArray(arrangedContent);
- this._arrangedContentIsUpdating = false;
- }
-
- let arrangedContentTag = (this._arrangedContentTag = tagFor(this, 'arrangedContent'));
- this._arrangedContentRevision = valueForTag(this._arrangedContentTag);
-
- if (isObject(arrangedContent)) {
- this._lengthTag = combine([arrangedContentTag, tagForProperty(arrangedContent, 'length')]);
- this._arrTag = combine([arrangedContentTag, tagForProperty(arrangedContent, '[]')]);
- } else {
- this._lengthTag = this._arrTag = arrangedContentTag;
- }
- }
- }
-}
-
-ArrayProxy.reopen(MutableArray, {
- arrangedContent: alias('content'),
-});
-
-export default ArrayProxy;
diff --git a/packages/@ember/array/tests/is-ember-array-test.js b/packages/@ember/array/tests/is-ember-array-test.js
deleted file mode 100644
index 15d724d8992..00000000000
--- a/packages/@ember/array/tests/is-ember-array-test.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import { setEmberArray, isEmberArray } from '@ember/array/-internals';
-import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
-
-moduleFor(
- '@ember/-internals/utils Trackable Object',
- class extends AbstractTestCase {
- ['@test classes'](assert) {
- class Test {
- constructor() {
- setEmberArray(this);
- }
- }
-
- let instance = new Test();
-
- assert.equal(isEmberArray(instance), true);
- }
- }
-);
diff --git a/packages/@ember/array/type-tests/index.test.ts b/packages/@ember/array/type-tests/index.test.ts
deleted file mode 100644
index e7ee89b26ac..00000000000
--- a/packages/@ember/array/type-tests/index.test.ts
+++ /dev/null
@@ -1,220 +0,0 @@
-import type { NativeArray } from '@ember/array';
-import type EmberArray from '@ember/array';
-import { A, isArray, makeArray } from '@ember/array';
-import type MutableArray from '@ember/array/mutable';
-
-import { expectTypeOf } from 'expect-type';
-
-class Foo {
- bar = 1;
- hi(): string {
- return 'Hi';
- }
- withArgs(foo: number, bar: string): string {
- return `${foo}${bar}`;
- }
-}
-
-let foo = new Foo();
-
-let arr = A([foo]);
-
-class Target {
- foo = 2;
-}
-
-let target = new Target();
-
-// NativeArray does not exactly extend the interface of EmberArray and MutableArray,
-// since native methods are not overwritten.
-expectTypeOf(arr).not.toMatchTypeOf>();
-expectTypeOf(arr).not.toMatchTypeOf>();
-
-expectTypeOf(arr).toEqualTypeOf>();
-
-expectTypeOf(arr.length).toEqualTypeOf();
-
-expectTypeOf(arr.objectAt(1)).toEqualTypeOf();
-
-expectTypeOf(arr.firstObject).toEqualTypeOf();
-
-expectTypeOf(arr.lastObject).toEqualTypeOf();
-
-expectTypeOf(arr.slice()).toEqualTypeOf();
-expectTypeOf(arr.slice(1)).toEqualTypeOf();
-expectTypeOf(arr.slice(1, 2)).toEqualTypeOf();
-
-expectTypeOf(arr.indexOf(new Foo())).toEqualTypeOf();
-// @ts-expect-error checks param type
-arr.indexOf('invalid');
-
-expectTypeOf(arr.lastIndexOf(new Foo())).toEqualTypeOf();
-// @ts-expect-error checks param type
-arr.lastIndexOf('invalid');
-
-expectTypeOf(arr.forEach((item: Foo) => String(item))).toEqualTypeOf();
-
-arr.forEach((item, index, arr) => {
- expectTypeOf(this).toEqualTypeOf();
- expectTypeOf(item).toEqualTypeOf();
- expectTypeOf(index).toEqualTypeOf();
- expectTypeOf(arr).toEqualTypeOf(arr);
-});
-arr.forEach(function (_item) {
- // No-op
-}, target);
-
-expectTypeOf(arr.getEach('bar')).toEqualTypeOf>();
-// @ts-expect-error Unknown property
-arr.getEach('missing');
-
-expectTypeOf(arr.setEach('bar', 2)).toEqualTypeOf(arr);
-// @ts-expect-error Invalid value
-arr.setEach('bar', 'string');
-
-// @ts-expect-error Unknown property
-arr.setEach('missing', 'anything');
-
-let mapped = arr.map((item, index, arr) => {
- expectTypeOf(item).toEqualTypeOf();
- expectTypeOf(index).toEqualTypeOf();
- expectTypeOf(arr).toEqualTypeOf(arr);
- return 1;
-});
-expectTypeOf(mapped).toEqualTypeOf();
-
-arr.map(function (_item) {
- return true;
-}, target);
-
-expectTypeOf(arr.mapBy('bar')).toEqualTypeOf>();
-expectTypeOf(arr.mapBy('missing')).toEqualTypeOf>();
-
-let filtered = arr.filter((item, index, arr) => {
- expectTypeOf(item).toEqualTypeOf();
- expectTypeOf(index).toEqualTypeOf();
- expectTypeOf(arr).toEqualTypeOf(arr);
- return true;
-});
-expectTypeOf(filtered).toEqualTypeOf();
-arr.filter(function (_item) {
- return true;
-}, target);
-
-let rejected = arr.reject((item, index, arr) => {
- expectTypeOf(item).toEqualTypeOf();
- expectTypeOf(index).toEqualTypeOf();
- expectTypeOf(arr).toEqualTypeOf(arr);
- return true;
-});
-expectTypeOf(rejected).toEqualTypeOf>();
-arr.reject(function (_item) {
- expectTypeOf(this).toEqualTypeOf(target);
- return true;
-}, target);
-
-expectTypeOf(arr.filterBy('bar')).toEqualTypeOf>();
-expectTypeOf(arr.filterBy('missing')).toEqualTypeOf>();
-
-expectTypeOf(arr.rejectBy('bar')).toEqualTypeOf>();
-expectTypeOf(arr.rejectBy('missing')).toEqualTypeOf