language
stringclasses 1
value | owner
stringlengths 2
15
| repo
stringlengths 2
21
| sha
stringlengths 45
45
| message
stringlengths 7
36.3k
| path
stringlengths 1
199
| patch
stringlengths 15
102k
| is_multipart
bool 2
classes |
---|---|---|---|---|---|---|---|
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-glimmer/lib/views/outlet.ts
|
@@ -1,6 +1,6 @@
import { Simple } from '@glimmer/interfaces';
import { environment } from 'ember-environment';
-import { run } from 'ember-metal';
+import { schedule } from 'ember-metal';
import { assign, OWNER, Owner } from 'ember-utils';
import { OutletDefinitionState } from '../component-managers/outlet';
import { Renderer } from '../renderer';
@@ -73,7 +73,7 @@ export default class OutletView {
target = selector;
}
- run.schedule('render', this.renderer, 'appendOutletView', this, target);
+ schedule('render', this.renderer, 'appendOutletView', this, target);
}
rerender() { /**/ }
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-glimmer/tests/integration/application/engine-test.js
|
@@ -5,7 +5,7 @@ import { Controller, RSVP } from 'ember-runtime';
import { Component } from 'ember-glimmer';
import { Engine } from 'ember-application';
import { Route } from 'ember-routing';
-import { run } from 'ember-metal';
+import { next } from 'ember-metal';
moduleFor('Application test: engine rendering', class extends ApplicationTest {
get routerOptions() {
@@ -414,7 +414,7 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
this.additionalEngineRegistrations(function() {
this.register('route:application_error', Route.extend({
activate() {
- run.next(errorEntered.resolve);
+ next(errorEntered.resolve);
}
}));
this.register('template:application_error', compile('Error! {{model.message}}'));
@@ -444,7 +444,7 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
this.additionalEngineRegistrations(function() {
this.register('route:error', Route.extend({
activate() {
- run.next(errorEntered.resolve);
+ next(errorEntered.resolve);
}
}));
this.register('template:error', compile('Error! {{model.message}}'));
@@ -474,7 +474,7 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
this.additionalEngineRegistrations(function() {
this.register('route:post_error', Route.extend({
activate() {
- run.next(errorEntered.resolve);
+ next(errorEntered.resolve);
}
}));
this.register('template:post_error', compile('Error! {{model.message}}'));
@@ -504,7 +504,7 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
this.additionalEngineRegistrations(function() {
this.register('route:post.error', Route.extend({
activate() {
- run.next(errorEntered.resolve);
+ next(errorEntered.resolve);
}
}));
this.register('template:post.error', compile('Error! {{model.message}}'));
@@ -536,7 +536,7 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
this.additionalEngineRegistrations(function() {
this.register('route:application_loading', Route.extend({
activate() {
- run.next(loadingEntered.resolve);
+ next(loadingEntered.resolve);
}
}));
this.register('template:application_loading', compile('Loading'));
@@ -577,7 +577,7 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
this.additionalEngineRegistrations(function() {
this.register('route:loading', Route.extend({
activate() {
- run.next(loadingEntered.resolve);
+ next(loadingEntered.resolve);
}
}));
this.register('template:loading', compile('Loading'));
@@ -655,7 +655,7 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
this.register('template:post.comments', compile('Comments'));
this.register('route:post.loading', Route.extend({
activate() {
- run.next(loadingEntered.resolve);
+ next(loadingEntered.resolve);
}
}));
this.register('template:post.loading', compile('Loading'));
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-glimmer/tests/integration/components/life-cycle-test.js
|
@@ -1,4 +1,4 @@
-import { set, setProperties, run } from 'ember-metal';
+import { set, setProperties, schedule } from 'ember-metal';
import { A as emberA } from 'ember-runtime';
import { Component } from '../../utils/helpers';
import { strip } from '../../utils/abstract-test-case';
@@ -139,7 +139,7 @@ class LifeCycleHooksTest extends RenderingTest {
this.on('init', () => pushHook('on(init)'));
- run.schedule('afterRender', () => {
+ schedule('afterRender', () => {
this.isInitialRender = false;
});
},
@@ -1279,7 +1279,7 @@ moduleFor('Run loop and lifecycle hooks', class extends RenderingTest {
let ComponentClass = Component.extend({
width: '5',
didInsertElement() {
- run.schedule('afterRender', () => {
+ schedule('afterRender', () => {
this.set('width', '10');
});
}
@@ -1300,7 +1300,7 @@ moduleFor('Run loop and lifecycle hooks', class extends RenderingTest {
['@test afterRender set on parent']() {
let ComponentClass = Component.extend({
didInsertElement() {
- run.schedule('afterRender', () => {
+ schedule('afterRender', () => {
let parent = this.get('parent');
parent.set('foo', 'wat');
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-glimmer/tests/integration/event-dispatcher-test.js
|
@@ -3,7 +3,8 @@ import { Component } from '../utils/helpers';
import {
instrumentationSubscribe,
instrumentationReset,
- run
+ run,
+ getCurrentRunLoop,
} from 'ember-metal';
import { EMBER_IMPROVED_INSTRUMENTATION } from 'ember/features';
@@ -93,7 +94,7 @@ moduleFor('EventDispatcher', class extends RenderingTest {
this.registerComponent('x-foo', {
ComponentClass: Component.extend({
change() {
- assert.ok(run.currentRunLoop, 'a run loop should have started');
+ assert.ok(getCurrentRunLoop(), 'a run loop should have started');
}
}),
template: `<input id="is-done" type="checkbox">`
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-glimmer/tests/integration/helpers/closure-action-test.js
|
@@ -1,5 +1,5 @@
import {
- run,
+ getCurrentRunLoop,
set,
computed,
instrumentationSubscribe,
@@ -987,7 +987,7 @@ moduleFor('Helpers test: closure {{action}}', class extends RenderingTest {
let OuterComponent = Component.extend({
actions: {
submit() {
- capturedRunLoop = run.currentRunLoop;
+ capturedRunLoop = getCurrentRunLoop();
}
}
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-glimmer/tests/integration/render-settled-test.js
|
@@ -5,7 +5,7 @@ import {
} from 'internal-test-helpers';
import { renderSettled } from 'ember-glimmer';
import { all } from 'rsvp';
-import { run } from 'ember-metal';
+import { run, schedule } from 'ember-metal';
moduleFor('renderSettled', class extends RenderingTestCase {
['@test resolves when no rendering is happening'](assert) {
@@ -52,14 +52,14 @@ moduleFor('renderSettled', class extends RenderingTestCase {
let promise;
return run(() => {
- run.schedule('actions', null, () => {
+ schedule('actions', null, () => {
this.component.set('foo', 'set in actions');
promise = renderSettled().then(() => {
this.assertText('set in afterRender');
});
- run.schedule('afterRender', null, () => {
+ schedule('afterRender', null, () => {
this.component.set('foo', 'set in afterRender');
});
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-glimmer/tests/unit/outlet-test.js
|
@@ -1,5 +1,5 @@
import { OutletView } from 'ember-glimmer';
-import { run } from 'ember-metal';
+import { run, schedule } from 'ember-metal';
QUnit.module('Glimmer OutletView');
@@ -22,7 +22,7 @@ QUnit.test('render in the render queue', function(assert) {
outletView.appendTo(expectedOutlet);
assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (sync after appendTo)');
- run.schedule('actions', () => assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (in actions)'));
- run.schedule('render', () => assert.equal(didAppendOutletView, 1, 'appendOutletView should be invoked in render'));
+ schedule('actions', () => assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (in actions)'));
+ schedule('render', () => assert.equal(didAppendOutletView, 1, 'appendOutletView should be invoked in render'));
});
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/lib/index.d.ts
|
@@ -6,18 +6,15 @@ interface IBackburner {
scheduleOnce(...args: any[]): void;
schedule(queueName: string, target: Object | null, method: Function | string): void;
}
-interface IRun {
- (...args: any[]): any;
- schedule(...args: any[]): void;
- later(...args: any[]): void;
- join(...args: any[]): void;
- backburner: IBackburner;
- currentRunLoop: boolean;
-}
export function peekMeta(obj: any): any;
-export const run: IRun;
+export function run(...args: any[]): any;
+export function schedule(...args: any[]): void;
+export function later(...args: any[]): void;
+export function join(...args: any[]): void;
+export const backburner: IBackburner;
+export function getCurrentRunLoop(): boolean;
export const PROPERTY_DID_CHANGE: symbol;
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/lib/index.js
|
@@ -67,7 +67,26 @@ export { default as isNone } from './is_none';
export { default as isEmpty } from './is_empty';
export { default as isBlank } from './is_blank';
export { default as isPresent } from './is_present';
-export { default as run } from './run_loop';
+export {
+ getCurrentRunLoop,
+ backburner,
+ run,
+ join,
+ bind,
+ begin,
+ end,
+ schedule,
+ hasScheduledTimers,
+ cancelTimers,
+ later,
+ once,
+ scheduleOnce,
+ next,
+ cancel,
+ debounce,
+ throttle,
+ _globalsRun,
+} from './run_loop';
export {
beginPropertyChanges,
changeProperties,
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/lib/run_loop.js
|
@@ -9,31 +9,49 @@ import {
} from './property_events';
import Backburner from 'backburner';
+let currentRunLoop = null;
+export function getCurrentRunLoop() {
+ return currentRunLoop;
+}
+
function onBegin(current) {
- run.currentRunLoop = current;
+ currentRunLoop = current;
}
function onEnd(current, next) {
- run.currentRunLoop = next;
+ currentRunLoop = next;
}
-const backburner = new Backburner(
- [
- 'sync',
- 'actions',
+/**
+ Array of named queues. This array determines the order in which queues
+ are flushed at the end of the RunLoop. You can define your own queues by
+ simply adding the queue name to this array. Normally you should not need
+ to inspect or modify this property.
+
+ @property queues
+ @type Array
+ @default ['actions', 'destroy']
+ @private
+*/
+export const queues = [
+ 'sync',
+ 'actions',
+
+ // used in router transitions to prevent unnecessary loading state entry
+ // if all context promises resolve on the 'actions' queue first
+ 'routerTransitions',
- // used in router transitions to prevent unnecessary loading state entry
- // if all context promises resolve on the 'actions' queue first
- 'routerTransitions',
+ 'render',
+ 'afterRender',
+ 'destroy',
- 'render',
- 'afterRender',
- 'destroy',
+ // used to re-throw unhandled RSVP rejection errors specifically in this
+ // position to avoid breaking anything rendered in the other sections
+ P`rsvpAfter`
+];
- // used to re-throw unhandled RSVP rejection errors specifically in this
- // position to avoid breaking anything rendered in the other sections
- P`rsvpAfter`
- ],
+export const backburner = new Backburner(
+ queues,
{
sync: {
before: beginPropertyChanges,
@@ -81,7 +99,12 @@ const backburner = new Backburner(
@return {Object} return value from invoking the passed function.
@public
*/
-export default function run() {
+export function run() {
+ return backburner.run(...arguments);
+}
+
+// used for the Ember.run global only
+export function _globalsRun() {
return backburner.run(...arguments);
}
@@ -129,9 +152,9 @@ export default function run() {
when called within an existing loop, no return value is possible.
@public
*/
-run.join = function() {
+export function join() {
return backburner.join(...arguments);
-};
+}
/**
Allows you to specify which context to call the specified function in while
@@ -195,15 +218,11 @@ run.join = function() {
@since 1.4.0
@public
*/
-run.bind = (...curried) => (...args) => run.join(...curried.concat(args));
-
-run.backburner = backburner;
-run.currentRunLoop = null;
-run.queues = backburner.queueNames;
+export const bind = (...curried) => (...args) => join(...curried.concat(args));
/**
Begins a new RunLoop. Any deferred actions invoked after the begin will
- be buffered until you invoke a matching call to `run.end()`. This is
+ be buffered until you invoke a matching call to `end()`. This is
a lower-level way to use a RunLoop instead of using `run()`.
```javascript
@@ -220,13 +239,13 @@ run.queues = backburner.queueNames;
@return {void}
@public
*/
-run.begin = function() {
+export function begin() {
backburner.begin();
-};
+}
/**
Ends a RunLoop. This must be called sometime after you call
- `run.begin()` to flush any deferred actions. This is a lower-level way
+ `begin()` to flush any deferred actions. This is a lower-level way
to use a RunLoop instead of using `run()`.
```javascript
@@ -243,21 +262,9 @@ run.begin = function() {
@return {void}
@public
*/
-run.end = function() {
+export function end() {
backburner.end();
-};
-
-/**
- Array of named queues. This array determines the order in which queues
- are flushed at the end of the RunLoop. You can define your own queues by
- simply adding the queue name to this array. Normally you should not need
- to inspect or modify this property.
-
- @property queues
- @type Array
- @default ['actions', 'destroy']
- @private
-*/
+}
/**
Adds the passed target/method and any optional arguments to the named
@@ -267,7 +274,7 @@ run.end = function() {
At the end of a RunLoop, any methods scheduled in this way will be invoked.
Methods will be invoked in an order matching the named queues defined in
- the `run.queues` property.
+ the `queues` property.
```javascript
import { schedule } from '@ember/runloop';
@@ -292,14 +299,14 @@ run.end = function() {
will be resolved on the target object at the time the scheduled item is
invoked allowing you to change the target function.
@param {Object} [arguments*] Optional arguments to be passed to the queued method.
- @return {*} Timer information for use in canceling, see `run.cancel`.
+ @return {*} Timer information for use in canceling, see `cancel`.
@public
*/
-run.schedule = function(queue /*, target, method */) {
+export function schedule(queue /*, target, method */) {
assert(
`You have turned on testing mode, which disabled the run-loop's autorun. ` +
`You will need to wrap any code with asynchronous side-effects in a run`,
- run.currentRunLoop || !isTesting()
+ currentRunLoop || !isTesting()
);
deprecate(
`Scheduling into the '${queue}' run loop queue is deprecated.`,
@@ -308,17 +315,17 @@ run.schedule = function(queue /*, target, method */) {
);
return backburner.schedule(...arguments);
-};
+}
// Used by global test teardown
-run.hasScheduledTimers = function() {
+export function hasScheduledTimers() {
return backburner.hasTimers();
-};
+}
// Used by global test teardown
-run.cancelTimers = function() {
+export function cancelTimers() {
backburner.cancelTimers();
-};
+}
/**
Invokes the passed target/method and optional arguments after a specified
@@ -347,15 +354,15 @@ run.cancelTimers = function() {
target at the time the method is invoked.
@param {Object} [args*] Optional arguments to pass to the timeout.
@param {Number} wait Number of milliseconds to wait.
- @return {*} Timer information for use in canceling, see `run.cancel`.
+ @return {*} Timer information for use in canceling, see `cancel`.
@public
*/
-run.later = function(/*target, method*/) {
+export function later(/*target, method*/) {
return backburner.later(...arguments);
-};
+}
/**
- Schedule a function to run one time during the current RunLoop. This is equivalent
+ Schedule a function to run one time during the current RunLoop. This is equivalent
to calling `scheduleOnce` with the "actions" queue.
@method once
@@ -366,18 +373,18 @@ run.later = function(/*target, method*/) {
If you pass a string it will be resolved on the
target at the time the method is invoked.
@param {Object} [args*] Optional arguments to pass to the timeout.
- @return {Object} Timer information for use in canceling, see `run.cancel`.
+ @return {Object} Timer information for use in canceling, see `cancel`.
@public
*/
-run.once = function(...args) {
+export function once(...args) {
assert(
`You have turned on testing mode, which disabled the run-loop's autorun. ` +
`You will need to wrap any code with asynchronous side-effects in a run`,
- run.currentRunLoop || !isTesting()
+ currentRunLoop || !isTesting()
);
args.unshift('actions');
return backburner.scheduleOnce(...args);
-};
+}
/**
Schedules a function to run one time in a given queue of the current RunLoop.
@@ -402,7 +409,7 @@ run.once = function(...args) {
});
```
- Also note that for `run.scheduleOnce` to prevent additional calls, you need to
+ Also note that for `scheduleOnce` to prevent additional calls, you need to
pass the same function instance. The following case works as expected:
```javascript
@@ -432,12 +439,12 @@ run.once = function(...args) {
scheduleIt();
scheduleIt();
- // "Closure" will print twice, even though we're using `run.scheduleOnce`,
+ // "Closure" will print twice, even though we're using `scheduleOnce`,
// because the function we pass to it won't match the
// previously scheduled operation.
```
- Available queues, and their order, can be found at `run.queues`
+ Available queues, and their order, can be found at `queues`
@method scheduleOnce
@static
@@ -448,27 +455,27 @@ run.once = function(...args) {
If you pass a string it will be resolved on the
target at the time the method is invoked.
@param {Object} [args*] Optional arguments to pass to the timeout.
- @return {Object} Timer information for use in canceling, see `run.cancel`.
+ @return {Object} Timer information for use in canceling, see `cancel`.
@public
*/
-run.scheduleOnce = function(queue /*, target, method*/) {
+export function scheduleOnce(queue /*, target, method*/) {
assert(
`You have turned on testing mode, which disabled the run-loop's autorun. ` +
`You will need to wrap any code with asynchronous side-effects in a run`,
- run.currentRunLoop || !isTesting()
+ currentRunLoop || !isTesting()
);
deprecate(
`Scheduling into the '${queue}' run loop queue is deprecated.`,
queue !== 'sync',
{ id: 'ember-metal.run.sync', until: '3.5.0' }
);
return backburner.scheduleOnce(...arguments);
-};
+}
/**
Schedules an item to run from within a separate run loop, after
control has been returned to the system. This is equivalent to calling
- `run.later` with a wait time of 1ms.
+ `later` with a wait time of 1ms.
```javascript
import { next } from '@ember/runloop';
@@ -479,12 +486,12 @@ run.scheduleOnce = function(queue /*, target, method*/) {
});
```
- Multiple operations scheduled with `run.next` will coalesce
+ Multiple operations scheduled with `next` will coalesce
into the same later run loop, along with any other operations
- scheduled by `run.later` that expire right around the same
- time that `run.next` operations will fire.
+ scheduled by `later` that expire right around the same
+ time that `next` operations will fire.
- Note that there are often alternatives to using `run.next`.
+ Note that there are often alternatives to using `next`.
For instance, if you'd like to schedule an operation to happen
after all DOM element operations have completed within the current
run loop, you can make use of the `afterRender` run loop queue (added
@@ -513,16 +520,16 @@ run.scheduleOnce = function(queue /*, target, method*/) {
});
```
- One benefit of the above approach compared to using `run.next` is
+ One benefit of the above approach compared to using `next` is
that you will be able to perform DOM/CSS operations before unprocessed
elements are rendered to the screen, which may prevent flickering or
other artifacts caused by delaying processing until after rendering.
- The other major benefit to the above approach is that `run.next`
+ The other major benefit to the above approach is that `next`
introduces an element of non-determinism, which can make things much
harder to test, due to its reliance on `setTimeout`; it's much harder
to guarantee the order of scheduled operations when they are scheduled
- outside of the current run loop, i.e. with `run.next`.
+ outside of the current run loop, i.e. with `next`.
@method next
@static
@@ -532,13 +539,13 @@ run.scheduleOnce = function(queue /*, target, method*/) {
If you pass a string it will be resolved on the
target at the time the method is invoked.
@param {Object} [args*] Optional arguments to pass to the timeout.
- @return {Object} Timer information for use in canceling, see `run.cancel`.
+ @return {Object} Timer information for use in canceling, see `cancel`.
@public
*/
-run.next = function(...args) {
+export function next(...args) {
args.push(1);
return backburner.later(...args);
-};
+}
/**
Cancels a scheduled item. Must be a value returned by `later()`,
@@ -607,9 +614,9 @@ run.next = function(...args) {
@return {Boolean} true if canceled or false/undefined if it wasn't found
@public
*/
-run.cancel = function(timer) {
+export function cancel(timer) {
return backburner.cancel(timer);
-};
+}
/**
Delay calling the target method until the debounce period has elapsed
@@ -682,12 +689,12 @@ run.cancel = function(timer) {
@param {Number} wait Number of milliseconds to wait.
@param {Boolean} immediate Trigger the function on the leading instead
of the trailing edge of the wait interval. Defaults to false.
- @return {Array} Timer information for use in canceling, see `run.cancel`.
+ @return {Array} Timer information for use in canceling, see `cancel`.
@public
*/
-run.debounce = function() {
+export function debounce() {
return backburner.debounce(...arguments);
-};
+}
/**
Ensure that the target method is never called more frequently than
@@ -729,9 +736,9 @@ run.debounce = function() {
@param {Number} spacing Number of milliseconds to space out requests.
@param {Boolean} immediate Trigger the function on the leading instead
of the trailing edge of the wait interval. Defaults to true.
- @return {Array} Timer information for use in canceling, see `run.cancel`.
+ @return {Array} Timer information for use in canceling, see `cancel`.
@public
*/
-run.throttle = function() {
+export function throttle() {
return backburner.throttle(...arguments);
-};
+}
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/lib/tags.js
|
@@ -2,7 +2,7 @@ import { CONSTANT_TAG, UpdatableTag, DirtyableTag, combine } from '@glimmer/refe
import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';
import { meta as metaFor } from './meta';
import { isProxy } from './is_proxy';
-import run from './run_loop';
+import { backburner } from './run_loop';
let hasViews = () => false;
@@ -85,12 +85,7 @@ export function markObjectAsDirty(obj, propertyKey, meta) {
}
}
-let backburner;
function ensureRunloop() {
- if (backburner === undefined) {
- backburner = run.backburner;
- }
-
if (hasViews()) {
backburner.ensureInstance();
}
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/tests/run_loop/debounce_test.js
|
@@ -1,4 +1,4 @@
-import { run } from '../..';
+import { debounce } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor('debounce', class extends AbstractTestCase {
@@ -12,9 +12,9 @@ moduleFor('debounce', class extends AbstractTestCase {
}
};
- run.debounce(target, target.someFunc, 10);
- run.debounce(target, target.someFunc, 10);
- run.debounce(target, target.someFunc, 10);
+ debounce(target, target.someFunc, 10);
+ debounce(target, target.someFunc, 10);
+ debounce(target, target.someFunc, 10);
setTimeout(() => {
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments');
@@ -32,9 +32,9 @@ moduleFor('debounce', class extends AbstractTestCase {
}
};
- run.debounce(target, 'someFunc', 10);
- run.debounce(target, 'someFunc', 10);
- run.debounce(target, 'someFunc', 10);
+ debounce(target, 'someFunc', 10);
+ debounce(target, 'someFunc', 10);
+ debounce(target, 'someFunc', 10);
setTimeout(() => {
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments');
@@ -50,9 +50,9 @@ moduleFor('debounce', class extends AbstractTestCase {
calledWith.push(args);
}
- run.debounce(someFunc, 10);
- run.debounce(someFunc, 10);
- run.debounce(someFunc, 10);
+ debounce(someFunc, 10);
+ debounce(someFunc, 10);
+ debounce(someFunc, 10);
setTimeout(() => {
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments');
@@ -68,9 +68,9 @@ moduleFor('debounce', class extends AbstractTestCase {
calledWith.push(args);
}
- run.debounce(someFunc, { isFoo: true }, 10);
- run.debounce(someFunc, { isBar: true }, 10);
- run.debounce(someFunc, { isBaz: true }, 10);
+ debounce(someFunc, { isFoo: true }, 10);
+ debounce(someFunc, { isBar: true }, 10);
+ debounce(someFunc, { isBaz: true }, 10);
setTimeout(() => {
assert.deepEqual(calledWith, [ [ { isBaz: true } ] ], 'someFunc called once with correct arguments');
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/tests/run_loop/later_test.js
|
@@ -1,16 +1,23 @@
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import { assign } from 'ember-utils';
-import { run, isNone } from '../..';
+import {
+ run,
+ later,
+ backburner,
+ isNone,
+ hasScheduledTimers,
+ getCurrentRunLoop,
+} from '../..';
const originalSetTimeout = window.setTimeout;
const originalDateValueOf = Date.prototype.valueOf;
-const originalPlatform = run.backburner._platform;
+const originalPlatform = backburner._platform;
function wait(callback, maxWaitCount) {
maxWaitCount = isNone(maxWaitCount) ? 100 : maxWaitCount;
originalSetTimeout(() => {
- if (maxWaitCount > 0 && (run.hasScheduledTimers() || run.currentRunLoop)) {
+ if (maxWaitCount > 0 && (hasScheduledTimers() || getCurrentRunLoop())) {
wait(callback, maxWaitCount - 1);
return;
@@ -21,9 +28,9 @@ function wait(callback, maxWaitCount) {
}
// Synchronous "sleep". This simulates work being done
-// after run.later was called but before the run loop
+// after later was called but before the run loop
// has flushed. In previous versions, this would have
-// caused the run.later callback to have run from
+// caused the later callback to have run from
// within the run loop flush, since by the time the
// run loop has to flush, it would have considered
// the timer already expired.
@@ -33,7 +40,7 @@ function pauseUntil(time) {
moduleFor('run.later', class extends AbstractTestCase {
teardown() {
- run.backburner._platform = originalPlatform;
+ backburner._platform = originalPlatform;
window.setTimeout = originalSetTimeout;
Date.prototype.valueOf = originalDateValueOf;
}
@@ -43,7 +50,7 @@ moduleFor('run.later', class extends AbstractTestCase {
let invoked = false;
run(() => {
- run.later(() => invoked = true, 100);
+ later(() => invoked = true, 100);
});
wait(() => {
@@ -57,7 +64,7 @@ moduleFor('run.later', class extends AbstractTestCase {
let obj = { invoked: false };
run(() => {
- run.later(obj, function() { this.invoked = true; }, 100);
+ later(obj, function() { this.invoked = true; }, 100);
});
wait(() => {
@@ -71,7 +78,7 @@ moduleFor('run.later', class extends AbstractTestCase {
let obj = { invoked: 0 };
run(() => {
- run.later(obj, function(amt) { this.invoked += amt; }, 10, 100);
+ later(obj, function(amt) { this.invoked += amt; }, 10, 100);
});
wait(() => {
@@ -86,18 +93,18 @@ moduleFor('run.later', class extends AbstractTestCase {
let firstRunLoop, secondRunLoop;
run(() => {
- firstRunLoop = run.currentRunLoop;
+ firstRunLoop = getCurrentRunLoop();
- run.later(obj, function(amt) {
+ later(obj, function(amt) {
this.invoked += amt;
- secondRunLoop = run.currentRunLoop;
+ secondRunLoop = getCurrentRunLoop();
}, 10, 1);
pauseUntil(+new Date() + 100);
});
assert.ok(firstRunLoop, 'first run loop captured');
- assert.ok(!run.currentRunLoop, 'shouldn\'t be in a run loop after flush');
+ assert.ok(!getCurrentRunLoop(), 'shouldn\'t be in a run loop after flush');
assert.equal(obj.invoked, 0, 'shouldn\'t have invoked later item yet');
wait(() => {
@@ -117,11 +124,11 @@ moduleFor('run.later', class extends AbstractTestCase {
// function fn(val) { array.push(val); }
// run(function() {
- // run.later(this, fn, 4, 5);
- // run.later(this, fn, 1, 1);
- // run.later(this, fn, 5, 10);
- // run.later(this, fn, 2, 3);
- // run.later(this, fn, 3, 3);
+ // later(this, fn, 4, 5);
+ // later(this, fn, 1, 1);
+ // later(this, fn, 5, 10);
+ // later(this, fn, 2, 3);
+ // later(this, fn, 3, 3);
// });
// deepEqual(array, []);
@@ -139,18 +146,18 @@ moduleFor('run.later', class extends AbstractTestCase {
// asyncTest('callbacks coalesce into same run loop if expiring at the same time', function() {
// let array = [];
- // function fn(val) { array.push(run.currentRunLoop); }
+ // function fn(val) { array.push(getCurrentRunLoop()); }
// run(function() {
// // Force +new Date to return the same result while scheduling
- // // run.later timers. Otherwise: non-determinism!
+ // // later timers. Otherwise: non-determinism!
// let now = +new Date();
// Date.prototype.valueOf = function() { return now; };
- // run.later(this, fn, 10);
- // run.later(this, fn, 200);
- // run.later(this, fn, 200);
+ // later(this, fn, 10);
+ // later(this, fn, 200);
+ // later(this, fn, 200);
// Date.prototype.valueOf = originalDateValueOf;
// });
@@ -167,21 +174,21 @@ moduleFor('run.later', class extends AbstractTestCase {
// });
// });
- ['@test inception calls to run.later should run callbacks in separate run loops'](assert) {
+ ['@test inception calls to later should run callbacks in separate run loops'](assert) {
let done = assert.async();
let runLoop, finished;
run(() => {
- runLoop = run.currentRunLoop;
+ runLoop = getCurrentRunLoop();
assert.ok(runLoop);
- run.later(() => {
- assert.ok(run.currentRunLoop && run.currentRunLoop !== runLoop,
+ later(() => {
+ assert.ok(getCurrentRunLoop() && getCurrentRunLoop() !== runLoop,
'first later callback has own run loop');
- runLoop = run.currentRunLoop;
+ runLoop = getCurrentRunLoop();
- run.later(() => {
- assert.ok(run.currentRunLoop && run.currentRunLoop !== runLoop,
+ later(() => {
+ assert.ok(getCurrentRunLoop() && getCurrentRunLoop() !== runLoop,
'second later callback has own run loop');
finished = true;
}, 40);
@@ -203,7 +210,7 @@ moduleFor('run.later', class extends AbstractTestCase {
// happens when an expired timer callback takes a while to run,
// which is what we simulate here.
let newSetTimeoutUsed;
- run.backburner._platform = assign({}, originalPlatform, {
+ backburner._platform = assign({}, originalPlatform, {
setTimeout() {
let wait = arguments[arguments.length - 1];
newSetTimeoutUsed = true;
@@ -215,7 +222,7 @@ moduleFor('run.later', class extends AbstractTestCase {
let count = 0;
run(() => {
- run.later(() => {
+ later(() => {
count++;
// This will get run first. Waste some time.
@@ -227,7 +234,7 @@ moduleFor('run.later', class extends AbstractTestCase {
pauseUntil(+new Date() + 60);
}, 1);
- run.later(() => {
+ later(() => {
assert.equal(count, 1, 'callbacks called in order');
}, 50);
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/tests/run_loop/next_test.js
|
@@ -1,12 +1,12 @@
-import { run } from '../..';
+import { run, next, getCurrentRunLoop } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor('run.next', class extends AbstractTestCase {
['@test should invoke immediately on next timeout'](assert) {
let done = assert.async();
let invoked = false;
- run(() => run.next(() => invoked = true));
+ run(() => next(() => invoked = true));
assert.equal(invoked, false, 'should not have invoked yet');
@@ -20,8 +20,8 @@ moduleFor('run.next', class extends AbstractTestCase {
let done = assert.async();
let firstRunLoop, secondRunLoop;
run(() => {
- firstRunLoop = run.currentRunLoop;
- run.next(() => secondRunLoop = run.currentRunLoop);
+ firstRunLoop = getCurrentRunLoop();
+ next(() => secondRunLoop = getCurrentRunLoop());
});
setTimeout(() => {
@@ -31,12 +31,12 @@ moduleFor('run.next', class extends AbstractTestCase {
}, 20);
}
- ['@test multiple calls to run.next share coalesce callbacks into same run loop'](assert) {
+ ['@test multiple calls to next share coalesce callbacks into same run loop'](assert) {
let done = assert.async();
let secondRunLoop, thirdRunLoop;
run(() => {
- run.next(() => secondRunLoop = run.currentRunLoop);
- run.next(() => thirdRunLoop = run.currentRunLoop);
+ next(() => secondRunLoop = getCurrentRunLoop());
+ next(() => thirdRunLoop = getCurrentRunLoop());
});
setTimeout(() => {
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/tests/run_loop/once_test.js
|
@@ -1,14 +1,14 @@
-import { run } from '../..';
+import { run, getCurrentRunLoop, once } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor('system/run_loop/once_test', class extends AbstractTestCase {
['@test calling invokeOnce more than once invokes only once'](assert) {
let count = 0;
run(() => {
function F() { count++; }
- run.once(F);
- run.once(F);
- run.once(F);
+ once(F);
+ once(F);
+ once(F);
});
assert.equal(count, 1, 'should have invoked once');
@@ -19,10 +19,10 @@ moduleFor('system/run_loop/once_test', class extends AbstractTestCase {
let B = { count: 0 };
run(() => {
function F() { this.count++; }
- run.once(A, F);
- run.once(B, F);
- run.once(A, F);
- run.once(B, F);
+ once(A, F);
+ once(B, F);
+ once(A, F);
+ once(B, F);
});
assert.equal(A.count, 1, 'should have invoked once on A');
@@ -36,10 +36,10 @@ moduleFor('system/run_loop/once_test', class extends AbstractTestCase {
run(() => {
function F(amt) { this.count += amt; }
- run.once(A, F, 10);
- run.once(B, F, 20);
- run.once(A, F, 30);
- run.once(B, F, 40);
+ once(A, F, 10);
+ once(B, F, 20);
+ once(A, F, 30);
+ once(B, F, 40);
});
assert.equal(A.count, 30, 'should have invoked once on A');
@@ -48,7 +48,7 @@ moduleFor('system/run_loop/once_test', class extends AbstractTestCase {
['@test should be inside of a runloop when running'](assert) {
run(() => {
- run.once(() => assert.ok(!!run.currentRunLoop, 'should have a runloop'));
+ once(() => assert.ok(!!getCurrentRunLoop(), 'should have a runloop'));
});
}
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/tests/run_loop/run_bind_test.js
|
@@ -1,4 +1,4 @@
-import { run } from '../..';
+import { bind, getCurrentRunLoop } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor('system/run_loop/run_bind_test', class extends AbstractTestCase {
@@ -8,12 +8,12 @@ moduleFor('system/run_loop/run_bind_test', class extends AbstractTestCase {
let obj = {
value: 0,
increment(increment) {
- assert.ok(run.currentRunLoop, 'expected a run-loop');
+ assert.ok(getCurrentRunLoop(), 'expected a run-loop');
return this.value += increment;
}
};
- let proxiedFunction = run.bind(obj, obj.increment, 1);
+ let proxiedFunction = bind(obj, obj.increment, 1);
assert.equal(proxiedFunction(), 1);
assert.equal(obj.value, 1);
}
@@ -22,7 +22,7 @@ moduleFor('system/run_loop/run_bind_test', class extends AbstractTestCase {
assert.expect(4);
function asyncCallback(increment, increment2, increment3) {
- assert.ok(run.currentRunLoop, 'expected a run-loop');
+ assert.ok(getCurrentRunLoop(), 'expected a run-loop');
assert.equal(increment, 1);
assert.equal(increment2, 2);
assert.equal(increment3, 3);
@@ -32,6 +32,6 @@ moduleFor('system/run_loop/run_bind_test', class extends AbstractTestCase {
fn(2, 3);
}
- asyncFunction(run.bind(asyncCallback, asyncCallback, 1));
+ asyncFunction(bind(asyncCallback, asyncCallback, 1));
}
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/tests/run_loop/schedule_test.js
|
@@ -1,13 +1,13 @@
-import { run } from '../..';
+import { run, cancel, schedule, getCurrentRunLoop } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor('system/run_loop/schedule_test', class extends AbstractTestCase {
['@test scheduling item in queue should defer until finished'](assert) {
let cnt = 0;
run(() => {
- run.schedule('actions', () => cnt++);
- run.schedule('actions', () => cnt++);
+ schedule('actions', () => cnt++);
+ schedule('actions', () => cnt++);
assert.equal(cnt, 0, 'should not run action yet');
});
@@ -18,8 +18,8 @@ moduleFor('system/run_loop/schedule_test', class extends AbstractTestCase {
let hasRan = false;
run(() => {
- let cancelId = run.schedule('actions', () => hasRan = true);
- run.cancel(cancelId);
+ let cancelId = schedule('actions', () => hasRan = true);
+ cancel(cancelId);
});
assert.notOk(hasRan, 'should not have ran callback run');
@@ -29,11 +29,11 @@ moduleFor('system/run_loop/schedule_test', class extends AbstractTestCase {
let cnt = 0;
run(() => {
- run.schedule('actions', () => cnt++);
+ schedule('actions', () => cnt++);
assert.equal(cnt, 0, 'should not run action yet');
run(() => {
- run.schedule('actions', () => cnt++);
+ schedule('actions', () => cnt++);
});
assert.equal(cnt, 1, 'should not run action yet');
});
@@ -45,46 +45,46 @@ moduleFor('system/run_loop/schedule_test', class extends AbstractTestCase {
let order = [];
run(() => {
- let runLoop = run.currentRunLoop;
+ let runLoop = getCurrentRunLoop();
assert.ok(runLoop, 'run loop present');
expectDeprecation(() => {
- run.schedule('sync', () => {
+ schedule('sync', () => {
order.push('sync');
- assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
+ assert.equal(runLoop, getCurrentRunLoop(), 'same run loop used');
});
}, `Scheduling into the 'sync' run loop queue is deprecated.`);
- run.schedule('actions', () => {
+ schedule('actions', () => {
order.push('actions');
- assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
+ assert.equal(runLoop, getCurrentRunLoop(), 'same run loop used');
- run.schedule('actions', () => {
+ schedule('actions', () => {
order.push('actions');
- assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
+ assert.equal(runLoop, getCurrentRunLoop(), 'same run loop used');
});
expectDeprecation(() => {
- run.schedule('sync', () => {
+ schedule('sync', () => {
order.push('sync');
- assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
+ assert.equal(runLoop, getCurrentRunLoop(), 'same run loop used');
});
}, `Scheduling into the 'sync' run loop queue is deprecated.`);
});
- run.schedule('destroy', () => {
+ schedule('destroy', () => {
order.push('destroy');
- assert.equal(runLoop, run.currentRunLoop, 'same run loop used');
+ assert.equal(runLoop, getCurrentRunLoop(), 'same run loop used');
});
});
assert.deepEqual(order, ['sync', 'actions', 'sync', 'actions', 'destroy']);
}
['@test makes sure it does not trigger an autorun during testing']() {
- expectAssertion(() => run.schedule('actions', () => {}), /wrap any code with asynchronous side-effects in a run/);
+ expectAssertion(() => schedule('actions', () => {}), /wrap any code with asynchronous side-effects in a run/);
// make sure not just the first violation is asserted.
- expectAssertion(() => run.schedule('actions', () => {}), /wrap any code with asynchronous side-effects in a run/);
+ expectAssertion(() => schedule('actions', () => {}), /wrap any code with asynchronous side-effects in a run/);
}
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/tests/run_loop/sync_test.js
|
@@ -1,4 +1,4 @@
-import { run } from '../..';
+import { run, schedule } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor('system/run_loop/sync_test', class extends AbstractTestCase {
@@ -11,10 +11,10 @@ moduleFor('system/run_loop/sync_test', class extends AbstractTestCase {
function syncfunc() {
if (++cnt < 5) {
expectDeprecation(() => {
- run.schedule('sync', syncfunc);
+ schedule('sync', syncfunc);
}, `Scheduling into the 'sync' run loop queue is deprecated.`);
}
- run.schedule('actions', cntup);
+ schedule('actions', cntup);
}
syncfunc();
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-metal/tests/run_loop/unwind_test.js
|
@@ -1,40 +1,34 @@
-import { run } from '../..';
+import { run, schedule, getCurrentRunLoop } from '../..';
import { Error as EmberError } from 'ember-debug';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
moduleFor('system/run_loop/unwind_test', class extends AbstractTestCase {
['@test RunLoop unwinds despite unhandled exception'](assert) {
- let initialRunLoop = run.currentRunLoop;
+ let initialRunLoop = getCurrentRunLoop();
assert.throws(() => {
run(() => {
- run.schedule('actions', function() { throw new EmberError('boom!'); });
+ schedule('actions', function() { throw new EmberError('boom!'); });
});
}, Error, 'boom!');
// The real danger at this point is that calls to autorun will stick
// tasks into the already-dead runloop, which will never get
// flushed. I can't easily demonstrate this in a unit test because
// autorun explicitly doesn't work in test mode. - ef4
- assert.equal(run.currentRunLoop, initialRunLoop, 'Previous run loop should be cleaned up despite exception');
-
- // Prevent a failure in this test from breaking subsequent tests.
- run.currentRunLoop = initialRunLoop;
+ assert.equal(getCurrentRunLoop(), initialRunLoop, 'Previous run loop should be cleaned up despite exception');
}
['@test run unwinds despite unhandled exception'](assert) {
- var initialRunLoop = run.currentRunLoop;
+ var initialRunLoop = getCurrentRunLoop();
assert.throws(() => {
run(function() {
throw new EmberError('boom!');
});
}, EmberError, 'boom!');
- assert.equal(run.currentRunLoop, initialRunLoop, 'Previous run loop should be cleaned up despite exception');
-
- // Prevent a failure in this test from breaking subsequent tests.
- run.currentRunLoop = initialRunLoop;
+ assert.equal(getCurrentRunLoop(), initialRunLoop, 'Previous run loop should be cleaned up despite exception');
}
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-routing/lib/location/hash_location.js
|
@@ -1,7 +1,7 @@
import {
get,
set,
- run
+ bind
} from 'ember-metal';
import { Object as EmberObject } from 'ember-runtime';
@@ -127,7 +127,7 @@ export default EmberObject.extend({
onUpdateURL(callback) {
this._removeEventListener();
- this._hashchangeHandler = run.bind(this, function() {
+ this._hashchangeHandler = bind(this, function() {
let path = this.getURL();
if (get(this, 'lastSetURL') === path) { return; }
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-routing/lib/system/route.js
|
@@ -5,7 +5,7 @@ import {
getProperties,
setProperties,
computed,
- run,
+ once,
isEmpty
} from 'ember-metal';
import { assert, info, isTesting, deprecate } from 'ember-debug';
@@ -2082,7 +2082,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
let renderOptions = buildRenderOptions(this, isDefaultRender, name, options);
this.connections.push(renderOptions);
- run.once(this._router, '_setOutlets');
+ once(this._router, '_setOutlets');
},
/**
@@ -2193,7 +2193,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
controller: undefined,
template: undefined,
};
- run.once(this._router, '_setOutlets');
+ once(this._router, '_setOutlets');
}
}
},
@@ -2210,7 +2210,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
teardownViews() {
if (this.connections && this.connections.length > 0) {
this.connections = [];
- run.once(this._router, '_setOutlets');
+ once(this._router, '_setOutlets');
}
}
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-routing/lib/system/router.js
|
@@ -7,7 +7,11 @@ import {
set,
defineProperty,
computed,
- run
+ run,
+ once,
+ scheduleOnce,
+ schedule,
+ cancel,
} from 'ember-metal';
import {
Error as EmberError,
@@ -258,7 +262,7 @@ const EmberRouter = EmberObject.extend(Evented, {
// Put this in the runloop so url will be accurate. Seems
// less surprising than didTransition being out of sync.
- run.once(this, this.trigger, 'didTransition');
+ once(this, this.trigger, 'didTransition');
if (DEBUG) {
if (get(this, 'namespace').LOG_TRANSITIONS) {
@@ -332,7 +336,7 @@ const EmberRouter = EmberObject.extend(Evented, {
@since 1.11.0
*/
willTransition(oldInfos, newInfos, transition) {
- run.once(this, this.trigger, 'willTransition', transition);
+ once(this, this.trigger, 'willTransition', transition);
if (DEBUG) {
if (get(this, 'namespace').LOG_TRANSITIONS) {
@@ -486,7 +490,7 @@ const EmberRouter = EmberObject.extend(Evented, {
*/
_activeQPChanged(queryParameterName, newValue) {
this._queuedQPChanges[queryParameterName] = newValue;
- run.once(this, this._fireQueryParamTransition);
+ once(this, this._fireQueryParamTransition);
},
_updatingQPChanged(queryParameterName) {
@@ -633,7 +637,7 @@ const EmberRouter = EmberObject.extend(Evented, {
routerMicrolib.updateURL = path => {
lastURL = path;
- run.once(doUpdateURL);
+ once(doUpdateURL);
};
if (location.replaceURL) {
@@ -644,7 +648,7 @@ const EmberRouter = EmberObject.extend(Evented, {
routerMicrolib.replaceURL = path => {
lastURL = path;
- run.once(doReplaceURL);
+ once(doReplaceURL);
};
}
@@ -985,7 +989,7 @@ const EmberRouter = EmberObject.extend(Evented, {
_scheduleLoadingEvent(transition, originRoute) {
this._cancelSlowTransitionTimer();
- this._slowTransitionTimer = run.scheduleOnce('routerTransitions', this, '_handleSlowTransition', transition, originRoute);
+ this._slowTransitionTimer = scheduleOnce('routerTransitions', this, '_handleSlowTransition', transition, originRoute);
},
currentState: null,
@@ -1008,7 +1012,7 @@ const EmberRouter = EmberObject.extend(Evented, {
_cancelSlowTransitionTimer() {
if (this._slowTransitionTimer) {
- run.cancel(this._slowTransitionTimer);
+ cancel(this._slowTransitionTimer);
}
this._slowTransitionTimer = null;
},
@@ -1527,7 +1531,7 @@ function appendOrphan(liveRoutes, into, myState) {
};
}
liveRoutes.outlets.__ember_orphans__.outlets[into] = myState;
- run.schedule('afterRender', () => {
+ schedule('afterRender', () => {
// `wasUsed` gets set by the render helper.
assert(`You attempted to render into '${into}' but it was not found`,
liveRoutes.outlets.__ember_orphans__.outlets[into].wasUsed);
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-runtime/lib/ext/rsvp.js
|
@@ -1,13 +1,11 @@
import * as RSVP from 'rsvp';
import {
- run,
+ backburner,
getDispatchOverride
} from 'ember-metal';
import { assert } from 'ember-debug';
import { privatize as P } from 'container';
-const backburner = run.backburner;
-
RSVP.configure('async', (callback, promise) => {
backburner.schedule('actions', null, callback, promise);
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-runtime/lib/system/core_object.js
|
@@ -25,7 +25,7 @@ import {
defineProperty,
ComputedProperty,
InjectedProperty,
- run,
+ schedule,
deleteMeta,
descriptor
} from 'ember-metal';
@@ -36,7 +36,6 @@ import { DEBUG } from 'ember-env-flags';
import { ENV } from 'ember-environment';
import { MANDATORY_GETTER, MANDATORY_SETTER, EMBER_METAL_ES5_GETTERS } from 'ember/features';
-const schedule = run.schedule;
const applyMixin = Mixin._apply;
const reopen = Mixin.prototype.reopen;
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-runtime/tests/ext/rsvp_test.js
|
@@ -1,7 +1,9 @@
import {
setOnerror,
getOnerror,
- run
+ run,
+ schedule,
+ next,
} from 'ember-metal';
import RSVP from '../../ext/rsvp';
import { isTesting, setTesting } from 'ember-debug';
@@ -177,20 +179,20 @@ QUnit.test('handled within the same micro-task (via Ember.RVP.Promise)', functio
QUnit.test('handled within the same micro-task (via direct run-loop)', function(assert) {
run(function() {
let rejection = RSVP.Promise.reject(reason);
- run.schedule('afterRender', () => rejection.catch(function() { }));
+ schedule('afterRender', () => rejection.catch(function() { }));
}); // handled, we shouldn't need to assert.
assert.ok(true, 'reached end of test');
});
-QUnit.test('handled in the next microTask queue flush (run.next)', function(assert) {
+QUnit.test('handled in the next microTask queue flush (next)', function(assert) {
assert.expect(2);
let done = assert.async();
assert.throws(function() {
run(function() {
let rejection = RSVP.Promise.reject(reason);
- run.next(() => {
+ next(() => {
rejection.catch(function() { });
assert.ok(true, 'reached end of test');
done();
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-testing/lib/ext/rsvp.js
|
@@ -1,5 +1,5 @@
import { RSVP } from 'ember-runtime';
-import { run } from 'ember-metal';
+import { backburner } from 'ember-metal';
import { isTesting } from 'ember-debug';
import {
asyncStart,
@@ -8,14 +8,14 @@ import {
RSVP.configure('async', function(callback, promise) {
// if schedule will cause autorun, we need to inform adapter
- if (isTesting() && !run.backburner.currentInstance) {
+ if (isTesting() && !backburner.currentInstance) {
asyncStart();
- run.backburner.schedule('actions', () => {
+ backburner.schedule('actions', () => {
asyncEnd();
callback(promise);
});
} else {
- run.backburner.schedule('actions', () => callback(promise));
+ backburner.schedule('actions', () => callback(promise));
}
});
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-testing/lib/helpers/wait.js
|
@@ -3,7 +3,7 @@
*/
import { checkWaiters } from '../test/waiters';
import { RSVP } from 'ember-runtime';
-import { run } from 'ember-metal';
+import { getCurrentRunLoop, hasScheduledTimers, run } from 'ember-metal';
import { pendingRequests } from '../test/pending_requests';
/**
@@ -50,7 +50,7 @@ export default function wait(app, value) {
if (pendingRequests()) { return; }
// 3. If there are scheduled timers or we are inside of a run loop, keep polling
- if (run.hasScheduledTimers() || run.currentRunLoop) { return; }
+ if (hasScheduledTimers() || getCurrentRunLoop()) { return; }
if (checkWaiters()) {
return;
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-testing/lib/test/run.js
|
@@ -1,7 +1,7 @@
-import { run as emberRun } from 'ember-metal';
+import { run as emberRun, getCurrentRunLoop } from 'ember-metal';
export default function run(fn) {
- if (!emberRun.currentRunLoop) {
+ if (!getCurrentRunLoop()) {
return emberRun(fn);
} else {
return fn();
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-testing/tests/acceptance_test.js
|
@@ -3,7 +3,7 @@ import {
AutobootApplicationTestCase
} from 'internal-test-helpers';
-import { run } from 'ember-metal';
+import { later } from 'ember-metal';
import Test from '../test';
import QUnitAdapter from '../adapters/qunit';
import { Route } from 'ember-routing';
@@ -85,7 +85,7 @@ if (!jQueryDisabled) {
this.application.setupForTesting();
Test.registerAsyncHelper('slowHelper', () => {
- return new RSVP.Promise(resolve => run.later(resolve, 10));
+ return new RSVP.Promise(resolve => later(resolve, 10));
});
this.application.injectTestHelpers();
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-testing/tests/adapters_test.js
|
@@ -1,4 +1,4 @@
-import { run, setOnerror } from 'ember-metal';
+import { run, next, setOnerror } from 'ember-metal';
import Test from '../test';
import Adapter from '../adapters/adapter';
import QUnitAdapter from '../adapters/qunit';
@@ -21,7 +21,7 @@ function runThatThrowsSync(message = 'Error for testing error handling') {
}
function runThatThrowsAsync(message = 'Error for testing error handling') {
- return run.next(() => {
+ return next(() => {
throw new Error(message);
});
}
@@ -201,12 +201,12 @@ moduleFor('ember-testing Adapters', class extends AdapterSetupAndTearDown {
Test.adapter ={
exception() {
- assert.notOk(true, 'Adapter.exception is not called for errors thrown in run.next');
+ assert.notOk(true, 'Adapter.exception is not called for errors thrown in next');
}
};
setOnerror(function() {
- assert.ok(true, 'onerror is invoked for errors thrown in run.next/run.later');
+ assert.ok(true, 'onerror is invoked for errors thrown in next/later');
});
runThatThrowsAsync();
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-testing/tests/ext/rsvp_test.js
|
@@ -1,7 +1,7 @@
import RSVP from '../../ext/rsvp';
import { getAdapter, setAdapter } from '../../test/adapter';
import TestPromise, { getLastPromise } from '../../test/promise';
-import { run } from 'ember-metal';
+import { getCurrentRunLoop } from 'ember-metal';
import { isTesting, setTesting } from 'ember-debug';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
@@ -36,7 +36,7 @@ moduleFor('ember-testing RSVP', class extends AbstractTestCase {
let done = assert.async();
assert.expect(19);
- assert.ok(!run.currentRunLoop, 'expect no run-loop');
+ assert.ok(!getCurrentRunLoop(), 'expect no run-loop');
setTesting(true);
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-testing/tests/helpers_test.js
|
@@ -9,7 +9,7 @@ import {
Controller,
RSVP
} from 'ember-runtime';
-import { run } from 'ember-metal';
+import { later } from 'ember-metal';
import {
Component,
} from 'ember-glimmer';
@@ -561,7 +561,7 @@ if (!jQueryDisabled) {
});
let waitDone = false;
- run.later(() => {
+ later(() => {
waitDone = true;
}, 20);
@@ -896,7 +896,7 @@ if (!jQueryDisabled) {
afterEach() {
setDebugFunction('info', originalInfo);
}
-
+
constructor() {
super();
this.runTask(() => {
@@ -909,7 +909,8 @@ if (!jQueryDisabled) {
// overwrite info to supress the console output (see https://github.com/emberjs/ember.js/issues/16391)
setDebugFunction('info', noop);
- let {application: {testHelpers: {andThen, pauseTest}}} = this;
+ let { andThen, pauseTest } = this.application.testHelpers;
+
andThen(() => {
Test.adapter.asyncStart = () => {
assert.ok(
@@ -929,7 +930,7 @@ if (!jQueryDisabled) {
let {application: {testHelpers: {pauseTest, resumeTest}}} = this;
- run.later(() => resumeTest(), 20);
+ later(() => resumeTest(), 20);
return pauseTest().then(() => {
assert.ok(true, 'pauseTest promise was resolved');
});
@@ -1138,7 +1139,7 @@ if (!jQueryDisabled) {
* at least one tick to test whether wait() held off while the
* async router was still loading. 20ms should be enough.
*/
- run.later(resolve, {firstName: 'Tom'}, 20);
+ later(resolve, {firstName: 'Tom'}, 20);
});
this.add('route:user', Route.extend({
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember-views/lib/views/states/has_element.js
|
@@ -1,6 +1,6 @@
import { assign } from 'ember-utils';
import _default from './default';
-import { run, flaggedInstrument } from 'ember-metal';
+import { join, flaggedInstrument } from 'ember-metal';
const hasElement = Object.create(_default);
@@ -20,7 +20,7 @@ assign(hasElement, {
// Handler should be able to re-dispatch events, so we don't
// preventDefault or stopPropagation.
return flaggedInstrument(`interaction.${eventName}`, { event, view }, () => {
- return run.join(view, view.trigger, eventName, event);
+ return join(view, view.trigger, eventName, event);
});
} else {
return true; // continue event propagation
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember/lib/index.js
|
@@ -85,7 +85,28 @@ Ember.isNone = metal.isNone;
Ember.isEmpty = metal.isEmpty;
Ember.isBlank = metal.isBlank;
Ember.isPresent = metal.isPresent;
-Ember.run = metal.run;
+// Using _globalsRun here so that mutating the function (adding `next`,
+// `later`, etc to it) does not appear available throughout the rest of the
+// codebase. This is specifically to ensure that we do not accidentally
+// regress and write `run.next`, etc...
+Ember.run = metal._globalsRun;
+Ember.run.backburner = metal.backburner;
+Ember.run.begin = metal.begin;
+Ember.run.bind = metal.bind;
+Ember.run.cancel = metal.cancel;
+Ember.run.debounce = metal.debounce;
+Ember.run.end = metal.end;
+Ember.run.join = metal.join;
+Ember.run.later = metal.later;
+Ember.run.next = metal.next;
+Ember.run.once = metal.once;
+Ember.run.schedule = metal.schedule;
+Ember.run.scheduleOnce = metal.scheduleOnce;
+Ember.run.throttle = metal.throttle;
+Object.defineProperty(Ember.run, 'currentRunLoop', {
+ get: metal.getCurrentRunLoop,
+ enumerable: false
+});
Ember.propertyWillChange = metal.propertyWillChange;
Ember.propertyDidChange = metal.propertyDidChange;
Ember.notifyPropertyChange = metal.notifyPropertyChange;
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember/tests/error_handler_test.js
|
@@ -1,5 +1,5 @@
import { isTesting, setTesting } from 'ember-debug';
-import { run, getOnerror, setOnerror } from 'ember-metal';
+import { run, later, getOnerror, setOnerror } from 'ember-metal';
import RSVP from 'rsvp';
let WINDOW_ONERROR;
@@ -118,7 +118,7 @@ QUnit.test('does not swallow exceptions by default (Ember.testing = true, no Emb
return true;
};
- run.later(() => {
+ later(() => {
throw new Error('the error');
}, 10);
@@ -146,7 +146,7 @@ QUnit.test('does not swallow exceptions by default (Ember.testing = false, no Em
return true;
};
- run.later(() => {
+ later(() => {
throw new Error('the error');
}, 10);
@@ -178,7 +178,7 @@ QUnit.test('Ember.onerror can intercept errors (aka swallow) by not rethrowing (
assert.strictEqual(error, thrown, 'Ember.onerror is called with the error');
});
- run.later(() => {
+ later(() => {
throw thrown;
}, 10);
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/ember/tests/reexports_test.js
|
@@ -70,7 +70,21 @@ let allExports =[
['isBlank', 'ember-metal'],
['isPresent', 'ember-metal'],
['_Backburner', 'backburner', 'default'],
- ['run', 'ember-metal'],
+ ['run', 'ember-metal', '_globalsRun'],
+ ['run.backburner', 'ember-metal', 'backburner'],
+ ['run.begin', 'ember-metal', 'begin'],
+ ['run.bind', 'ember-metal', 'bind'],
+ ['run.cancel', 'ember-metal', 'cancel'],
+ ['run.debounce', 'ember-metal', 'debounce'],
+ ['run.end', 'ember-metal', 'end'],
+ ['run.join', 'ember-metal', 'join'],
+ ['run.later', 'ember-metal', 'later'],
+ ['run.next', 'ember-metal', 'next'],
+ ['run.once', 'ember-metal', 'once'],
+ ['run.schedule', 'ember-metal', 'schedule'],
+ ['run.scheduleOnce', 'ember-metal', 'scheduleOnce'],
+ ['run.throttle', 'ember-metal', 'throttle'],
+ ['run.currentRunLoop', 'ember-metal', { get: 'getCurrentRunLoop' }],
['propertyWillChange', 'ember-metal'],
['propertyDidChange', 'ember-metal'],
['notifyPropertyChange', 'ember-metal'],
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/internal-test-helpers/lib/ember-dev/run-loop.js
|
@@ -1,3 +1,10 @@
+import {
+ getCurrentRunLoop,
+ hasScheduledTimers,
+ cancelTimers,
+ end,
+} from 'ember-metal';
+
function RunLoopAssertion(env){
this.env = env;
}
@@ -7,18 +14,17 @@ RunLoopAssertion.prototype = {
inject: function(){},
assert: function(){
let { assert } = QUnit.config.current;
- var run = this.env.Ember.run;
- if (run.currentRunLoop) {
+ if (getCurrentRunLoop()) {
assert.ok(false, "Should not be in a run loop at end of test");
- while (run.currentRunLoop) {
- run.end();
+ while (getCurrentRunLoop()) {
+ end();
}
}
- if (run.hasScheduledTimers()) {
+ if (hasScheduledTimers()) {
assert.ok(false, "Ember run should not have scheduled timers at end of test");
- run.cancelTimers();
+ cancelTimers();
}
},
restore: function(){}
| true |
Other
|
emberjs
|
ember.js
|
3b77850fa877c1872b126f6a0661159f57173b03.json
|
Make run loop functions named exports.
|
packages/internal-test-helpers/lib/test-cases/abstract.js
|
@@ -1,7 +1,7 @@
/* global Element */
import { assign } from 'ember-utils';
-import { run } from 'ember-metal';
+import { run, next, hasScheduledTimers, getCurrentRunLoop } from 'ember-metal';
import NodeQuery from './node-query';
import equalInnerHTML from '../equal-inner-html';
@@ -50,7 +50,7 @@ export default class AbstractTestCase {
runTaskNext() {
return new Promise((resolve) => {
- return run.next(resolve);
+ return next(resolve);
});
}
@@ -134,7 +134,7 @@ export default class AbstractTestCase {
// Every 5ms, poll for the async thing to have finished
let watcher = setInterval(() => {
// If there are scheduled timers or we are inside of a run loop, keep polling
- if (run.hasScheduledTimers() || run.currentRunLoop) { return; }
+ if (hasScheduledTimers() || getCurrentRunLoop()) { return; }
// Stop polling
clearInterval(watcher);
| true |
Other
|
emberjs
|
ember.js
|
a155b309541e7077c31cf0a7e1a4302d4c87fb17.json
|
Remove `Controller#content` alias.
This was deprecated and labeled as `until` 2.17. With 3.2 approaching
beta soon, its time has passed...
|
packages/ember-runtime/lib/mixins/controller.js
|
@@ -40,13 +40,4 @@ export default Mixin.create(ActionHandler, {
@public
*/
model: null,
-
- /**
- @private
- */
- content: deprecatingAlias('model', {
- id: 'ember-runtime.controller.content-alias',
- until: '2.17.0',
- url: 'https://emberjs.com/deprecations/v2.x/#toc_controller-content-alias'
- })
});
| true |
Other
|
emberjs
|
ember.js
|
a155b309541e7077c31cf0a7e1a4302d4c87fb17.json
|
Remove `Controller#content` alias.
This was deprecated and labeled as `until` 2.17. With 3.2 approaching
beta soon, its time has passed...
|
packages/ember-runtime/tests/controllers/controller_test.js
|
@@ -106,17 +106,6 @@ QUnit.module('Controller deprecations');
QUnit.module('Controller Content -> Model Alias');
-QUnit.test('`content` is a deprecated alias of `model`', function(assert) {
- assert.expect(2);
- let controller = Controller.extend({
- model: 'foo-bar'
- }).create();
-
- expectDeprecation(function () {
- assert.equal(controller.get('content'), 'foo-bar', 'content is an alias of model');
- });
-});
-
QUnit.test('`content` is not moved to `model` when `model` is unset', function(assert) {
assert.expect(2);
let controller;
| true |
Other
|
emberjs
|
ember.js
|
3ea74706473b7f4d14fa14b521e979ea8b72d820.json
|
Use explicit `/index` for importing from folder.
|
packages/ember-template-compiler/lib/index.js
|
@@ -17,7 +17,7 @@ export {
registerPlugin,
unregisterPlugin
} from './system/compile-options';
-export { default as defaultPlugins } from './plugins';
+export { default as defaultPlugins } from './plugins/index';
// used for adding Ember.Handlebars.compile for backwards compat
import './compat';
@@ -27,4 +27,4 @@ import './system/bootstrap';
// add domTemplates initializer (only does something if `ember-template-compiler`
// is loaded already)
-import './system/initializer';
\ No newline at end of file
+import './system/initializer';
| true |
Other
|
emberjs
|
ember.js
|
3ea74706473b7f4d14fa14b521e979ea8b72d820.json
|
Use explicit `/index` for importing from folder.
|
packages/ember-template-compiler/lib/system/compile-options.js
|
@@ -1,5 +1,5 @@
import { assign } from 'ember-utils';
-import PLUGINS from '../plugins';
+import PLUGINS from '../plugins/index';
let USER_PLUGINS = [];
| true |
Other
|
emberjs
|
ember.js
|
d4645deaf0f3c7d462895c63a08b0bd20338001d.json
|
Use native class for promise inheritance test.
Prior to this change, when testing untranspiled ES an error is thrown
(cannot call promise constructor without `new`).
|
packages/ember-runtime/tests/mixins/promise_proxy_test.js
|
@@ -214,12 +214,7 @@ QUnit.test('unhandled rejects still propagate to RSVP.on(\'error\', ...) ', func
});
QUnit.test('should work with promise inheritance', function(assert) {
- function PromiseSubclass() {
- RSVP.Promise.apply(this, arguments);
- }
-
- PromiseSubclass.prototype = Object.create(RSVP.Promise.prototype);
- PromiseSubclass.prototype.constructor = PromiseSubclass;
+ class PromiseSubclass extends RSVP.Promise { }
let proxy = ObjectPromiseProxy.create({
promise: new PromiseSubclass(() => { })
| false |
Other
|
emberjs
|
ember.js
|
7d5a9c300b6275b58bb1c8c42af071cf145bcb94.json
|
Enable tests using ES<latest> AMD bundle...
|
tests/index.html
|
@@ -80,10 +80,17 @@
<script>
var dist = QUnit.urlParams.dist;
- if (dist) {
- loadScript('../ember.' + dist + '.js');
- } else {
- loadScript('../ember.debug.js');
+ switch (dist) {
+ case 'prod':
+ case 'min':
+ loadScript('../ember.' + dist + '.js');
+ break;
+ case 'es':
+ loadScript('../ember-all.debug.js');
+ break;
+ default:
+ loadScript('../ember.debug.js');
+ break;
}
</script>
@@ -97,8 +104,11 @@
<script>
var prod = QUnit.urlParams.prod;
+ var dist = QUnit.urlParams.dist;
- if (prod) {
+ if (dist === 'es') {
+ // do nothing, tests are included
+ } else if (prod) {
loadScript('../ember-tests.prod.js');
} else {
loadScript('../ember-tests.js');
@@ -120,7 +130,8 @@
}
}
- Ember.Debug.registerDeprecationHandler(function (message, options, next) {
+ let EmberDebug = Ember.__loader.require('ember-debug');
+ EmberDebug.registerDeprecationHandler(function (message, options, next) {
var id = options && options.id;
next(message, options);
});
| false |
Other
|
emberjs
|
ember.js
|
7b9c1a19535eb334c9caf39bf6a946987c9582fe.json
|
remove redundant existence checks
|
packages/ember-runtime/lib/compare.js
|
@@ -95,14 +95,12 @@ export default function compare(v, w) {
let type1 = typeOf(v);
let type2 = typeOf(w);
- if (Comparable) {
- if (type1 === 'instance' && Comparable.detect(v) && v.constructor.compare) {
- return v.constructor.compare(v, w);
- }
+ if (type1 === 'instance' && Comparable.detect(v) && v.constructor.compare) {
+ return v.constructor.compare(v, w);
+ }
- if (type2 === 'instance' && Comparable.detect(w) && w.constructor.compare) {
- return w.constructor.compare(w, v) * -1;
- }
+ if (type2 === 'instance' && Comparable.detect(w) && w.constructor.compare) {
+ return w.constructor.compare(w, v) * -1;
}
let res = spaceship(TYPE_ORDER[type1], TYPE_ORDER[type2]);
@@ -137,7 +135,7 @@ export default function compare(v, w) {
return spaceship(vLen, wLen);
}
case 'instance':
- if (Comparable && Comparable.detect(v)) {
+ if (Comparable.detect(v)) {
return v.compare(v, w);
}
return 0;
| false |
Other
|
emberjs
|
ember.js
|
6d64f3b48811efe4ed961c63e1afb673621edf22.json
|
Add tests for native Set
|
packages/ember-glimmer/tests/integration/syntax/each-test.js
|
@@ -94,6 +94,36 @@ class ArrayDelegate {
}
}
+const makeSet = (() => {
+ // IE11 does not support `new Set(items);`
+ let set = new Set([1,2,3]);
+
+ if (set.size === 3) {
+ return items => new Set(items);
+ } else {
+ return items => {
+ let s = new Set();
+ items.forEach(value => s.add(value));
+ return s;
+ };
+ }
+})();
+
+class SetDelegate extends ArrayDelegate {
+ constructor(set) {
+ let array = [];
+ set.forEach(value => array.push(value));
+ super(array, set);
+ this._set = set;
+ }
+
+ arrayContentDidChange() {
+ this._set.clear();
+ this._array.forEach(value => this._set.add(value));
+ super.arrayContentDidChange();
+ }
+}
+
class ForEachable extends ArrayDelegate {
get length() {
return this._array.length;
@@ -126,6 +156,7 @@ class BasicEachTest extends TogglingEachTest {}
const TRUTHY_CASES = [
['hello'],
emberA(['hello']),
+ makeSet(['hello']),
new ForEachable(['hello']),
ArrayProxy.create({ content: ['hello'] }),
ArrayProxy.create({ content: emberA(['hello']) })
@@ -139,6 +170,7 @@ const FALSY_CASES = [
0,
[],
emberA([]),
+ makeSet([]),
new ForEachable([]),
ArrayProxy.create({ content: [] }),
ArrayProxy.create({ content: emberA([]) })
@@ -933,6 +965,23 @@ moduleFor('Syntax test: {{#each}} with emberA-wrapped arrays', class extends Eac
});
+moduleFor('Syntax test: {{#each}} with native Set', class extends EachTest {
+
+ createList(items) {
+ let set = makeSet(items);
+ return { list: set, delegate: new SetDelegate(set) };
+ }
+
+ ['@test it can render duplicate primitive items'](assert) {
+ assert.ok(true, 'not supported by Set');
+ }
+
+ ['@test it can render duplicate objects'](assert) {
+ assert.ok(true, 'not supported by Set');
+ }
+
+});
+
moduleFor('Syntax test: {{#each}} with array-like objects implementing forEach', class extends EachTest {
createList(items) {
| false |
Other
|
emberjs
|
ember.js
|
ed27baafef1ce299e624b6c7acb36d1f9d476230.json
|
Remove build time linting.
We have a specific CI build that runs eslint, tsc, and tslint. Doing
this also in the build has turned out to be expensive and needlessly
bloat the final browser builds (which has a direct impact on IE11 test
run times)...
|
broccoli/lint.js
|
@@ -1,9 +0,0 @@
-'use strict';
-
-const ESLint = require('broccoli-lint-eslint');
-
-module.exports = function _lint(tree) {
- return new ESLint(tree, {
- testGenerator: 'qunit'
- });
-};
| true |
Other
|
emberjs
|
ember.js
|
ed27baafef1ce299e624b6c7acb36d1f9d476230.json
|
Remove build time linting.
We have a specific CI build that runs eslint, tsc, and tslint. Doing
this also in the build has turned out to be expensive and needlessly
bloat the final browser builds (which has a direct impact on IE11 test
run times)...
|
ember-cli-build.js
|
@@ -1,6 +1,5 @@
'use strict';
-const UnwatchedDir = require('broccoli-source').UnwatchedDir;
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const babelHelpers = require('./broccoli/babel-helpers');
@@ -10,7 +9,6 @@ const testIndexHTML = require('./broccoli/test-index-html');
const toES5 = require('./broccoli/to-es5');
const stripForProd = toES5.stripForProd;
const minify = require('./broccoli/minify');
-const lint = require('./broccoli/lint');
const { stripIndent } = require('common-tags');
const {
routerES,
@@ -77,12 +75,6 @@ module.exports = function() {
let testHarness = testHarnessFiles();
let backburner = toES5(backburnerES());
- // Linting
- let packages = new UnwatchedDir('packages');
- let linting = lint(new Funnel(packages, {
- include: ['**/*.js']
- }));
-
// ES5
let dependenciesES5 = dependenciesES6().map(toES5);
let emberES5 = emberCoreES6.map(toES5);
@@ -91,19 +83,10 @@ module.exports = function() {
// Bundling
let emberTestsBundle = new MergeTrees([
...emberTestsES5,
- linting,
loader,
nodeModule,
license,
babelDebugHelpersES5,
- lint(emberUtils),
- lint(emberTesting),
- lint(emberDebug),
- lint(emberTemplateCompiler),
- lint(emberMetal),
- lint(emberConsole),
- lint(emberEnvironment),
- lint(container)
]);
let emberDebugBase = [
| true |
Other
|
emberjs
|
ember.js
|
ed27baafef1ce299e624b6c7acb36d1f9d476230.json
|
Remove build time linting.
We have a specific CI build that runs eslint, tsc, and tslint. Doing
this also in the build has turned out to be expensive and needlessly
bloat the final browser builds (which has a direct impact on IE11 test
run times)...
|
package.json
|
@@ -91,7 +91,6 @@
"broccoli-concat": "^3.2.2",
"broccoli-debug": "^0.6.4",
"broccoli-file-creator": "^1.1.1",
- "broccoli-lint-eslint": "^3.2.2",
"broccoli-rollup": "^2.1.0",
"broccoli-source": "^1.1.0",
"broccoli-string-replace": "^0.1.2",
| true |
Other
|
emberjs
|
ember.js
|
ed27baafef1ce299e624b6c7acb36d1f9d476230.json
|
Remove build time linting.
We have a specific CI build that runs eslint, tsc, and tslint. Doing
this also in the build has turned out to be expensive and needlessly
bloat the final browser builds (which has a direct impact on IE11 test
run times)...
|
yarn.lock
|
@@ -261,12 +261,6 @@ anymatch@^1.3.0:
micromatch "^2.1.5"
normalize-path "^2.0.0"
-aot-test-generators@^0.1.0:
- version "0.1.0"
- resolved "https://registry.yarnpkg.com/aot-test-generators/-/aot-test-generators-0.1.0.tgz#43f0f615f97cb298d7919c1b0b4e6b7310b03cd0"
- dependencies:
- jsesc "^2.5.0"
-
aproba@^1.0.3:
version "1.2.0"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
@@ -1359,18 +1353,6 @@ broccoli-kitchen-sink-helpers@^0.3.1:
glob "^5.0.10"
mkdirp "^0.5.1"
-broccoli-lint-eslint@^3.2.2:
- version "3.3.2"
- resolved "https://registry.yarnpkg.com/broccoli-lint-eslint/-/broccoli-lint-eslint-3.3.2.tgz#47e58dc2eb05dadf329a622720e92f22feca1ce6"
- dependencies:
- aot-test-generators "^0.1.0"
- broccoli-concat "^3.2.2"
- broccoli-persistent-filter "^1.4.3"
- eslint "^3.0.0"
- json-stable-stringify "^1.0.1"
- lodash.defaultsdeep "^4.6.0"
- md5-hex "^2.0.0"
-
broccoli-merge-trees@^1.0.0, broccoli-merge-trees@^1.1.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/broccoli-merge-trees/-/broccoli-merge-trees-1.2.4.tgz#a001519bb5067f06589d91afa2942445a2d0fdb5"
@@ -1405,7 +1387,7 @@ broccoli-middleware@^1.0.0:
handlebars "^4.0.4"
mime "^1.2.11"
-broccoli-persistent-filter@^1.1.5, broccoli-persistent-filter@^1.1.6, broccoli-persistent-filter@^1.4.0, broccoli-persistent-filter@^1.4.3:
+broccoli-persistent-filter@^1.1.5, broccoli-persistent-filter@^1.1.6, broccoli-persistent-filter@^1.4.0:
version "1.4.3"
resolved "https://registry.yarnpkg.com/broccoli-persistent-filter/-/broccoli-persistent-filter-1.4.3.tgz#3511bc52fc53740cda51621f58a28152d9911bc1"
dependencies:
@@ -4318,10 +4300,6 @@ jsesc@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b"
-jsesc@^2.5.0:
- version "2.5.1"
- resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.1.tgz#e421a2a8e20d6b0819df28908f782526b96dd1fe"
-
jsesc@~0.3.x:
version "0.3.0"
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.3.0.tgz#1bf5ee63b4539fe2e26d0c1e99c240b97a457972"
| true |
Other
|
emberjs
|
ember.js
|
87980e24a49c46cea29c08b76a90a3bc979f54e6.json
|
avoid iteration when possible in `each_proxy`
|
packages/ember-metal/lib/array.js
|
@@ -12,8 +12,8 @@ export function objectAt(array, index) {
return array[index];
} else {
return array.objectAt(index);
- }
-}
+ }
+}
export function replace(array, start, deleteCount, items = EMPTY_ARRAY) {
if (Array.isArray(array)) {
@@ -104,17 +104,18 @@ export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) {
}
}
+ let meta = peekMeta(array);
+
if (addAmt < 0 || removeAmt < 0 || addAmt - removeAmt !== 0) {
- notifyPropertyChange(array, 'length');
+ notifyPropertyChange(array, 'length', meta);
}
- notifyPropertyChange(array, '[]');
+ notifyPropertyChange(array, '[]', meta);
eachProxyArrayDidChange(array, startIdx, removeAmt, addAmt);
sendEvent(array, '@array:change', [array, startIdx, removeAmt, addAmt]);
- let meta = peekMeta(array);
let cache = peekCacheFor(array);
if (cache !== undefined) {
let length = get(array, 'length');
| true |
Other
|
emberjs
|
ember.js
|
87980e24a49c46cea29c08b76a90a3bc979f54e6.json
|
avoid iteration when possible in `each_proxy`
|
packages/ember-metal/lib/each_proxy.js
|
@@ -44,8 +44,8 @@ class EachProxy {
arrayWillChange(content, idx, removedCnt, addedCnt) { // eslint-disable-line no-unused-vars
let keys = this._keys;
let lim = removedCnt > 0 ? idx + removedCnt : -1;
- for (let key in keys) {
- if (lim > 0) {
+ if (lim > 0) {
+ for (let key in keys) {
removeObserverForContentKey(content, key, this, idx, lim);
}
}
@@ -81,7 +81,7 @@ class EachProxy {
beginObservingContentKey(keyName) {
let keys = this._keys;
- if (!keys) {
+ if (keys === undefined) {
keys = this._keys = Object.create(null);
}
@@ -98,9 +98,9 @@ class EachProxy {
stopObservingContentKey(keyName) {
let keys = this._keys;
- if (keys && (keys[keyName] > 0) && (--keys[keyName] <= 0)) {
+ if (keys !== undefined && (keys[keyName] > 0) && (--keys[keyName] <= 0)) {
let content = this._content;
- let len = get(content, 'length');
+ let len = get(content, 'length');
removeObserverForContentKey(content, keyName, this, 0, len);
}
| true |
Other
|
emberjs
|
ember.js
|
9579cad57ad3c1dea32c8cfac84e968a7bd5f72a.json
|
fix broken imports
|
packages/ember-views/lib/views/states/default.js
|
@@ -1,19 +1,19 @@
-import {
- EmberError
-} from 'ember-debug';
+import { Error as EmberError } from 'ember-debug';
export default {
// appendChild is only legal while rendering the buffer.
appendChild() {
- throw new EmberError('You can\'t use appendChild outside of the rendering process');
+ throw new EmberError(
+ "You can't use appendChild outside of the rendering process"
+ );
},
// Handle events from `Ember.EventDispatcher`
handleEvent() {
return true; // continue event propagation
},
- rerender() { },
+ rerender() {},
- destroy() { }
+ destroy() {}
};
| true |
Other
|
emberjs
|
ember.js
|
9579cad57ad3c1dea32c8cfac84e968a7bd5f72a.json
|
fix broken imports
|
packages/ember/lib/index.js
|
@@ -93,7 +93,7 @@ Ember.overrideChains = metal.overrideChains;
Ember.beginPropertyChanges = metal.beginPropertyChanges;
Ember.endPropertyChanges = metal.endPropertyChanges;
Ember.changeProperties = metal.changeProperties;
-Ember.platform = {
+Ember.platform = {
defineProperty: true,
hasPropertyAccessors: true
};
@@ -126,12 +126,11 @@ Ember.aliasMethod = metal.aliasMethod;
Ember.observer = metal.observer;
Ember.mixin = metal.mixin;
Ember.Mixin = metal.Mixin;
-Ember.bind = metal.bind;
-Ember.Binding = metal.Binding;
-
Object.defineProperty(Ember, 'ENV', {
- get() { return ENV; },
+ get() {
+ return ENV;
+ },
enumerable: false
});
@@ -141,47 +140,62 @@ Object.defineProperty(Ember, 'ENV', {
@private
*/
Object.defineProperty(Ember, 'lookup', {
- get() { return context.lookup; },
- set(value) { context.lookup = value; },
+ get() {
+ return context.lookup;
+ },
+ set(value) {
+ context.lookup = value;
+ },
enumerable: false
});
Ember.EXTEND_PROTOTYPES = ENV.EXTEND_PROTOTYPES;
// BACKWARDS COMPAT ACCESSORS FOR ENV FLAGS
Object.defineProperty(Ember, 'LOG_STACKTRACE_ON_DEPRECATION', {
- get() { return ENV.LOG_STACKTRACE_ON_DEPRECATION; },
- set(value) { ENV.LOG_STACKTRACE_ON_DEPRECATION = !!value; },
+ get() {
+ return ENV.LOG_STACKTRACE_ON_DEPRECATION;
+ },
+ set(value) {
+ ENV.LOG_STACKTRACE_ON_DEPRECATION = !!value;
+ },
enumerable: false
});
Object.defineProperty(Ember, 'LOG_VERSION', {
- get() { return ENV.LOG_VERSION; },
- set(value) { ENV.LOG_VERSION = !!value; },
+ get() {
+ return ENV.LOG_VERSION;
+ },
+ set(value) {
+ ENV.LOG_VERSION = !!value;
+ },
enumerable: false
});
if (DEBUG) {
Object.defineProperty(Ember, 'MODEL_FACTORY_INJECTIONS', {
- get() { return false; },
+ get() {
+ return false;
+ },
set() {
- deprecate(
- 'Ember.MODEL_FACTORY_INJECTIONS is no longer required',
- false,
- {
- id: 'ember-metal.model_factory_injections',
- until: '2.17.0',
- url: 'https://emberjs.com/deprecations/v2.x/#toc_id-ember-metal-model_factory_injections'
- }
- );
+ deprecate('Ember.MODEL_FACTORY_INJECTIONS is no longer required', false, {
+ id: 'ember-metal.model_factory_injections',
+ until: '2.17.0',
+ url:
+ 'https://emberjs.com/deprecations/v2.x/#toc_id-ember-metal-model_factory_injections'
+ });
},
enumerable: false
});
}
Object.defineProperty(Ember, 'LOG_BINDINGS', {
- get() { return ENV.LOG_BINDINGS; },
- set(value) { ENV.LOG_BINDINGS = !!value; },
+ get() {
+ return ENV.LOG_BINDINGS;
+ },
+ set(value) {
+ ENV.LOG_BINDINGS = !!value;
+ },
enumerable: false
});
@@ -287,7 +301,6 @@ import {
deprecatingAlias,
and,
or,
- any,
// reduced computed macros
sum,
@@ -360,7 +373,6 @@ computed.readOnly = readOnly;
computed.deprecatingAlias = deprecatingAlias;
computed.and = and;
computed.or = or;
-computed.any = any;
computed.sum = sum;
computed.min = min;
@@ -443,7 +455,9 @@ Ember.LinkComponent = LinkComponent;
Object.defineProperty(Ember, '_setComponentManager', {
enumerable: false,
- get() { return componentManager; }
+ get() {
+ return componentManager;
+ }
});
if (ENV.EXTEND_PROTOTYPES.String) {
@@ -452,9 +466,10 @@ if (ENV.EXTEND_PROTOTYPES.String) {
};
}
-let EmberHandlebars = Ember.Handlebars = Ember.Handlebars || {};
-let EmberHTMLBars = Ember.HTMLBars = Ember.HTMLBars || {};
-let EmberHandleBarsUtils = EmberHandlebars.Utils = EmberHandlebars.Utils || {};
+let EmberHandlebars = (Ember.Handlebars = Ember.Handlebars || {});
+let EmberHTMLBars = (Ember.HTMLBars = Ember.HTMLBars || {});
+let EmberHandleBarsUtils = (EmberHandlebars.Utils =
+ EmberHandlebars.Utils || {});
EmberHTMLBars.template = EmberHandlebars.template = template;
EmberHandleBarsUtils.escapeExpression = escapeExpression;
@@ -499,8 +514,6 @@ import * as views from 'ember-views';
Ember.$ = views.jQuery;
-Ember.ViewTargetActionSupport = views.ViewTargetActionSupport;
-
Ember.ViewUtils = {
isSimpleClick: views.isSimpleClick,
getViewElement: views.getViewElement,
@@ -545,7 +558,6 @@ import * as extensionSupport from 'ember-extension-support';
Ember.DataAdapter = extensionSupport.DataAdapter;
Ember.ContainerDebugAdapter = extensionSupport.ContainerDebugAdapter;
-
if (has('ember-template-compiler')) {
require('ember-template-compiler');
}
@@ -569,7 +581,6 @@ runLoadHooks('Ember');
*/
export default Ember;
-
/* globals module */
if (IS_NODE) {
module.exports = Ember;
| true |
Other
|
emberjs
|
ember.js
|
97ed5c28a1d4fe4dbeee6cb2de3931f725dfbdd2.json
|
add small doc for `unwatch`
|
packages/ember-metal/lib/observer.js
|
@@ -21,14 +21,14 @@ export function changeEvent(keyName) {
@static
@for @ember/object/observers
@param obj
- @param {String} _path
+ @param {String} path
@param {Object|Function} target
@param {Function|String} [method]
@public
*/
-export function addObserver(obj, _path, target, method) {
- addListener(obj, changeEvent(_path), target, method);
- watch(obj, _path);
+export function addObserver(obj, path, target, method) {
+ addListener(obj, changeEvent(path), target, method);
+ watch(obj, path);
}
/**
| true |
Other
|
emberjs
|
ember.js
|
97ed5c28a1d4fe4dbeee6cb2de3931f725dfbdd2.json
|
add small doc for `unwatch`
|
packages/ember-metal/lib/watching.js
|
@@ -26,13 +26,14 @@ import {
@method watch
@for Ember
@param obj
- @param {String} _keyPath
+ @param {String} keyPath
+ @param {Object} meta
*/
-export function watch(obj, _keyPath, m) {
- if (isPath(_keyPath)) {
- watchPath(obj, _keyPath, m);
+export function watch(obj, keyPath, meta) {
+ if (isPath(keyPath)) {
+ watchPath(obj, keyPath, meta);
} else {
- watchKey(obj, _keyPath, m);
+ watchKey(obj, keyPath, meta);
}
}
@@ -45,10 +46,22 @@ export function watcherCount(obj, key) {
return (meta !== undefined && meta.peekWatching(key)) || 0;
}
-export function unwatch(obj, _keyPath, m) {
- if (isPath(_keyPath)) {
- unwatchPath(obj, _keyPath, m);
+/**
+ Stops watching a property on an object. Usually you will never call this method directly but instead
+ use higher level methods like `removeObserver()`.
+
+ @private
+ @method unwatch
+ @for Ember
+ @param obj
+ @param {String} keyPath
+ @param {Object} meta
+*/
+
+export function unwatch(obj, keyPath, meta) {
+ if (isPath(keyPath)) {
+ unwatchPath(obj, keyPath, meta);
} else {
- unwatchKey(obj, _keyPath, m);
+ unwatchKey(obj, keyPath, meta);
}
}
| true |
Other
|
emberjs
|
ember.js
|
27de208c87685aa3ea4e51ac967d23da15e0181c.json
|
Move array internals to ember-metal
|
packages/ember-extension-support/lib/data_adapter.js
|
@@ -1,12 +1,16 @@
import { getOwner } from 'ember-utils';
-import { get, run, objectAt } from 'ember-metal';
+import {
+ get,
+ run,
+ objectAt,
+ addArrayObserver,
+ removeArrayObserver
+} from 'ember-metal';
import {
String as StringUtils,
Namespace,
Object as EmberObject,
A as emberA,
- addArrayObserver,
- removeArrayObserver
} from 'ember-runtime';
/**
| true |
Other
|
emberjs
|
ember.js
|
27de208c87685aa3ea4e51ac967d23da15e0181c.json
|
Move array internals to ember-metal
|
packages/ember-metal/lib/array.js
|
@@ -1,7 +1,110 @@
+import { notifyPropertyChange } from "./property_events";
+import { eachProxyArrayDidChange, eachProxyArrayWillChange } from "./each_proxy";
+import { peekMeta } from "./meta";
+import { sendEvent, removeListener, addListener } from "./events";
+import { peekCacheFor } from "./computed";
+import { get } from "./property_get";
+
export function objectAt(content, idx) {
if (typeof content.objectAt === 'function') {
return content.objectAt(idx);
} else {
return content[idx];
}
}
+
+function arrayObserversHelper(obj, target, opts, operation, notify) {
+ let willChange = (opts && opts.willChange) || 'arrayWillChange';
+ let didChange = (opts && opts.didChange) || 'arrayDidChange';
+ let hasObservers = get(obj, 'hasArrayObservers');
+
+ operation(obj, '@array:before', target, willChange);
+ operation(obj, '@array:change', target, didChange);
+
+ if (hasObservers === notify) {
+ notifyPropertyChange(obj, 'hasArrayObservers');
+ }
+
+ return obj;
+}
+
+export function addArrayObserver(array, target, opts) {
+ return arrayObserversHelper(array, target, opts, addListener, false);
+}
+
+export function removeArrayObserver(array, target, opts) {
+ return arrayObserversHelper(array, target, opts, removeListener, true);
+}
+
+export function arrayContentWillChange(array, startIdx, removeAmt, addAmt) {
+ // if no args are passed assume everything changes
+ if (startIdx === undefined) {
+ startIdx = 0;
+ removeAmt = addAmt = -1;
+ } else {
+ if (removeAmt === undefined) {
+ removeAmt = -1;
+ }
+
+ if (addAmt === undefined) {
+ addAmt = -1;
+ }
+ }
+
+ eachProxyArrayWillChange(array, startIdx, removeAmt, addAmt);
+
+ sendEvent(array, '@array:before', [array, startIdx, removeAmt, addAmt]);
+
+ return array;
+}
+
+export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) {
+ // if no args are passed assume everything changes
+ if (startIdx === undefined) {
+ startIdx = 0;
+ removeAmt = addAmt = -1;
+ } else {
+ if (removeAmt === undefined) {
+ removeAmt = -1;
+ }
+
+ if (addAmt === undefined) {
+ addAmt = -1;
+ }
+ }
+
+ if (addAmt < 0 || removeAmt < 0 || addAmt - removeAmt !== 0) {
+ notifyPropertyChange(array, 'length');
+ }
+
+ notifyPropertyChange(array, '[]');
+
+ eachProxyArrayDidChange(array, startIdx, removeAmt, addAmt);
+
+ sendEvent(array, '@array:change', [array, startIdx, removeAmt, addAmt]);
+
+ let meta = peekMeta(array);
+ let cache = peekCacheFor(array);
+ if (cache !== undefined) {
+ let length = get(array, 'length');
+ let addedAmount = (addAmt === -1 ? 0 : addAmt);
+ let removedAmount = (removeAmt === -1 ? 0 : removeAmt);
+ let delta = addedAmount - removedAmount;
+ let previousLength = length - delta;
+
+ let normalStartIdx = startIdx < 0 ? previousLength + startIdx : startIdx;
+ if (cache.has('firstObject') && normalStartIdx === 0) {
+ notifyPropertyChange(array, 'firstObject', meta);
+ }
+
+ if (cache.has('lastObject')) {
+ let previousLastIndex = previousLength - 1;
+ let lastAffectedIndex = normalStartIdx + removedAmount;
+ if (previousLastIndex < lastAffectedIndex) {
+ notifyPropertyChange(array, 'lastObject', meta);
+ }
+ }
+ }
+
+ return array;
+}
| true |
Other
|
emberjs
|
ember.js
|
27de208c87685aa3ea4e51ac967d23da15e0181c.json
|
Move array internals to ember-metal
|
packages/ember-metal/lib/index.js
|
@@ -41,7 +41,13 @@ export {
set,
trySet
} from './property_set';
-export { objectAt } from './array';
+export {
+ objectAt,
+ addArrayObserver,
+ removeArrayObserver,
+ arrayContentWillChange,
+ arrayContentDidChange
+} from './array';
export {
eachProxyFor,
eachProxyArrayWillChange,
| true |
Other
|
emberjs
|
ember.js
|
27de208c87685aa3ea4e51ac967d23da15e0181c.json
|
Move array internals to ember-metal
|
packages/ember-runtime/lib/index.js
|
@@ -13,8 +13,6 @@ export { default as isEqual } from './is-equal';
export {
default as Array,
isEmberArray,
- addArrayObserver,
- removeArrayObserver,
NativeArray,
A,
MutableArray,
| true |
Other
|
emberjs
|
ember.js
|
27de208c87685aa3ea4e51ac967d23da15e0181c.json
|
Move array internals to ember-metal
|
packages/ember-runtime/lib/mixins/array.js
|
@@ -12,18 +12,14 @@ import {
isNone,
aliasMethod,
Mixin,
- notifyPropertyChange,
- addListener,
- removeListener,
- sendEvent,
hasListeners,
- peekMeta,
eachProxyFor,
- eachProxyArrayWillChange,
- eachProxyArrayDidChange,
beginPropertyChanges,
endPropertyChanges,
- peekCacheFor
+ addArrayObserver,
+ removeArrayObserver,
+ arrayContentWillChange,
+ arrayContentDidChange
} from 'ember-metal';
import { assert, deprecate } from 'ember-debug';
import Enumerable from './enumerable';
@@ -35,102 +31,6 @@ import copy from '../copy';
import { Error as EmberError } from 'ember-debug';
import MutableEnumerable from './mutable_enumerable';
-function arrayObserversHelper(obj, target, opts, operation, notify) {
- let willChange = (opts && opts.willChange) || 'arrayWillChange';
- let didChange = (opts && opts.didChange) || 'arrayDidChange';
- let hasObservers = get(obj, 'hasArrayObservers');
-
- operation(obj, '@array:before', target, willChange);
- operation(obj, '@array:change', target, didChange);
-
- if (hasObservers === notify) {
- notifyPropertyChange(obj, 'hasArrayObservers');
- }
-
- return obj;
-}
-
-export function addArrayObserver(array, target, opts) {
- return arrayObserversHelper(array, target, opts, addListener, false);
-}
-
-export function removeArrayObserver(array, target, opts) {
- return arrayObserversHelper(array, target, opts, removeListener, true);
-}
-
-export function arrayContentWillChange(array, startIdx, removeAmt, addAmt) {
- // if no args are passed assume everything changes
- if (startIdx === undefined) {
- startIdx = 0;
- removeAmt = addAmt = -1;
- } else {
- if (removeAmt === undefined) {
- removeAmt = -1;
- }
-
- if (addAmt === undefined) {
- addAmt = -1;
- }
- }
-
- eachProxyArrayWillChange(array, startIdx, removeAmt, addAmt);
-
- sendEvent(array, '@array:before', [array, startIdx, removeAmt, addAmt]);
-
- return array;
-}
-
-export function arrayContentDidChange(array, startIdx, removeAmt, addAmt) {
- // if no args are passed assume everything changes
- if (startIdx === undefined) {
- startIdx = 0;
- removeAmt = addAmt = -1;
- } else {
- if (removeAmt === undefined) {
- removeAmt = -1;
- }
-
- if (addAmt === undefined) {
- addAmt = -1;
- }
- }
-
- if (addAmt < 0 || removeAmt < 0 || addAmt - removeAmt !== 0) {
- notifyPropertyChange(array, 'length');
- }
-
- notifyPropertyChange(array, '[]');
-
- eachProxyArrayDidChange(array, startIdx, removeAmt, addAmt);
-
- sendEvent(array, '@array:change', [array, startIdx, removeAmt, addAmt]);
-
- let meta = peekMeta(array);
- let cache = peekCacheFor(array);
- if (cache !== undefined) {
- let length = get(array, 'length');
- let addedAmount = (addAmt === -1 ? 0 : addAmt);
- let removedAmount = (removeAmt === -1 ? 0 : removeAmt);
- let delta = addedAmount - removedAmount;
- let previousLength = length - delta;
-
- let normalStartIdx = startIdx < 0 ? previousLength + startIdx : startIdx;
- if (cache.has('firstObject') && normalStartIdx === 0) {
- notifyPropertyChange(array, 'firstObject', meta);
- }
-
- if (cache.has('lastObject')) {
- let previousLastIndex = previousLength - 1;
- let lastAffectedIndex = normalStartIdx + removedAmount;
- if (previousLastIndex < lastAffectedIndex) {
- notifyPropertyChange(array, 'lastObject', meta);
- }
- }
- }
-
- return array;
-}
-
const EMBER_ARRAY = symbol('EMBER_ARRAY');
export function isEmberArray(obj) {
| true |
Other
|
emberjs
|
ember.js
|
27de208c87685aa3ea4e51ac967d23da15e0181c.json
|
Move array internals to ember-metal
|
packages/ember-runtime/lib/system/array_proxy.js
|
@@ -7,17 +7,15 @@ import {
objectAt,
computed,
alias,
- PROPERTY_DID_CHANGE
+ PROPERTY_DID_CHANGE,
+ addArrayObserver,
+ removeArrayObserver
} from 'ember-metal';
import {
isArray
} from '../utils';
import EmberObject from './object';
import { MutableArray } from '../mixins/array';
-import {
- addArrayObserver,
- removeArrayObserver
-} from '../mixins/array';
import { assert } from 'ember-debug';
const ARRAY_OBSERVER_MAPPING = {
| true |
Other
|
emberjs
|
ember.js
|
27de208c87685aa3ea4e51ac967d23da15e0181c.json
|
Move array internals to ember-metal
|
packages/ember-runtime/tests/helpers/array.js
|
@@ -1,15 +1,18 @@
import ArrayProxy from '../../system/array_proxy';
import EmberArray, {
A as emberA,
- MutableArray,
- arrayContentDidChange,
- arrayContentWillChange,
- addArrayObserver,
- removeArrayObserver,
+ MutableArray
} from '../../mixins/array';
import { generateGuid, guidFor } from 'ember-utils';
-import { get, set } from 'ember-metal';
-import { computed } from 'ember-metal';
+import {
+ get,
+ set,
+ computed,
+ addArrayObserver,
+ removeArrayObserver,
+ arrayContentWillChange,
+ arrayContentDidChange
+} from 'ember-metal';
import EmberObject from '../../system/object';
import Copyable from '../../mixins/copyable';
import { moduleFor } from 'internal-test-helpers';
| true |
Other
|
emberjs
|
ember.js
|
27de208c87685aa3ea4e51ac967d23da15e0181c.json
|
Move array internals to ember-metal
|
packages/ember-runtime/tests/mixins/array_test.js
|
@@ -4,16 +4,15 @@ import {
objectAt,
addObserver,
observer as emberObserver,
- computed
-} from 'ember-metal';
-import { testBoth } from 'internal-test-helpers';
-import EmberObject from '../../system/object';
-import EmberArray, {
+ computed,
addArrayObserver,
removeArrayObserver,
arrayContentDidChange,
arrayContentWillChange
-} from '../../mixins/array';
+} from 'ember-metal';
+import { testBoth } from 'internal-test-helpers';
+import EmberObject from '../../system/object';
+import EmberArray from '../../mixins/array';
import { A as emberA } from '../../mixins/array';
/*
| true |
Other
|
emberjs
|
ember.js
|
4feeed7daeb442b9575603d5f48a32c9f786cd8f.json
|
Upgrade backburner.js to 2.2.2.
Upstream issue causing revert of 2.2.0 and 2.2.1 has been addressed,
this updates to the fixed version 2.2.2.
Once landed, further testing can be done..
|
package.json
|
@@ -86,7 +86,7 @@
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-proto-to-assign": "^6.26.0",
"babel-template": "^6.26.0",
- "backburner.js": "2.1.0",
+ "backburner.js": "^2.2.2",
"broccoli-babel-transpiler": "^6.1.2",
"broccoli-concat": "^3.2.2",
"broccoli-debug": "^0.6.4",
| true |
Other
|
emberjs
|
ember.js
|
4feeed7daeb442b9575603d5f48a32c9f786cd8f.json
|
Upgrade backburner.js to 2.2.2.
Upstream issue causing revert of 2.2.0 and 2.2.1 has been addressed,
this updates to the fixed version 2.2.2.
Once landed, further testing can be done..
|
yarn.lock
|
@@ -988,9 +988,9 @@ backbone@^1.1.2:
dependencies:
underscore ">=1.8.3"
[email protected]:
- version "2.1.0"
- resolved "https://registry.yarnpkg.com/backburner.js/-/backburner.js-2.1.0.tgz#2dd3b0f5043fc495b91407cf9f27d976e86159d5"
+backburner.js@^2.2.2:
+ version "2.2.2"
+ resolved "https://registry.yarnpkg.com/backburner.js/-/backburner.js-2.2.2.tgz#c7215cafdd81004fcb3d950e2d80517ff8196248"
[email protected]:
version "1.0.2"
| true |
Other
|
emberjs
|
ember.js
|
66c39c2f1888c6533f0d807d7f4804ec2bfbcb65.json
|
Add v3.1.0-beta.5 to CHANGELOG
[ci skip]
(cherry picked from commit 8f395f06a2b6140ecfa326945bf657c040a1a6f9)
|
CHANGELOG.md
|
@@ -1,5 +1,13 @@
# Ember Changelog
+### v3.1.0-beta.5 (March 12, 2018)
+- [#15601](https://github.com/emberjs/ember.js/pull/15601) [BUGFIX] Ensure Mixin.prototype.toString does not return constructor code
+- [#16326](https://github.com/emberjs/ember.js/pull/16326) [BUGFIX] Expanded syntax error for if handlebars helper to include source of error
+- [#16347](https://github.com/emberjs/ember.js/pull/16347) [BUGFIX] Adds toJSON to list of descriptorTrap assertion exception
+- [#16350](https://github.com/emberjs/ember.js/pull/16350) [BUGFIX] Fix initialiters tests blueprints
+- [#16351](https://github.com/emberjs/ember.js/pull/16351) [BUGFIX] Bring RSVP.cast back from the dead
+- [#16365](https://github.com/emberjs/ember.js/pull/16365) [BUGFIX] Fold all trap methods together
+
### v3.1.0-beta.4 (March 5, 2018)
- [#16294](https://github.com/emberjs/ember.js/pull/16294) [BUGFIX] Fix input macro params handling
- [#16297](https://github.com/emberjs/ember.js/pull/16297) [BUGFIX] Revert "Update to [email protected]."
| false |
Other
|
emberjs
|
ember.js
|
06c40663a22e1a225d3308fd35487b27bdeef83d.json
|
add weakset polyfill
|
packages/ember-metal/lib/is_proxy.js
|
@@ -1,9 +1,11 @@
-const PROXIES = new WeakMap();
+import WeakSet from './weak_set';
+
+const PROXIES = new WeakSet();
export function isProxy(object) {
return PROXIES.has(object);
}
export function setProxy(object) {
- return PROXIES.set(object, true);
+ return PROXIES.add(object);
}
| true |
Other
|
emberjs
|
ember.js
|
06c40663a22e1a225d3308fd35487b27bdeef83d.json
|
add weakset polyfill
|
packages/ember-metal/lib/weak_set.js
|
@@ -0,0 +1,22 @@
+const HAS_WEAK_SET = typeof WeakSet === 'function';
+
+class WeakSetPolyFill {
+ constructor() {
+ this._weakmap = new WeakMap();
+ }
+
+ add(val) {
+ this._weakmap.set(val, true);
+ return this;
+ }
+
+ delete(val) {
+ return this._weakmap.delete(val);
+ }
+
+ has(val) {
+ return this._weakmap.has(val);
+ }
+}
+
+export default HAS_WEAK_SET ? WeakSet : WeakSetPolyFill; // eslint-disable-line
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
features.json
|
@@ -9,7 +9,8 @@
"ember-engines-mount-params": true,
"ember-module-unification": null,
"glimmer-custom-component-manager": null,
- "ember-template-block-let-helper": null
+ "ember-template-block-let-helper": null,
+ "ember-metal-tracked-properties": null
},
"deprecations": {
"container-lookupFactory": "2.12.0",
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-glimmer/tests/integration/application/engine-test.js
|
@@ -717,8 +717,8 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
let href1337 = this.element.querySelector('.author-1337').href;
// check if link ends with the suffix
- assert.ok(this.stringsEndWith(href1, suffix1));
- assert.ok(this.stringsEndWith(href1337, suffix1337));
+ assert.ok(this.stringsEndWith(href1, suffix1), `${href1} ends with ${suffix1}`);
+ assert.ok(this.stringsEndWith(href1337, suffix1337), `${href1337} ends with ${suffix1337}`);
});
}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/externs.d.ts
|
@@ -0,0 +1,12 @@
+declare module 'ember/features' {
+ export const EMBER_TEMPLATE_BLOCK_LET_HELPER: boolean | null;
+ export const EMBER_MODULE_UNIFICATION: boolean | null;
+ export const GLIMMER_CUSTOM_COMPONENT_MANAGER: boolean | null;
+ export const EMBER_ENGINES_MOUNT_PARAMS: boolean | null;
+ export const EMBER_GLIMMER_DETECT_BACKTRACKING_RERENDER: boolean | null;
+ export const MANDATORY_SETTER: boolean | null;
+}
+
+declare module 'ember-env-flags' {
+ export const DEBUG: boolean;
+}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/lib/computed.js
|
@@ -2,6 +2,7 @@ import { inspect } from 'ember-utils';
import { assert, warn, Error as EmberError } from 'ember-debug';
import { set } from './property_set';
import { meta as metaFor, peekMeta } from './meta';
+import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';
import expandProperties from './expand_properties';
import {
Descriptor,
@@ -14,6 +15,8 @@ import {
addDependentKeys,
removeDependentKeys
} from './dependent_keys';
+import { getCurrentTracker, setCurrentTracker } from './tracked';
+import { tagForProperty, update } from './tags';
/**
@module @ember/object
@@ -150,6 +153,10 @@ class ComputedProperty extends Descriptor {
this._meta = undefined;
this._volatile = false;
+ if (EMBER_METAL_TRACKED_PROPERTIES) {
+ this._auto = false;
+ }
+
this._dependentKeys = opts && opts.dependentKeys;
this._readOnly = opts && hasGetterOnly && opts.readOnly === true;
}
@@ -328,13 +335,48 @@ class ComputedProperty extends Descriptor {
}
let cache = getCacheFor(obj);
+ let propertyTag;
+
+ if (EMBER_METAL_TRACKED_PROPERTIES) {
+ propertyTag = tagForProperty(obj, keyName);
+
+ if (cache.has(keyName)) {
+ // special-case for computed with no dependent keys used to
+ // trigger cacheable behavior.
+ if (!this._auto && (!this._dependentKeys || this._dependentKeys.length === 0)) {
+ return cache.get(keyName);
+ }
+
+ let lastRevision = getLastRevisionFor(obj, keyName);
+ if (propertyTag.validate(lastRevision)) {
+ return cache.get(keyName);
+ }
+ }
+ } else {
+ if (cache.has(keyName)) {
+ return cache.get(keyName);
+ }
+ }
+
+ let parent;
+ let tracker;
- if (cache.has(keyName)) {
- return cache.get(keyName);
+ if (EMBER_METAL_TRACKED_PROPERTIES) {
+ parent = getCurrentTracker();
+ tracker = setCurrentTracker();
}
let ret = this._getter.call(obj, keyName);
+ if (EMBER_METAL_TRACKED_PROPERTIES) {
+ setCurrentTracker(parent);
+ let tag = tracker.combine();
+ if (parent) parent.add(tag);
+
+ update(propertyTag, tag);
+ setLastRevisionFor(obj, keyName, propertyTag.value());
+ }
+
cache.set(keyName, ret);
let meta = metaFor(obj);
@@ -409,6 +451,11 @@ class ComputedProperty extends Descriptor {
notifyPropertyChange(obj, keyName, meta);
+ if (EMBER_METAL_TRACKED_PROPERTIES) {
+ let propertyTag = tagForProperty(obj, keyName);
+ setLastRevisionFor(obj, keyName, propertyTag.value());
+ }
+
return ret;
}
@@ -423,6 +470,14 @@ class ComputedProperty extends Descriptor {
}
}
}
+
+if (EMBER_METAL_TRACKED_PROPERTIES) {
+ ComputedProperty.prototype.auto = function() {
+ this._auto = true;
+ return this;
+ };
+}
+
/**
This helper returns a new property descriptor that wraps the passed
computed property function. You can use this helper to define properties
@@ -524,6 +579,7 @@ export default function computed(...args) {
}
const COMPUTED_PROPERTY_CACHED_VALUES = new WeakMap();
+const COMPUTED_PROPERTY_LAST_REVISION = EMBER_METAL_TRACKED_PROPERTIES ? new WeakMap() : undefined;
/**
Returns the cached value for a property, if one exists.
@@ -544,6 +600,11 @@ export function getCacheFor(obj) {
let cache = COMPUTED_PROPERTY_CACHED_VALUES.get(obj);
if (cache === undefined) {
cache = new Map();
+
+ if (EMBER_METAL_TRACKED_PROPERTIES) {
+ COMPUTED_PROPERTY_LAST_REVISION.set(obj, new Map());
+ }
+
COMPUTED_PROPERTY_CACHED_VALUES.set(obj, cache);
}
return cache;
@@ -556,6 +617,25 @@ export function getCachedValueFor(obj, key) {
}
}
+export let setLastRevisionFor;
+export let getLastRevisionFor;
+
+if (EMBER_METAL_TRACKED_PROPERTIES) {
+ setLastRevisionFor = (obj, key, revision) => {
+ let lastRevision = COMPUTED_PROPERTY_LAST_REVISION.get(obj);
+ lastRevision.set(key, revision);
+ };
+
+ getLastRevisionFor = (obj, key) => {
+ let cache = COMPUTED_PROPERTY_LAST_REVISION.get(obj);
+ if (cache == undefined) {
+ return 0;
+ } else {
+ return cache.get(key);
+ }
+ };
+}
+
export function peekCacheFor(obj) {
return COMPUTED_PROPERTY_CACHED_VALUES.get(obj);
}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/lib/index.js
|
@@ -135,3 +135,4 @@ export {
setProxy
} from './is_proxy';
export { default as descriptor } from './descriptor';
+export { tracked } from './tracked';
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/lib/property_get.js
|
@@ -4,9 +4,11 @@
import { assert, deprecate } from 'ember-debug';
import { HAS_NATIVE_PROXY, symbol } from 'ember-utils';
-import { DESCRIPTOR_TRAP, EMBER_METAL_ES5_GETTERS, MANDATORY_GETTER } from 'ember/features';
+import { DESCRIPTOR_TRAP, EMBER_METAL_ES5_GETTERS, EMBER_METAL_TRACKED_PROPERTIES, MANDATORY_GETTER } from 'ember/features';
import { isPath } from './path_cache';
import { isDescriptor, isDescriptorTrap, DESCRIPTOR, descriptorFor } from './meta';
+import { getCurrentTracker } from './tracked';
+import { tagForProperty } from './tags';
const ALLOWABLE_TYPES = {
object: true,
@@ -86,6 +88,11 @@ export function get(obj, keyName) {
let value;
if (isObjectLike) {
+ if (EMBER_METAL_TRACKED_PROPERTIES) {
+ let tracker = getCurrentTracker();
+ if (tracker) tracker.add(tagForProperty(obj, keyName));
+ }
+
if (EMBER_METAL_ES5_GETTERS) {
descriptor = descriptorFor(obj, keyName);
}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/lib/tags.js
|
@@ -1,4 +1,5 @@
-import { CONSTANT_TAG, DirtyableTag } from '@glimmer/reference';
+import { CONSTANT_TAG, UpdatableTag, DirtyableTag, combine } from '@glimmer/reference';
+import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';
import { meta as metaFor } from './meta';
import { isProxy } from './is_proxy';
import run from './run_loop';
@@ -13,6 +14,8 @@ function makeTag() {
return DirtyableTag.create();
}
+export const TRACKED_GETTERS = EMBER_METAL_TRACKED_PROPERTIES ? new WeakMap() : undefined;
+
export function tagForProperty(object, propertyKey, _meta) {
if (typeof object !== 'object' || object === null) { return CONSTANT_TAG; }
@@ -25,7 +28,12 @@ export function tagForProperty(object, propertyKey, _meta) {
let tag = tags[propertyKey];
if (tag) { return tag; }
- return tags[propertyKey] = makeTag();
+ if (EMBER_METAL_TRACKED_PROPERTIES) {
+ let pair = combine([makeTag(), UpdatableTag.create(CONSTANT_TAG)]);
+ return tags[propertyKey] = pair;
+ } else {
+ return tags[propertyKey] = makeTag();
+ }
}
export function tagFor(object, _meta) {
@@ -37,6 +45,23 @@ export function tagFor(object, _meta) {
}
}
+export let dirty;
+export let update;
+
+if (EMBER_METAL_TRACKED_PROPERTIES) {
+ dirty = (tag) => {
+ tag.inner.first.inner.dirty();
+ };
+
+ update = (outer, inner) => {
+ outer.inner.second.inner.update(inner);
+ };
+} else {
+ dirty = (tag) => {
+ tag.inner.dirty();
+ };
+}
+
export function markObjectAsDirty(obj, propertyKey, meta) {
let objectTag = meta.readableTag();
@@ -52,7 +77,7 @@ export function markObjectAsDirty(obj, propertyKey, meta) {
let propertyTag = tags !== undefined ? tags[propertyKey] : undefined;
if (propertyTag !== undefined) {
- propertyTag.inner.dirty();
+ dirty(propertyTag);
}
if (objectTag !== undefined || propertyTag !== undefined) {
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/lib/tracked.js
|
@@ -0,0 +1,202 @@
+import { combine, CONSTANT_TAG } from '@glimmer/reference';
+import { tagFor, tagForProperty, dirty, update } from './tags';
+/**
+ An object that that tracks @tracked properties that were consumed.
+
+ @private
+ */
+class Tracker {
+ constructor() {
+ this.tags = new Set();
+ this.last = null;
+ }
+ add(tag) {
+ this.tags.add(tag);
+ this.last = tag;
+ }
+ get size() {
+ return this.tags.size;
+ }
+ combine() {
+ if (this.tags.size === 0) {
+ return CONSTANT_TAG;
+ }
+ else if (this.tags.size === 1) {
+ return this.last;
+ }
+ else {
+ let tags = [];
+ this.tags.forEach(tag => tags.push(tag));
+ return combine(tags);
+ }
+ }
+}
+/**
+ @decorator
+ @private
+
+ Marks a property as tracked.
+
+ By default, a component's properties are expected to be static,
+ meaning you are not able to update them and have the template update accordingly.
+ Marking a property as tracked means that when that property changes,
+ a rerender of the component is scheduled so the template is kept up to date.
+
+ There are two usages for the `@tracked` decorator, shown below.
+
+ @example No dependencies
+
+ If you don't pass an argument to `@tracked`, only changes to that property
+ will be tracked:
+
+ ```typescript
+ import Component, { tracked } from '@glimmer/component';
+
+ export default class MyComponent extends Component {
+ @tracked
+ remainingApples = 10
+ }
+ ```
+
+ When something changes the component's `remainingApples` property, the rerender
+ will be scheduled.
+
+ @example Dependents
+
+ In the case that you have a computed property that depends other
+ properties, you want to track both so that when one of the
+ dependents change, a rerender is scheduled.
+
+ In the following example we have two properties,
+ `eatenApples`, and `remainingApples`.
+
+ ```typescript
+ import Component, { tracked } from '@glimmer/component';
+
+ const totalApples = 100;
+
+ export default class MyComponent extends Component {
+ @tracked
+ eatenApples = 0
+
+ @tracked('eatenApples')
+ get remainingApples() {
+ return totalApples - this.eatenApples;
+ }
+
+ increment() {
+ this.eatenApples = this.eatenApples + 1;
+ }
+ }
+ ```
+
+ @param dependencies Optional dependents to be tracked.
+ */
+export function tracked(target, key, descriptor) {
+ if ('value' in descriptor) {
+ return descriptorForDataProperty(key, descriptor);
+ }
+ else {
+ return descriptorForAccessor(key, descriptor);
+ }
+}
+/**
+ @private
+
+ Whenever a tracked computed property is entered, the current tracker is
+ saved off and a new tracker is replaced.
+
+ Any tracked properties consumed are added to the current tracker.
+
+ When a tracked computed property is exited, the tracker's tags are
+ combined and added to the parent tracker.
+
+ The consequence is that each tracked computed property has a tag
+ that corresponds to the tracked properties consumed inside of
+ itself, including child tracked computed properties.
+ */
+let CURRENT_TRACKER = null;
+export function getCurrentTracker() {
+ return CURRENT_TRACKER;
+}
+export function setCurrentTracker(tracker = new Tracker()) {
+ return CURRENT_TRACKER = tracker;
+}
+function descriptorForAccessor(key, descriptor) {
+ let get = descriptor.get;
+ let set = descriptor.set;
+ function getter() {
+ // Swap the parent tracker for a new tracker
+ let old = CURRENT_TRACKER;
+ let tracker = CURRENT_TRACKER = new Tracker();
+ // Call the getter
+ let ret = get.call(this);
+ // Swap back the parent tracker
+ CURRENT_TRACKER = old;
+ // Combine the tags in the new tracker and add them to the parent tracker
+ let tag = tracker.combine();
+ if (CURRENT_TRACKER)
+ CURRENT_TRACKER.add(tag);
+ // Update the UpdatableTag for this property with the tag for all of the
+ // consumed dependencies.
+ update(tagForProperty(this, key), tag);
+ return ret;
+ }
+ function setter() {
+ // Mark the UpdatableTag for this property with the current tag.
+ dirty(tagForProperty(this, key));
+ set.apply(this, arguments);
+ }
+ return {
+ enumerable: true,
+ configurable: false,
+ get: get && getter,
+ set: set && setter
+ };
+}
+/**
+ @private
+
+ A getter/setter for change tracking for a particular key. The accessor
+ acts just like a normal property, but it triggers the `propertyDidChange`
+ hook when written to.
+
+ Values are saved on the object using a "shadow key," or a symbol based on the
+ tracked property name. Sets write the value to the shadow key, and gets read
+ from it.
+ */
+function descriptorForDataProperty(key, descriptor) {
+ let shadowKey = Symbol(key);
+ return {
+ enumerable: true,
+ configurable: true,
+ get() {
+ if (CURRENT_TRACKER)
+ CURRENT_TRACKER.add(tagForProperty(this, key));
+ if (!(shadowKey in this)) {
+ this[shadowKey] = descriptor.value;
+ }
+ return this[shadowKey];
+ },
+ set(newValue) {
+ tagFor(this).inner.dirty();
+ dirty(tagForProperty(this, key));
+ this[shadowKey] = newValue;
+ propertyDidChange();
+ }
+ };
+}
+let propertyDidChange = function () { };
+export function setPropertyDidChange(cb) {
+ propertyDidChange = cb;
+}
+export class UntrackedPropertyError extends Error {
+ constructor(target, key, message) {
+ super(message);
+ this.target = target;
+ this.key = key;
+ }
+ static for(obj, key) {
+ return new UntrackedPropertyError(obj, key, `The property '${key}' on ${obj} was changed after being rendered. If you want to change a property used in a template after the component has rendered, mark the property as a tracked property with the @tracked decorator.`);
+ }
+}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/lib/tracked.ts
|
@@ -0,0 +1,246 @@
+import { combine, CONSTANT_TAG, CURRENT_TAG, DirtyableTag, Tag, TagWrapper, UpdatableTag } from '@glimmer/reference';
+
+import {
+ MANDATORY_SETTER
+} from 'ember/features';
+import { meta as metaFor } from './meta';
+import { dirty, markObjectAsDirty, tagFor, tagForProperty, TRACKED_GETTERS, update } from './tags';
+
+type Option<T> = T | null;
+type unknown = null | undefined | void | {};
+
+interface Dict<T> {
+ [key: string]: T;
+}
+
+/**
+ An object that that tracks @tracked properties that were consumed.
+
+ @private
+ */
+class Tracker {
+ private tags = new Set<Tag>();
+ private last: Option<Tag> = null;
+
+ add(tag: Tag) {
+ this.tags.add(tag);
+ this.last = tag;
+ }
+
+ get size() {
+ return this.tags.size;
+ }
+
+ combine(): Tag {
+ if (this.tags.size === 0) {
+ return CONSTANT_TAG;
+ } else if (this.tags.size === 1) {
+ return this.last;
+ } else {
+ let tags: Tag[] = [];
+ this.tags.forEach(tag => tags.push(tag));
+ return combine(tags);
+ }
+ }
+}
+
+/**
+ @decorator
+ @private
+
+ Marks a property as tracked.
+
+ By default, a component's properties are expected to be static,
+ meaning you are not able to update them and have the template update accordingly.
+ Marking a property as tracked means that when that property changes,
+ a rerender of the component is scheduled so the template is kept up to date.
+
+ There are two usages for the `@tracked` decorator, shown below.
+
+ @example No dependencies
+
+ If you don't pass an argument to `@tracked`, only changes to that property
+ will be tracked:
+
+ ```typescript
+ import Component, { tracked } from '@glimmer/component';
+
+ export default class MyComponent extends Component {
+ @tracked
+ remainingApples = 10
+ }
+ ```
+
+ When something changes the component's `remainingApples` property, the rerender
+ will be scheduled.
+
+ @example Dependents
+
+ In the case that you have a computed property that depends other
+ properties, you want to track both so that when one of the
+ dependents change, a rerender is scheduled.
+
+ In the following example we have two properties,
+ `eatenApples`, and `remainingApples`.
+
+ ```typescript
+ import Component, { tracked } from '@glimmer/component';
+
+ const totalApples = 100;
+
+ export default class MyComponent extends Component {
+ @tracked
+ eatenApples = 0
+
+ @tracked('eatenApples')
+ get remainingApples() {
+ return totalApples - this.eatenApples;
+ }
+
+ increment() {
+ this.eatenApples = this.eatenApples + 1;
+ }
+ }
+ ```
+
+ @param dependencies Optional dependents to be tracked.
+ */
+export function tracked(target: object, key: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor {
+ if ('value' in descriptor) {
+ return descriptorForDataProperty(key, descriptor);
+ } else {
+ return descriptorForAccessor(key, descriptor);
+ }
+}
+
+/**
+ @private
+
+ Whenever a tracked computed property is entered, the current tracker is
+ saved off and a new tracker is replaced.
+
+ Any tracked properties consumed are added to the current tracker.
+
+ When a tracked computed property is exited, the tracker's tags are
+ combined and added to the parent tracker.
+
+ The consequence is that each tracked computed property has a tag
+ that corresponds to the tracked properties consumed inside of
+ itself, including child tracked computed properties.
+ */
+let CURRENT_TRACKER: Option<Tracker> = null;
+
+export function getCurrentTracker(): Option<Tracker> {
+ return CURRENT_TRACKER;
+}
+
+export function setCurrentTracker(tracker: Tracker = new Tracker()): Tracker {
+ return CURRENT_TRACKER = tracker;
+}
+
+function descriptorForAccessor(key: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor {
+ let get = descriptor.get as Function;
+ let set = descriptor.set as Function;
+
+ function getter(this: any) {
+ // Swap the parent tracker for a new tracker
+ let old = CURRENT_TRACKER;
+ let tracker = CURRENT_TRACKER = new Tracker();
+
+ // Call the getter
+ let ret = get.call(this);
+
+ // Swap back the parent tracker
+ CURRENT_TRACKER = old;
+
+ // Combine the tags in the new tracker and add them to the parent tracker
+ let tag = tracker.combine();
+ if (CURRENT_TRACKER) CURRENT_TRACKER.add(tag);
+
+ // Update the UpdatableTag for this property with the tag for all of the
+ // consumed dependencies.
+ update(tagForProperty(this, key), tag);
+
+ return ret;
+ }
+
+ function setter(this: unknown) {
+ dirty(tagForProperty(this, key));
+ set.apply(this, arguments);
+ }
+
+ return {
+ enumerable: true,
+ configurable: false,
+ get: get && getter,
+ set: set && setter
+ };
+}
+
+export type Key = string;
+
+/**
+ @private
+
+ A getter/setter for change tracking for a particular key. The accessor
+ acts just like a normal property, but it triggers the `propertyDidChange`
+ hook when written to.
+
+ Values are saved on the object using a "shadow key," or a symbol based on the
+ tracked property name. Sets write the value to the shadow key, and gets read
+ from it.
+ */
+
+function descriptorForDataProperty(key, descriptor) {
+ let shadowKey = Symbol(key);
+
+ return {
+ enumerable: true,
+ configurable: true,
+
+ get() {
+ if (CURRENT_TRACKER) CURRENT_TRACKER.add(tagForProperty(this, key));
+
+ if (!(shadowKey in this)) {
+ this[shadowKey] = descriptor.value;
+ }
+
+ return this[shadowKey];
+ },
+
+ set(newValue) {
+ tagFor(this).inner.dirty();
+ dirty(tagForProperty(this, key));
+ this[shadowKey] = newValue;
+ propertyDidChange();
+ }
+ };
+}
+
+export interface Interceptors {
+ [key: string]: boolean;
+}
+
+let propertyDidChange = function() {};
+
+export function setPropertyDidChange(cb: () => void) {
+ propertyDidChange = cb;
+}
+
+export class UntrackedPropertyError extends Error {
+ static for(obj: any, key: string): UntrackedPropertyError {
+ return new UntrackedPropertyError(obj, key, `The property '${key}' on ${obj} was changed after being rendered. If you want to change a property used in a template after the component has rendered, mark the property as a tracked property with the @tracked decorator.`);
+ }
+
+ constructor(public target: any, public key: string, message: string) {
+ super(message);
+ }
+}
+
+/**
+ * Function that can be used in development mode to generate more meaningful
+ * error messages.
+ */
+export interface UntrackedPropertyErrorThrower {
+ (obj: any, key: string): void;
+}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/tests/tracked/computed_test.js
|
@@ -0,0 +1,68 @@
+import { createWithDescriptors } from './support';
+import { get, set, tracked } from '../..';
+
+import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';
+
+if (EMBER_METAL_TRACKED_PROPERTIES) {
+
+ QUnit.module('tracked getters');
+
+ QUnit.test('works without get', assert => {
+ let count = 0;
+
+ class Count {
+ get foo() {
+ count++;
+ return `computed foo`;
+ }
+ }
+
+ tracked(Count.prototype, 'foo', Object.getOwnPropertyDescriptor(Count.prototype, 'foo'));
+
+ let obj = new Count();
+
+ assert.equal(obj.foo, 'computed foo', 'should return value');
+ assert.equal(count, 1, 'should have invoked computed property');
+ });
+
+
+ QUnit.test('defining computed property should invoke property on get', function(assert) {
+ let count = 0;
+
+ class Count {
+ get foo() {
+ count++;
+ return `computed foo`;
+ }
+ }
+
+ tracked(Count.prototype, 'foo', Object.getOwnPropertyDescriptor(Count.prototype, 'foo'));
+
+ let obj = new Count();
+
+ assert.equal(get(obj, 'foo'), 'computed foo', 'should return value');
+ assert.equal(count, 1, 'should have invoked computed property');
+ });
+
+
+ QUnit.test('defining computed property should invoke property on set', function(assert) {
+ let count = 0;
+
+ let obj = createWithDescriptors({
+ get foo() {
+ return this.__foo;
+ },
+
+ set foo(value) {
+ count++;
+ this.__foo = `computed ${value}`;
+ }
+ });
+
+
+ assert.equal(set(obj, 'foo', 'bar'), 'bar', 'should return set value');
+ assert.equal(count, 1, 'should have invoked computed property');
+ assert.equal(get(obj, 'foo'), 'computed bar', 'should return new value');
+ });
+
+}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/tests/tracked/get_test.js
|
@@ -0,0 +1,78 @@
+import {
+ get,
+ getWithDefault,
+ tracked
+} from '../..';
+
+import { createTracked } from './support';
+
+import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
+
+import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';
+
+if (EMBER_METAL_TRACKED_PROPERTIES) {
+
+ moduleFor('tracked get', class extends AbstractTestCase {
+ ['@test should get arbitrary properties on an object'](assert) {
+ let obj = createTracked({
+ string: 'string',
+ number: 23,
+ boolTrue: true,
+ boolFalse: false,
+ nullValue: null
+ });
+
+ for (let key in obj) {
+ assert.equal(get(obj, key), obj[key], key);
+ }
+ }
+
+ ['@test should retrieve a number key on an object'](assert) {
+ let obj = createTracked({ 1: 'first' });
+
+ assert.equal(get(obj, 1), 'first');
+ }
+
+ ['@test should not access a property more than once'](assert) {
+ let count = 20;
+
+ class Count {
+ get id() {
+ return ++count;
+ }
+ }
+
+ tracked(Count.prototype, 'id', Object.getOwnPropertyDescriptor(Count.prototype, 'id'));
+
+ let obj = new Count();
+
+ get(obj, 'id');
+
+ assert.equal(count, 21);
+ }
+ });
+
+ moduleFor('tracked getWithDefault', class extends AbstractTestCase {
+ ['@test should get arbitrary properties on an object'](assert) {
+ let obj = createTracked({
+ string: 'string',
+ number: 23,
+ boolTrue: true,
+ boolFalse: false,
+ nullValue: null
+ });
+
+ for (let key in obj) {
+ assert.equal(getWithDefault(obj, key, 'fail'), obj[key], key);
+ }
+
+ obj = createTracked({
+ undef: undefined
+ });
+
+ assert.equal(getWithDefault(obj, 'undef', 'default'), 'default', 'explicit undefined retrieves the default');
+ assert.equal(getWithDefault(obj, 'not-present', 'default'), 'default', 'non-present key retrieves the default');
+ }
+ });
+
+}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/tests/tracked/set_test.js
|
@@ -0,0 +1,47 @@
+import {
+ get,
+ set,
+ setHasViews
+} from '../..';
+import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
+
+import { createTracked } from './support';
+
+import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';
+
+if (EMBER_METAL_TRACKED_PROPERTIES) {
+
+ moduleFor('tracked set', class extends AbstractTestCase {
+ teardown() {
+ setHasViews(() => false);
+ }
+
+ ['@test should set arbitrary properties on an object'](assert) {
+ let obj = createTracked({
+ string: 'string',
+ number: 23,
+ boolTrue: true,
+ boolFalse: false,
+ nullValue: null,
+ undefinedValue: undefined
+ });
+
+ let newObj = createTracked({
+ undefinedValue: 'emberjs'
+ });
+
+ for (let key in obj) {
+ assert.equal(set(newObj, key, obj[key]), obj[key], 'should return value');
+ assert.equal(get(newObj, key), obj[key], 'should set value');
+ }
+ }
+
+ ['@test should set a number key on an object'](assert) {
+ let obj = createTracked({ 1: 'original' });
+
+ set(obj, 1, 'first');
+ assert.equal(obj[1], 'first');
+ }
+ });
+
+}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/tests/tracked/support.js
|
@@ -0,0 +1,30 @@
+import {
+ tracked
+} from '../..';
+
+export function createTracked(values, proto = {}) {
+ function Class() {
+ for (let prop in values) {
+ this[prop] = values[prop];
+ }
+ }
+
+ for (let prop in values) {
+ Object.defineProperty(proto, prop, tracked(proto, prop, { enumerable: true, configurable: true, writable: true, value: values[prop] }));
+ }
+
+ Class.prototype = proto;
+
+ return new Class();
+}
+
+export function createWithDescriptors(values) {
+ function Class() {}
+
+ for (let prop in values) {
+ let descriptor = Object.getOwnPropertyDescriptor(values, prop);
+ Object.defineProperty(Class.prototype, prop, tracked(Class.prototype, prop, descriptor));
+ }
+
+ return new Class();
+}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-metal/tests/tracked/validation_test.js
|
@@ -0,0 +1,214 @@
+import {
+ computed,
+ defineProperty,
+ get,
+ set,
+ tracked
+} from '../..';
+
+import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
+import { tagForProperty } from '../..';
+
+import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';
+
+if (EMBER_METAL_TRACKED_PROPERTIES) {
+
+ moduleFor('tracked get validation', class extends AbstractTestCase {
+ [`@test validators for tracked getters with dependencies should invalidate when the dependencies invalidate`](assert) {
+ class Tracked {
+ constructor(first, last) {
+ this.first = first;
+ this.last = last;
+ }
+ }
+
+ track(Tracked, ['first', 'last'], {
+ get full() {
+ return `${this.first} ${this.last}`;
+ }
+ });
+
+ let obj = new Tracked('Tom', 'Dale');
+
+ let tag = tagForProperty(obj, 'full');
+ let snapshot = tag.value();
+
+ let full = obj.full;
+ assert.equal(full, 'Tom Dale', 'The full name starts correct');
+ assert.equal(tag.validate(snapshot), true);
+
+ snapshot = tag.value();
+ assert.equal(tag.validate(snapshot), true);
+
+ obj.first = 'Thomas';
+ assert.equal(tag.validate(snapshot), false);
+
+ assert.equal(obj.full, 'Thomas Dale');
+ snapshot = tag.value();
+
+ assert.equal(tag.validate(snapshot), true);
+ }
+
+ [`@test interaction with Ember object model (tracked property depending on Ember property)`](assert) {
+ class Tracked {
+ constructor(name) {
+ this.name = name;
+ }
+ }
+
+ track(Tracked, ['name'], {
+ get full() {
+ return `${get(this.name, 'first')} ${get(this.name, 'last')}`;
+ }
+ });
+
+ let tom = { first: 'Tom', last: 'Dale' };
+
+ let obj = new Tracked(tom);
+
+ let tag = tagForProperty(obj, 'full');
+ let snapshot = tag.value();
+
+ let full = obj.full;
+ assert.equal(full, 'Tom Dale');
+ assert.equal(tag.validate(snapshot), true);
+
+ snapshot = tag.value();
+ assert.equal(tag.validate(snapshot), true);
+
+ set(tom, 'first', 'Thomas');
+ assert.equal(tag.validate(snapshot), false, 'invalid after setting with Ember set');
+
+ assert.equal(obj.full, 'Thomas Dale');
+ snapshot = tag.value();
+
+ assert.equal(tag.validate(snapshot), true);
+ }
+
+ [`@test interaction with Ember object model (Ember computed property depending on tracked property)`](assert) {
+ class EmberObject {
+ constructor(name) {
+ this.name = name;
+ }
+ }
+
+ defineProperty(EmberObject.prototype, 'full', computed('name', function() {
+ let name = get(this, 'name');
+ return `${name.first} ${name.last}`;
+ }));
+
+ class Name {
+ constructor(first, last) {
+ this.first = first;
+ this.last = last;
+ }
+ }
+
+ track(Name, ['first', 'last']);
+
+ let tom = new Name('Tom', 'Dale');
+ let obj = new EmberObject(tom);
+
+ let tag = tagForProperty(obj, 'full');
+ let snapshot = tag.value();
+
+ let full = get(obj, 'full');
+ assert.equal(full, 'Tom Dale');
+ assert.equal(tag.validate(snapshot), true);
+
+ snapshot = tag.value();
+ assert.equal(tag.validate(snapshot), true);
+
+ tom.first = 'Thomas';
+ assert.equal(tag.validate(snapshot), false, 'invalid after setting with tracked properties');
+
+ assert.equal(get(obj, 'full'), 'Thomas Dale');
+ snapshot = tag.value();
+
+ // assert.equal(tag.validate(snapshot), true);
+ }
+
+ ['@test interaction with the Ember object model (paths going through tracked properties)'](assert) {
+ class EmberObject {
+ constructor(contact) {
+ this.contact = contact;
+ }
+ }
+
+ defineProperty(EmberObject.prototype, 'full', computed('contact.name.first', 'contact.name.last', function() {
+ let contact = get(this, 'contact');
+ return `${get(contact.name, 'first')} ${get(contact.name, 'last')}`;
+ }));
+
+ class Contact {
+ constructor(name) {
+ this.name = name;
+ }
+ }
+
+ track(Contact, ['name']);
+
+ class EmberName {
+ constructor(first, last) {
+ this.first = first;
+ this.last = last;
+ }
+ }
+
+ let tom = new EmberName('Tom', 'Dale');
+ let contact = new Contact(tom);
+ let obj = new EmberObject(contact);
+
+ let tag = tagForProperty(obj, 'full');
+ let snapshot = tag.value();
+
+ let full = get(obj, 'full');
+ assert.equal(full, 'Tom Dale');
+ assert.equal(tag.validate(snapshot), true);
+
+ snapshot = tag.value();
+ assert.equal(tag.validate(snapshot), true);
+
+ set(tom, 'first', 'Thomas');
+ assert.equal(tag.validate(snapshot), false, 'invalid after setting with Ember.set');
+
+ assert.equal(get(obj, 'full'), 'Thomas Dale');
+ snapshot = tag.value();
+
+ tom = contact.name = new EmberName('T', 'Dale');
+ assert.equal(tag.validate(snapshot), false, 'invalid after setting with Ember.set');
+
+ assert.equal(get(obj, 'full'), 'T Dale');
+ snapshot = tag.value();
+
+ set(tom, 'first', 'Tizzle');
+ assert.equal(tag.validate(snapshot), false, 'invalid after setting with Ember.set');
+
+ assert.equal(get(obj, 'full'), 'Tizzle Dale');
+ }
+ });
+
+}
+
+function track(Class, properties, accessors = {}) {
+ let proto = Class.prototype;
+
+ properties.forEach(prop => defineData(proto, prop));
+
+ let keys = Object.getOwnPropertyNames(accessors);
+
+ keys.forEach(key => defineAccessor(proto, key, Object.getOwnPropertyDescriptor(accessors, key)));
+}
+
+function defineData(prototype, property) {
+ Object.defineProperty(prototype, property, tracked(prototype, property, {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: undefined
+ }));
+}
+
+function defineAccessor(prototype, property, descriptor) {
+ Object.defineProperty(prototype, property, tracked(prototype, property, descriptor));
+}
| true |
Other
|
emberjs
|
ember.js
|
b2fc87ee1184c9aa8a9960758ae6a023e65ae91d.json
|
Add tracked properties behind a feature flag
|
packages/ember-runtime/tests/computed/reduce_computed_macros_test.js
|
@@ -29,6 +29,7 @@ import {
} from '../../computed/reduce_computed_macros';
import { isArray } from '../../utils';
import { A as emberA, removeAt } from '../../mixins/array';
+import { EMBER_METAL_TRACKED_PROPERTIES } from 'ember/features';
let obj;
QUnit.module('map', {
@@ -1299,19 +1300,25 @@ QUnit.test('changing item properties specified via @each triggers a resort of th
assert.deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Tyrion', 'Bran', 'Robb'], 'updating a specified property on an item resorts it');
});
-QUnit.test('changing item properties not specified via @each does not trigger a resort', function(assert) {
- let items = obj.get('items');
- let cersei = items[1];
+if (!EMBER_METAL_TRACKED_PROPERTIES) {
+ QUnit.test('changing item properties not specified via @each does not trigger a resort', function(assert) {
+ let items = obj.get('items');
+ let cersei = items[1];
- assert.deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
+ assert.deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
- set(cersei, 'lname', 'Stark'); // plot twist! (possibly not canon)
+ set(cersei, 'lname', 'Stark'); // plot twist! (possibly not canon)
- // The array has become unsorted. If your sort function is sensitive to
- // properties, they *must* be specified as dependent item property keys or
- // we'll be doing binary searches on unsorted arrays.
- assert.deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'updating an unspecified property on an item does not resort it');
-});
+ // The array has become unsorted. If your sort function is sensitive to
+ // properties, they *must* be specified as dependent item property keys or
+ // we'll be doing binary searches on unsorted arrays.
+ assert.deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'updating an unspecified property on an item does not resort it');
+ });
+} else {
+ QUnit.todo('changing item properties not specified via @each does not trigger a resort', assert => {
+ assert.ok(false, 'It is unclear whether changing this behavior should be considered a breaking change, and whether it catches more bugs than it causes');
+ });
+}
QUnit.module('sort - stability', {
beforeEach() {
| true |
Other
|
emberjs
|
ember.js
|
80c11595d506cf1dafae565f7889137085aead9c.json
|
reuse mixin array build logic
|
packages/ember-metal/lib/mixin.js
|
@@ -429,25 +429,7 @@ export function mixin(obj, ...args) {
export default class Mixin {
constructor(mixins, properties) {
this.properties = properties;
-
- let length = mixins && mixins.length;
-
- if (length > 0) {
- let m = new Array(length);
-
- for (let i = 0; i < length; i++) {
- let x = mixins[i];
- if (x instanceof Mixin) {
- m[i] = x;
- } else {
- m[i] = new Mixin(undefined, x);
- }
- }
-
- this.mixins = m;
- } else {
- this.mixins = undefined;
- }
+ this.mixins = buildMixinsArray(mixins);
this.ownerConstructor = undefined;
this._without = undefined;
this[NAME_KEY] = null;
@@ -507,35 +489,18 @@ export default class Mixin {
@param arguments*
@private
*/
- reopen() {
- let currentMixin;
+ reopen(...args) {
+ if (args.length === 0) { return; }
if (this.properties) {
- currentMixin = new Mixin(undefined, this.properties);
+ let currentMixin = new Mixin(undefined, this.properties);
this.properties = undefined;
this.mixins = [currentMixin];
} else if (!this.mixins) {
this.mixins = [];
}
- let mixins = this.mixins;
- let idx;
-
- for (idx = 0; idx < arguments.length; idx++) {
- currentMixin = arguments[idx];
- assert(
- `Expected hash or Mixin instance, got ${Object.prototype.toString.call(currentMixin)}`,
- typeof currentMixin === 'object' && currentMixin !== null &&
- Object.prototype.toString.call(currentMixin) !== '[object Array]'
- );
-
- if (currentMixin instanceof Mixin) {
- mixins.push(currentMixin);
- } else {
- mixins.push(new Mixin(undefined, currentMixin));
- }
- }
-
+ this.mixins = this.mixins.concat(buildMixinsArray(args));
return this;
}
@@ -583,6 +548,30 @@ export default class Mixin {
}
+function buildMixinsArray(mixins) {
+ let length = mixins && mixins.length;
+ let m;
+
+ if (length > 0) {
+ m = new Array(length);
+ for (let i = 0; i < length; i++) {
+ let x = mixins[i];
+ assert(
+ `Expected hash or Mixin instance, got ${Object.prototype.toString.call(x)}`,
+ typeof x === 'object' && x !== null && Object.prototype.toString.call(x) !== '[object Array]'
+ );
+
+ if (x instanceof Mixin) {
+ m[i] = x;
+ } else {
+ m[i] = new Mixin(undefined, x);
+ }
+ }
+ }
+
+ return m;
+}
+
if (ENV._ENABLE_BINDING_SUPPORT) {
// slotting this so that the legacy addon can add the function here
// without triggering an error due to the Object.seal done below
| false |
Other
|
emberjs
|
ember.js
|
ae867e537eae207b81c4bb2d7c2ada433a63cbc5.json
|
remove leftover `__ember_observesBefore__`
|
packages/ember-utils/lib/super.js
|
@@ -61,7 +61,6 @@ function _wrap(func, superFunc) {
superWrapper.wrappedFunction = func;
superWrapper.__ember_observes__ = func.__ember_observes__;
- superWrapper.__ember_observesBefore__ = func.__ember_observesBefore__;
superWrapper.__ember_listens__ = func.__ember_listens__;
return superWrapper;
| false |
Other
|
emberjs
|
ember.js
|
b7c0efd71a2a7ff7bdad221828572583c7a711e5.json
|
remove empty constructor
|
packages/ember-glimmer/lib/utils/iterable.ts
|
@@ -99,7 +99,7 @@ class ArrayIterator implements Iterator {
let { length } = array;
if (length > 0) {
- return new this(array, array.length, keyFor);
+ return new this(array, length, keyFor);
} else {
return EMPTY_ITERATOR;
}
@@ -149,10 +149,6 @@ class EmberArrayIterator extends ArrayIterator {
}
}
- constructor(array: any[], length: number, keyFor: KeyFor) {
- super(array, length, keyFor);
- }
-
getValue(position: number) {
return objectAt(this.array, position);
}
| false |
Other
|
emberjs
|
ember.js
|
6ce518024c8360a861e742c67f767b7ae74ac5d5.json
|
Fix spelling on LinkComponent documentation
|
packages/ember-glimmer/lib/components/link-to.ts
|
@@ -279,7 +279,7 @@
It is also possible to override the default event in this manner:
```javascript
- import LinkCompoennt from '@ember/routing/link-component';
+ import LinkComponent from '@ember/routing/link-component';
export default LinkComponent.extend({
eventName: 'customEventName'
| false |
Other
|
emberjs
|
ember.js
|
86f1591012d76cdee6929d7ae265910b13ed9edf.json
|
remove string constant from global
|
packages/ember-glimmer/lib/index.ts
|
@@ -305,4 +305,4 @@ export { default as DebugStack } from './utils/debug-stack';
export { default as OutletView } from './views/outlet';
export { default as CustomComponentManager } from './component-managers/custom';
export { COMPONENT_MANAGER, componentManager } from './utils/custom-component-manager';
-export { isSerializationFirstNode, SERIALIZATION_FIRST_NODE_STRING } from './utils/serialization-first-node-helpers';
+export { isSerializationFirstNode } from './utils/serialization-first-node-helpers';
| true |
Other
|
emberjs
|
ember.js
|
86f1591012d76cdee6929d7ae265910b13ed9edf.json
|
remove string constant from global
|
packages/ember-glimmer/lib/utils/serialization-first-node-helpers.ts
|
@@ -1 +1 @@
-export { isSerializationFirstNode, SERIALIZATION_FIRST_NODE_STRING } from '@glimmer/util';
+export { isSerializationFirstNode } from '@glimmer/util';
| true |
Other
|
emberjs
|
ember.js
|
86f1591012d76cdee6929d7ae265910b13ed9edf.json
|
remove string constant from global
|
packages/ember/lib/index.js
|
@@ -430,8 +430,7 @@ import {
template,
TextField,
TextArea,
- isSerializationFirstNode,
- SERIALIZATION_FIRST_NODE_STRING
+ isSerializationFirstNode
} from 'ember-glimmer';
Ember.Component = Component;
@@ -510,8 +509,7 @@ Ember.ViewUtils = {
getViewBoundingClientRect: views.getViewBoundingClientRect,
getRootViews: views.getRootViews,
getChildViews: views.getChildViews,
- isSerializationFirstNode: isSerializationFirstNode,
- SERIALIZATION_FIRST_NODE_STRING: SERIALIZATION_FIRST_NODE_STRING
+ isSerializationFirstNode: isSerializationFirstNode
};
Ember.TextSupport = views.TextSupport;
| true |
Other
|
emberjs
|
ember.js
|
86f1591012d76cdee6929d7ae265910b13ed9edf.json
|
remove string constant from global
|
packages/ember/tests/reexports_test.js
|
@@ -115,7 +115,6 @@ let allExports =[
['ViewUtils.getRootViews', 'ember-views', 'getRootViews'],
['ViewUtils.getChildViews', 'ember-views', 'getChildViews'],
['ViewUtils.isSerializationFirstNode', 'ember-glimmer', 'isSerializationFirstNode'],
- ['ViewUtils.SERIALIZATION_FIRST_NODE_STRING', 'ember-glimmer', 'SERIALIZATION_FIRST_NODE_STRING'],
['TextSupport', 'ember-views'],
['ComponentLookup', 'ember-views'],
['EventDispatcher', 'ember-views'],
| true |
Other
|
emberjs
|
ember.js
|
24070c437bcce9c8e563081b32a28ee549decf4e.json
|
Use isSerializationFirstNode in _renderMode test
|
packages/ember-application/tests/system/visit_test.js
|
@@ -10,7 +10,7 @@ import Application from '../../system/application';
import ApplicationInstance from '../../system/application-instance';
import Engine from '../../system/engine';
import { Route } from 'ember-routing';
-import { Component, helper } from 'ember-glimmer';
+import { Component, helper, isSerializationFirstNode } from 'ember-glimmer';
import { compile } from 'ember-template-compiler';
import { ENV } from 'ember-environment';
@@ -70,9 +70,8 @@ moduleFor('Application - visit()', class extends ApplicationTestCase {
return this.visit('/', bootOptions)
.then((instance) => {
- assert.equal(
- instance.rootElement.firstChild.nodeValue,
- '%+b:0%',
+ assert.ok(
+ isSerializationFirstNode(instance.rootElement.firstChild),
'glimmer-vm comment node was not found'
);
}).then(() =>{
| false |
Other
|
emberjs
|
ember.js
|
777bfd860d2ea30bd65d8070e3cf2c29e022c0a6.json
|
Add v3.1.0-beta.4 to CHANGELOG
[ci skip]
(cherry picked from commit 3be23a21a90a063913920e5c57fb3760eb278fcb)
|
CHANGELOG.md
|
@@ -1,5 +1,11 @@
# Ember Changelog
+### v3.1.0-beta.4 (March 5, 2018)
+- [#16294](https://github.com/emberjs/ember.js/pull/16294) [BUGFIX] Fix input macro params handling
+- [#16297](https://github.com/emberjs/ember.js/pull/16297) [BUGFIX] Revert "Update to [email protected]."
+- [#16299](https://github.com/emberjs/ember.js/pull/16299) [BUGFIX] Revert "[CLEANUP] Remove ':change' suffix on change events"
+- [#16307](https://github.com/emberjs/ember.js/pull/16307) [BUGFIX] Ensure proper .toString() of default components.
+
### v3.1.0-beta.3 (February 26, 2018)
- [#16271](https://github.com/emberjs/ember.js/pull/16271) [BUGFIX] Fix ChainNode unchaining
- [#16274](https://github.com/emberjs/ember.js/pull/16274) [BUGFIX] Ensure accessing a "proxy" itself does not error.
| false |
Other
|
emberjs
|
ember.js
|
401ff152f52b14f24f0df1167ff74c5661f76df6.json
|
Add 2.18.2 to the CHANGELOG.md.
(cherry picked from commit 3ebe27c84ee51578efa070ffa75a5e27cda5c9e6)
|
CHANGELOG.md
|
@@ -86,6 +86,10 @@
- [#16036](https://github.com/emberjs/ember.js/pull/16036) [CLEANUP] Convert ember-metal accessors tests to new style
- [#16023](https://github.com/emberjs/ember.js/pull/16023) Make event dispatcher work without jQuery
+### 2.18.2 (February 14, 2018)
+
+- [#16245](https://github.com/emberjs/ember.js/pull/16245) [BUGFIX] Ensure errors in deferred component hooks can be recovered.
+
### 2.18.1 (February 13, 2018)
- [#16174](https://github.com/emberjs/ember.js/pull/16174) [BUGFIX] Enable _some_ recovery of errors thrown during render.
| false |
Other
|
emberjs
|
ember.js
|
80c5127dc13de3abc9e5c9894d0edddd6737a668.json
|
Remove unnecessary resolverCacheKey
|
packages/container/lib/container.js
|
@@ -130,10 +130,6 @@ export default class Container {
return { [OWNER]: this.owner };
}
- _resolverCacheKey(name) {
- return this.registry.resolverCacheKey(name);
- }
-
/**
Given a fullName, return the corresponding factory. The consumer of the factory
is responsible for the destruction of any factory instances, as there is no
@@ -230,8 +226,7 @@ function lookup(container, fullName, options = {}) {
}
if (options.singleton !== false) {
- let cacheKey = container._resolverCacheKey(normalizedName);
- let cached = container.cache[cacheKey];
+ let cached = container.cache[normalizedName];
if (cached !== undefined) {
return cached;
}
@@ -242,8 +237,7 @@ function lookup(container, fullName, options = {}) {
function factoryFor(container, normalizedName, fullName) {
- let cacheKey = container._resolverCacheKey(normalizedName);
- let cached = container.factoryManagerCache[cacheKey];
+ let cached = container.factoryManagerCache[normalizedName];
if (cached !== undefined) { return cached; }
@@ -263,7 +257,7 @@ function factoryFor(container, normalizedName, fullName) {
manager = wrapManagerInDeprecationProxy(manager);
}
- container.factoryManagerCache[cacheKey] = manager;
+ container.factoryManagerCache[normalizedName] = manager;
return manager;
}
@@ -293,8 +287,7 @@ function instantiateFactory(container, normalizedName, fullName, options) {
// SomeClass { singleton: true, instantiate: true } | { singleton: true } | { instantiate: true } | {}
// By default majority of objects fall into this case
if (isSingletonInstance(container, fullName, options)) {
- let cacheKey = container._resolverCacheKey(normalizedName);
- return container.cache[cacheKey] = factoryManager.create();
+ return container.cache[normalizedName] = factoryManager.create();
}
// SomeClass { singleton: false, instantiate: true }
@@ -364,13 +357,12 @@ function resetCache(container) {
}
function resetMember(container, fullName) {
- let cacheKey = container._resolverCacheKey(fullName);
- let member = container.cache[cacheKey];
+ let member = container.cache[fullName];
- delete container.factoryManagerCache[cacheKey];
+ delete container.factoryManagerCache[fullName];
if (member) {
- delete container.cache[cacheKey];
+ delete container.cache[fullName];
if (member.destroy) {
member.destroy();
| true |
Other
|
emberjs
|
ember.js
|
80c5127dc13de3abc9e5c9894d0edddd6737a668.json
|
Remove unnecessary resolverCacheKey
|
packages/container/lib/registry.js
|
@@ -151,10 +151,9 @@ export default class Registry {
assert(`Attempting to register an unknown factory: '${fullName}'`, factory !== undefined);
let normalizedName = this.normalize(fullName);
- let cacheKey = this.resolverCacheKey(normalizedName);
- assert(`Cannot re-register: '${fullName}', as it has already been resolved.`, !this._resolveCache[cacheKey]);
+ assert(`Cannot re-register: '${fullName}', as it has already been resolved.`, !this._resolveCache[normalizedName]);
- this._failSet.delete(cacheKey);
+ this._failSet.delete(normalizedName);
this.registrations[normalizedName] = factory;
this._options[normalizedName] = options;
}
@@ -180,14 +179,13 @@ export default class Registry {
assert('fullName must be a proper full name', this.isValidFullName(fullName));
let normalizedName = this.normalize(fullName);
- let cacheKey = this.resolverCacheKey(normalizedName);
this._localLookupCache = Object.create(null);
delete this.registrations[normalizedName];
- delete this._resolveCache[cacheKey];
+ delete this._resolveCache[normalizedName];
delete this._options[normalizedName];
- this._failSet.delete(cacheKey);
+ this._failSet.delete(normalizedName);
}
/**
@@ -567,10 +565,6 @@ export default class Registry {
return injections;
}
- resolverCacheKey(name) {
- return name;
- }
-
/**
Given a fullName and a source fullName returns the fully resolved
fullName. Used to allow for local lookup.
@@ -685,10 +679,9 @@ function resolve(registry, normalizedName, options) {
}
}
- let cacheKey = registry.resolverCacheKey(normalizedName);
- let cached = registry._resolveCache[cacheKey];
+ let cached = registry._resolveCache[normalizedName];
if (cached !== undefined) { return cached; }
- if (registry._failSet.has(cacheKey)) { return; }
+ if (registry._failSet.has(normalizedName)) { return; }
let resolved;
@@ -701,9 +694,9 @@ function resolve(registry, normalizedName, options) {
}
if (resolved === undefined) {
- registry._failSet.add(cacheKey);
+ registry._failSet.add(normalizedName);
} else {
- registry._resolveCache[cacheKey] = resolved;
+ registry._resolveCache[normalizedName] = resolved;
}
return resolved;
| true |
Other
|
emberjs
|
ember.js
|
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
|
Introduce source to injections
Ember templates use a `source` argument to the container. This hints
where to look for "local lookup", and also what namespace to look in for
a partial specifier. For example a template in an addon's `src` tree can
invoke components and helpers in that tree becuase it has a `source`
argument passed to lookups.
This introduces the same functionality for service injections. A service
can now accept a `source` argument and its lookup will apply to the
namespace of that file.
Additionally, refactor away from using a `source` argument to the
`resolve` API of resolvers. Instead leveral the `expandLocalLookup` API
to pass the source and get an identifier that can be treated as
canonical for that factory.
|
FEATURES.md
|
@@ -43,9 +43,8 @@ for a detailed explanation.
([RFC](https://github.com/dgeb/rfcs/blob/module-unification/text/0000-module-unification.md))
to Ember. This includes:
- - Passing the `source` of a `lookup`/`factoryFor` call as the second argument
- to an Ember resolver's `resolve` method (as a positional arg we will call
- `referrer`).
+ - Passing the `source` of a `lookup`/`factoryFor` call as an argument to
+ `expandLocalLookup` on the resolver.
- Making `lookupComponentPair` friendly to local/private resolutions. The
new code ensures a local resolution is not paired with a global resolution.
| true |
Other
|
emberjs
|
ember.js
|
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
|
Introduce source to injections
Ember templates use a `source` argument to the container. This hints
where to look for "local lookup", and also what namespace to look in for
a partial specifier. For example a template in an addon's `src` tree can
invoke components and helpers in that tree becuase it has a `source`
argument passed to lookups.
This introduces the same functionality for service injections. A service
can now accept a `source` argument and its lookup will apply to the
namespace of that file.
Additionally, refactor away from using a `source` argument to the
`resolve` API of resolvers. Instead leveral the `expandLocalLookup` API
to pass the source and get an identifier that can be treated as
canonical for that factory.
|
packages/container/lib/container.js
|
@@ -130,8 +130,8 @@ export default class Container {
return { [OWNER]: this.owner };
}
- _resolverCacheKey(name, options) {
- return this.registry.resolverCacheKey(name, options);
+ _resolverCacheKey(name) {
+ return this.registry.resolverCacheKey(name);
}
/**
@@ -168,29 +168,7 @@ export default class Container {
}
}
- let cacheKey = this._resolverCacheKey(normalizedName, options);
- let cached = this.factoryManagerCache[cacheKey];
-
- if (cached !== undefined) { return cached; }
-
- let factory = EMBER_MODULE_UNIFICATION ? this.registry.resolve(normalizedName, options) : this.registry.resolve(normalizedName);
-
- if (factory === undefined) {
- return;
- }
-
- if (DEBUG && factory && typeof factory._onLookup === 'function') {
- factory._onLookup(fullName);
- }
-
- let manager = new FactoryManager(this, factory, fullName, normalizedName);
-
- if (DEBUG) {
- manager = wrapManagerInDeprecationProxy(manager);
- }
-
- this.factoryManagerCache[cacheKey] = manager;
- return manager;
+ return factoryFor(this, normalizedName, fullName);
}
}
/*
@@ -232,6 +210,7 @@ function isInstantiatable(container, fullName) {
}
function lookup(container, fullName, options = {}) {
+ let normalizedName = fullName;
if (options.source) {
let expandedFullName = container.registry.expandLocalLookup(fullName, options);
@@ -241,24 +220,51 @@ function lookup(container, fullName, options = {}) {
return;
}
- fullName = expandedFullName;
+ normalizedName = expandedFullName;
} else if (expandedFullName) {
// with ember-module-unification, if expandLocalLookup returns something,
// pass it to the resolve without the source
- fullName = expandedFullName;
+ normalizedName = expandedFullName;
options = {};
}
}
if (options.singleton !== false) {
- let cacheKey = container._resolverCacheKey(fullName, options);
+ let cacheKey = container._resolverCacheKey(normalizedName);
let cached = container.cache[cacheKey];
if (cached !== undefined) {
return cached;
}
}
- return instantiateFactory(container, fullName, options);
+ return instantiateFactory(container, normalizedName, fullName, options);
+}
+
+
+function factoryFor(container, normalizedName, fullName) {
+ let cacheKey = container._resolverCacheKey(normalizedName);
+ let cached = container.factoryManagerCache[cacheKey];
+
+ if (cached !== undefined) { return cached; }
+
+ let factory = container.registry.resolve(normalizedName);
+
+ if (factory === undefined) {
+ return;
+ }
+
+ if (DEBUG && factory && typeof factory._onLookup === 'function') {
+ factory._onLookup(fullName); // What should this pass? fullname or the normalized key?
+ }
+
+ let manager = new FactoryManager(container, factory, fullName, normalizedName);
+
+ if (DEBUG) {
+ manager = wrapManagerInDeprecationProxy(manager);
+ }
+
+ container.factoryManagerCache[cacheKey] = manager;
+ return manager;
}
function isSingletonClass(container, fullName, { instantiate, singleton }) {
@@ -277,8 +283,8 @@ function isFactoryInstance(container, fullName, { instantiate, singleton }) {
return instantiate !== false && (singleton !== false || isSingleton(container, fullName)) && isInstantiatable(container, fullName);
}
-function instantiateFactory(container, fullName, options) {
- let factoryManager = EMBER_MODULE_UNIFICATION && options && options.source ? container.factoryFor(fullName, options) : container.factoryFor(fullName);
+function instantiateFactory(container, normalizedName, fullName, options) {
+ let factoryManager = factoryFor(container, normalizedName, fullName);
if (factoryManager === undefined) {
return;
@@ -287,7 +293,7 @@ function instantiateFactory(container, fullName, options) {
// SomeClass { singleton: true, instantiate: true } | { singleton: true } | { instantiate: true } | {}
// By default majority of objects fall into this case
if (isSingletonInstance(container, fullName, options)) {
- let cacheKey = container._resolverCacheKey(fullName, options);
+ let cacheKey = container._resolverCacheKey(normalizedName);
return container.cache[cacheKey] = factoryManager.create();
}
@@ -313,12 +319,15 @@ function buildInjections(container, injections) {
container.registry.validateInjections(injections);
}
- let injection;
for (let i = 0; i < injections.length; i++) {
- injection = injections[i];
- hash[injection.property] = lookup(container, injection.fullName);
+ let {property, specifier, source} = injections[i];
+ if (source) {
+ hash[property] = lookup(container, specifier, {source});
+ } else {
+ hash[property] = lookup(container, specifier);
+ }
if (!isDynamic) {
- isDynamic = !isSingleton(container, injection.fullName);
+ isDynamic = !isSingleton(container, specifier);
}
}
}
@@ -355,12 +364,13 @@ function resetCache(container) {
}
function resetMember(container, fullName) {
- let member = container.cache[fullName];
+ let cacheKey = container._resolverCacheKey(fullName);
+ let member = container.cache[cacheKey];
- delete container.factoryManagerCache[fullName];
+ delete container.factoryManagerCache[cacheKey];
if (member) {
- delete container.cache[fullName];
+ delete container.cache[cacheKey];
if (member.destroy) {
member.destroy();
| true |
Other
|
emberjs
|
ember.js
|
cfaa47e48b0d6badb5e84419f117a46fd2f2ae8e.json
|
Introduce source to injections
Ember templates use a `source` argument to the container. This hints
where to look for "local lookup", and also what namespace to look in for
a partial specifier. For example a template in an addon's `src` tree can
invoke components and helpers in that tree becuase it has a `source`
argument passed to lookups.
This introduces the same functionality for service injections. A service
can now accept a `source` argument and its lookup will apply to the
namespace of that file.
Additionally, refactor away from using a `source` argument to the
`resolve` API of resolvers. Instead leveral the `expandLocalLookup` API
to pass the source and get an identifier that can be treated as
canonical for that factory.
|
packages/container/lib/registry.js
|
@@ -151,9 +151,10 @@ export default class Registry {
assert(`Attempting to register an unknown factory: '${fullName}'`, factory !== undefined);
let normalizedName = this.normalize(fullName);
- assert(`Cannot re-register: '${fullName}', as it has already been resolved.`, !this._resolveCache[normalizedName]);
+ let cacheKey = this.resolverCacheKey(normalizedName);
+ assert(`Cannot re-register: '${fullName}', as it has already been resolved.`, !this._resolveCache[cacheKey]);
- this._failSet.delete(normalizedName);
+ this._failSet.delete(cacheKey);
this.registrations[normalizedName] = factory;
this._options[normalizedName] = options;
}
@@ -179,13 +180,14 @@ export default class Registry {
assert('fullName must be a proper full name', this.isValidFullName(fullName));
let normalizedName = this.normalize(fullName);
+ let cacheKey = this.resolverCacheKey(normalizedName);
this._localLookupCache = Object.create(null);
delete this.registrations[normalizedName];
- delete this._resolveCache[normalizedName];
+ delete this._resolveCache[cacheKey];
delete this._options[normalizedName];
- this._failSet.delete(normalizedName);
+ this._failSet.delete(cacheKey);
}
/**
@@ -224,7 +226,6 @@ export default class Registry {
@return {Function} fullName's factory
*/
resolve(fullName, options) {
- assert('fullName must be a proper full name', this.isValidFullName(fullName));
let factory = resolve(this, this.normalize(fullName), options);
if (factory === undefined && this.fallback !== null) {
factory = this.fallback.resolve(...arguments);
@@ -450,7 +451,7 @@ export default class Registry {
let injections = this._typeInjections[type] ||
(this._typeInjections[type] = []);
- injections.push({ property, fullName });
+ injections.push({ property, specifier: fullName });
}
/**
@@ -514,7 +515,7 @@ export default class Registry {
let injections = this._injections[normalizedName] ||
(this._injections[normalizedName] = []);
- injections.push({ property, fullName: normalizedInjectionName });
+ injections.push({ property, specifier: normalizedInjectionName });
}
/**
@@ -566,12 +567,8 @@ export default class Registry {
return injections;
}
- resolverCacheKey(name, options) {
- if (!EMBER_MODULE_UNIFICATION) {
- return name;
- }
-
- return (options && options.source) ? `${options.source}:${name}` : name;
+ resolverCacheKey(name) {
+ return name;
}
/**
@@ -625,11 +622,13 @@ if (DEBUG) {
for (let key in hash) {
if (hash.hasOwnProperty(key)) {
- assert(`Expected a proper full name, given '${hash[key]}'`, this.isValidFullName(hash[key]));
+ let { specifier, source } = hash[key];
+ assert(`Expected a proper full name, given '${specifier}'`, this.isValidFullName(specifier));
injections.push({
property: key,
- fullName: hash[key]
+ specifier,
+ source
});
}
}
@@ -640,12 +639,10 @@ if (DEBUG) {
Registry.prototype.validateInjections = function(injections) {
if (!injections) { return; }
- let fullName;
-
for (let i = 0; i < injections.length; i++) {
- fullName = injections[i].fullName;
+ let {specifier, source} = injections[i];
- assert(`Attempting to inject an unknown injection: '${fullName}'`, this.has(fullName));
+ assert(`Attempting to inject an unknown injection: '${specifier}'`, this.has(specifier, {source}));
}
};
}
@@ -688,15 +685,15 @@ function resolve(registry, normalizedName, options) {
}
}
- let cacheKey = registry.resolverCacheKey(normalizedName, options);
+ let cacheKey = registry.resolverCacheKey(normalizedName);
let cached = registry._resolveCache[cacheKey];
if (cached !== undefined) { return cached; }
if (registry._failSet.has(cacheKey)) { return; }
let resolved;
if (registry.resolver) {
- resolved = registry.resolver.resolve(normalizedName, options && options.source);
+ resolved = registry.resolver.resolve(normalizedName);
}
if (resolved === undefined) {
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.