dist/ember-runtime.js in ember-source-2.18.0.beta.3 vs dist/ember-runtime.js in ember-source-2.18.0.beta.4
- old
+ new
@@ -4,11 +4,11 @@
* @copyright Copyright 2011-2017 Tilde Inc. and contributors
* Portions Copyright 2006-2011 Strobe Inc.
* Portions Copyright 2008-2011 Apple Inc. All rights reserved.
* @license Licensed under MIT license
* See https://raw.github.com/emberjs/ember.js/master/LICENSE
- * @version 2.18.0-beta.3
+ * @version 2.18.0-beta.4
*/
/*global process */
var enifed, requireModule, Ember;
var mainContext = this; // Used in ember-environment/lib/global.js
@@ -3111,11 +3111,11 @@
}
var counter = m.peekWatching(keyPath) || 0;
if (counter === 1) {
m.writeWatching(keyPath, 0);
- m.readableChains().remove(keyPath);
+ m.writableChains(makeChainNode).remove(keyPath);
} else if (counter > 1) {
m.writeWatching(keyPath, counter - 1);
}
}
@@ -3344,15 +3344,12 @@
ChainNode.prototype.remove = function remove(path) {
var paths = this._paths;
if (paths === undefined) {
return;
}
-
if (paths[path] > 0) {
paths[path]--;
- } else {
- return;
}
var key = firstKey(path);
var tail = path.slice(key.length + 1);
@@ -5803,18 +5800,19 @@
you are implementing raw event handlers when interfacing with other
libraries or plugins, you should probably wrap all of your code inside this
call.
```javascript
+ import { run } from '@ember/runloop';
+
run(function() {
// code to be executed within a RunLoop
});
```
-
- @class @ember/runloop
+ @method run
+ @for @ember/runloop
@static
- @constructor
@param {Object} [target] target of method to call
@param {Function|String} method Method to invoke.
May be a function or a string. If you pass a string
then it will be looked up on the passed target.
@param {Object} [args*] Any additional arguments you wish to pass to the method.
@@ -5833,21 +5831,26 @@
Please note: This is not for normal usage, and should be used sparingly.
If invoked when not within a run loop:
```javascript
- run.join(function() {
+ import { join } from '@ember/runloop';
+
+ join(function() {
// creates a new run-loop
});
```
Alternatively, if called within an existing run loop:
```javascript
+ import { run, join } from '@ember/runloop';
+
run(function() {
// creates a new run-loop
- run.join(function() {
+
+ join(function() {
// joins with the existing run-loop, and queues for invocation on
// the existing run-loops action queue.
});
});
```
@@ -5872,11 +5875,11 @@
Allows you to specify which context to call the specified function in while
adding the execution of that function to the Ember run loop. This ability
makes this method a great way to asynchronously integrate third-party libraries
into your Ember application.
- `run.bind` takes two main arguments, the desired context and the function to
+ `bind` takes two main arguments, the desired context and the function to
invoke in that context. Any additional arguments will be supplied as arguments
to the function that is passed in.
Let's use the creation of a TinyMCE component as an example. Currently,
TinyMCE provides a setup configuration option we can use to do some processing
@@ -5884,14 +5887,15 @@
We can use that setup option to do some additional setup for our component.
The component itself could look something like the following:
```app/components/rich-text-editor.js
import Component from '@ember/component';
+ import { on } from '@ember/object/evented';
import { bind } from '@ember/runloop';
export default Component.extend({
- initializeTinyMCE: Ember.on('didInsertElement', function() {
+ initializeTinyMCE: on('didInsertElement', function() {
tinymce.init({
selector: '#' + this.$().prop('id'),
setup: Ember.run.bind(this, this.setupEditor)
});
}),
@@ -5951,13 +5955,15 @@
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
a lower-level way to use a RunLoop instead of using `run()`.
```javascript
- run.begin();
+ import { begin, end } from '@ember/runloop';
+
+ begin();
// code to be executed within a RunLoop
- run.end();
+ end();
```
@method begin
@static
@for @ember/runloop
@@ -5972,13 +5978,15 @@
Ends a RunLoop. This must be called sometime after you call
`run.begin()` to flush any deferred actions. This is a lower-level way
to use a RunLoop instead of using `run()`.
```javascript
- run.begin();
+ import { begin, end } from '@ember/runloop';
+
+ begin();
// code to be executed within a RunLoop
- run.end();
+ end();
```
@method end
@static
@for @ember/runloop
@@ -6010,16 +6018,18 @@
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.
```javascript
- run.schedule('sync', this, function() {
+ import { schedule } from '@ember/runloop';
+
+ schedule('sync', this, function() {
// this will be executed in the first RunLoop queue, when bindings are synced
console.log('scheduled on sync queue');
});
- run.schedule('actions', this, function() {
+ schedule('actions', this, function() {
// this will be executed in the 'actions' queue, after bindings have synced.
console.log('scheduled on actions queue');
});
// Note the functions will be run in order based on the run queues order.
@@ -6091,11 +6101,13 @@
period of time instead of using `setTimeout()`. This method will ensure that
items that expire during the same script execution cycle all execute
together, which is often more efficient than using a real setTimeout.
```javascript
- run.later(myContext, function() {
+ import { later } from '@ember/runloop';
+
+ later(myContext, function() {
// code here will execute within a RunLoop in about 500ms with this == myContext
}, 500);
```
@method later
@@ -6148,17 +6160,19 @@
Note that although you can pass optional arguments these will not be
considered when looking for duplicates. New arguments will replace previous
calls.
```javascript
+ import { run, scheduleOnce } from '@ember/runloop';
+
function sayHi() {
console.log('hi');
}
run(function() {
- run.scheduleOnce('afterRender', myContext, sayHi);
- run.scheduleOnce('afterRender', myContext, sayHi);
+ scheduleOnce('afterRender', myContext, sayHi);
+ scheduleOnce('afterRender', myContext, sayHi);
// sayHi will only be executed once, in the afterRender queue of the RunLoop
});
```
Also note that for `run.scheduleOnce` to prevent additional calls, you need to
@@ -6168,22 +6182,24 @@
function log() {
console.log('Logging only once');
}
function scheduleIt() {
- run.scheduleOnce('actions', myContext, log);
+ scheduleOnce('actions', myContext, log);
}
scheduleIt();
scheduleIt();
```
But this other case will schedule the function multiple times:
```javascript
+ import { scheduleOnce } from '@ember/runloop';
+
function scheduleIt() {
- run.scheduleOnce('actions', myContext, function() {
+ scheduleOnce('actions', myContext, function() {
console.log('Closure');
});
}
scheduleIt();
@@ -6218,11 +6234,13 @@
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.
```javascript
- run.next(myContext, function() {
+ import { next } from '@ember/runloop';
+
+ next(myContext, function() {
// code to be executed in the next run loop,
// which will be scheduled after the current one
});
```
@@ -6240,15 +6258,16 @@
Example:
```app/components/my-component.js
import Component from '@ember/component';
+ import { scheduleOnce } from '@ember/runloop';
export Component.extend({
didInsertElement() {
this._super(...arguments);
- run.scheduleOnce('afterRender', this, 'processChildElements');
+ scheduleOnce('afterRender', this, 'processChildElements');
},
processChildElements() {
// ... do something with component's child component
// elements after they've finished rendering, which
@@ -6289,57 +6308,67 @@
args.push(1);
return backburner$1.later.apply(backburner$1, args);
};
/**
- Cancels a scheduled item. Must be a value returned by `run.later()`,
- `run.once()`, `run.scheduleOnce()`, `run.next()`, `run.debounce()`, or
- `run.throttle()`.
+ Cancels a scheduled item. Must be a value returned by `later()`,
+ `once()`, `scheduleOnce()`, `next()`, `debounce()`, or
+ `throttle()`.
```javascript
- let runNext = run.next(myContext, function() {
+ import {
+ next,
+ cancel,
+ later,
+ scheduleOnce,
+ once,
+ throttle,
+ debounce
+ } from '@ember/runloop';
+
+ let runNext = next(myContext, function() {
// will not be executed
});
- run.cancel(runNext);
+ cancel(runNext);
- let runLater = run.later(myContext, function() {
+ let runLater = later(myContext, function() {
// will not be executed
}, 500);
- run.cancel(runLater);
+ cancel(runLater);
- let runScheduleOnce = run.scheduleOnce('afterRender', myContext, function() {
+ let runScheduleOnce = scheduleOnce('afterRender', myContext, function() {
// will not be executed
});
- run.cancel(runScheduleOnce);
+ cancel(runScheduleOnce);
- let runOnce = run.once(myContext, function() {
+ let runOnce = once(myContext, function() {
// will not be executed
});
- run.cancel(runOnce);
+ cancel(runOnce);
- let throttle = run.throttle(myContext, function() {
+ let throttle = throttle(myContext, function() {
// will not be executed
}, 1, false);
- run.cancel(throttle);
+ cancel(throttle);
- let debounce = run.debounce(myContext, function() {
+ let debounce = debounce(myContext, function() {
// will not be executed
}, 1);
- run.cancel(debounce);
+ cancel(debounce);
- let debounceImmediate = run.debounce(myContext, function() {
+ let debounceImmediate = debounce(myContext, function() {
// will be executed since we passed in true (immediate)
}, 100, true);
// the 100ms delay until this method can be called again will be canceled
- run.cancel(debounceImmediate);
+ cancel(debounceImmediate);
```
@method cancel
@static
@for @ember/runloop
@@ -6361,20 +6390,22 @@
but the action should only be called once when the event is done firing.
A common example is for scroll events where you only want updates to
happen once scrolling has ceased.
```javascript
+ import { debounce } from '@ember/runloop';
+
function whoRan() {
console.log(this.name + ' ran.');
}
let myContext = { name: 'debounce' };
- run.debounce(myContext, whoRan, 150);
+ debounce(myContext, whoRan, 150);
// less than 150ms passes
- run.debounce(myContext, whoRan, 150);
+ debounce(myContext, whoRan, 150);
// 150ms passes
// whoRan is invoked with context myContext
// console logs 'debounce ran.' one time.
```
@@ -6384,30 +6415,31 @@
`debounce` is called again before the specified time has elapsed,
the timer is reset and the entire period must pass again before
the method can be called again.
```javascript
+ import { debounce } from '@ember/runloop';
+
function whoRan() {
console.log(this.name + ' ran.');
}
let myContext = { name: 'debounce' };
- run.debounce(myContext, whoRan, 150, true);
+ debounce(myContext, whoRan, 150, true);
// console logs 'debounce ran.' one time immediately.
// 100ms passes
- run.debounce(myContext, whoRan, 150, true);
+ debounce(myContext, whoRan, 150, true);
// 150ms passes and nothing else is logged to the console and
// the debouncee is no longer being watched
- run.debounce(myContext, whoRan, 150, true);
+ debounce(myContext, whoRan, 150, true);
// console logs 'debounce ran.' one time immediately.
// 150ms passes and nothing else is logged to the console and
// the debouncee is no longer being watched
-
```
@method debounce
@static
@for @ember/runloop
@@ -6429,27 +6461,29 @@
/**
Ensure that the target method is never called more frequently than
the specified spacing period. The target method is called immediately.
```javascript
+ import { throttle } from '@ember/runloop';
+
function whoRan() {
console.log(this.name + ' ran.');
}
let myContext = { name: 'throttle' };
- run.throttle(myContext, whoRan, 150);
+ throttle(myContext, whoRan, 150);
// whoRan is invoked with context myContext
// console logs 'throttle ran.'
// 50ms passes
- run.throttle(myContext, whoRan, 150);
+ throttle(myContext, whoRan, 150);
// 50ms passes
- run.throttle(myContext, whoRan, 150);
+ throttle(myContext, whoRan, 150);
// 150ms passes
- run.throttle(myContext, whoRan, 150);
+ throttle(myContext, whoRan, 150);
// whoRan is invoked with context myContext
// console logs 'throttle ran.'
```
@method throttle