dist/ember-runtime.js in ember-source-1.6.0.beta.5 vs dist/ember-runtime.js in ember-source-1.6.0
- old
+ new
@@ -3,11 +3,11 @@
* @copyright Copyright 2011-2014 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 1.6.0-beta.5
+ * @version 1.6.0
*/
(function() {
var define, requireModule, require, requirejs, Ember;
@@ -1062,23 +1062,21 @@
a_slice = [].slice,
o_create = create;
function UNDEFINED() { }
-
- var lengthPattern = /\.(length|\[\])$/;
-
+ var lengthPattern = /\.(length|\[\])$/;
// ..........................................................
// DEPENDENT KEYS
//
// data structure:
// meta.deps = {
- // 'depKey': {
- // 'keyName': count,
- // }
+ // 'depKey': {
+ // 'keyName': count,
+ // }
// }
/*
This function returns a map of unique dependencies for a
given object and key.
@@ -1158,11 +1156,11 @@
as it's dependencies have not been changed. Once firstName or lastName are updated
any future calls (or anything bound) to fullName will incorporate the new
values.
```javascript
- Person = Ember.Object.extend({
+ var Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function() {
@@ -1185,12 +1183,11 @@
If you try to set a computed property, it will be invoked with the key and
value you want to set it to. You can also accept the previous value as the
third parameter.
```javascript
-
- Person = Ember.Object.extend({
+ var Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function(key, value, oldValue) {
@@ -1201,24 +1198,25 @@
return firstName + ' ' + lastName;
// setter
} else {
- var name = value.split(" ");
+ var name = value.split(' ');
this.set('firstName', name[0]);
this.set('lastName', name[1]);
return value;
}
}.property('firstName', 'lastName')
});
var person = Person.create();
+
person.set('fullName', 'Peter Wagenet');
- person.get('firstName') // 'Peter'
- person.get('lastName') // 'Wagenet'
+ person.get('firstName'); // 'Peter'
+ person.get('lastName'); // 'Wagenet'
```
@class ComputedProperty
@namespace Ember
@extends Ember.Descriptor
@@ -1263,11 +1261,11 @@
/**
Call on a computed property to set it into non-cached mode. When in this
mode the computed property will not automatically cache the return value.
```javascript
- MyApp.outsideService = Ember.Object.extend({
+ var outsideService = Ember.Object.extend({
value: function() {
return OutsideService.getValue();
}.property().volatile()
}).create();
```
@@ -1283,19 +1281,19 @@
/**
Call on a computed property to set it into read-only mode. When in this
mode the computed property will throw an error when set.
```javascript
- MyApp.Person = Ember.Object.extend({
+ var Person = Ember.Object.extend({
guid: function() {
return 'guid-guid-guid';
}.property().readOnly()
});
- MyApp.person = MyApp.Person.create();
+ var person = Person.create();
- MyApp.person.set('guid', 'new-guid'); // will throw an exception
+ person.set('guid', 'new-guid'); // will throw an exception
```
@method readOnly
@return {Ember.ComputedProperty} this
@chainable
@@ -1308,25 +1306,25 @@
/**
Sets the dependent keys on this computed property. Pass any number of
arguments containing key paths that this computed property depends on.
```javascript
- MyApp.President = Ember.Object.extend({
+ var President = Ember.Object.extend({
fullName: computed(function() {
return this.get('firstName') + ' ' + this.get('lastName');
// Tell Ember that this computed property depends on firstName
// and lastName
}).property('firstName', 'lastName')
});
- MyApp.president = MyApp.President.create({
+ var president = President.create({
firstName: 'Barack',
lastName: 'Obama',
});
- MyApp.president.get('fullName'); // 'Barack Obama'
+ president.get('fullName'); // 'Barack Obama'
```
@method property
@param {String} path* zero or more property paths
@return {Ember.ComputedProperty} this
@@ -1406,14 +1404,13 @@
Access the value of the function backing the computed property.
If this property has already been cached, return the cached result.
Otherwise, call the function passing the property name as an argument.
```javascript
- Person = Ember.Object.extend({
+ var Person = Ember.Object.extend({
fullName: function(keyName) {
// the keyName parameter is 'fullName' in this case.
-
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
@@ -1660,42 +1657,43 @@
return computedFunc.property.apply(computedFunc, properties);
};
};
-
- /**
- A computed property that returns true if the value of the dependent
- property is null, an empty string, empty array, or empty function.
+ /**
+ A computed property that returns true if the value of the dependent
+ property is null, an empty string, empty array, or empty function.
- Example
+ Example
- ```javascript
- var ToDoList = Ember.Object.extend({
- done: Ember.computed.empty('todos')
- });
+ ```javascript
+ var ToDoList = Ember.Object.extend({
+ done: Ember.computed.empty('todos')
+ });
- var todoList = ToDoList.create({todos: ['Unit Test', 'Documentation', 'Release']});
+ var todoList = ToDoList.create({
+ todos: ['Unit Test', 'Documentation', 'Release']
+ });
- todoList.get('done'); // false
- todoList.get('todos').clear();
- todoList.get('done'); // true
- ```
+ todoList.get('done'); // false
+ todoList.get('todos').clear();
+ todoList.get('done'); // true
+ ```
- @since 1.6.0
- @method computed.empty
- @for Ember
- @param {String} dependentKey
- @return {Ember.ComputedProperty} computed property which negate
- the original value for property
- */
- computed.empty = function (dependentKey) {
- return computed(dependentKey + '.length', function () {
- return isEmpty(get(this, dependentKey));
- });
- };
-
+ @since 1.6.0
+ @method computed.empty
+ @for Ember
+ @param {String} dependentKey
+ @return {Ember.ComputedProperty} computed property which negate
+ the original value for property
+ */
+ computed.empty = function (dependentKey) {
+ return computed(dependentKey + '.length', function () {
+ return isEmpty(get(this, dependentKey));
+ });
+ };
+
/**
A computed property that returns true if the value of the dependent
property is NOT null, an empty string, empty array, or empty function.
Note: When using `computed.notEmpty` to watch an array make sure to
@@ -1707,15 +1705,15 @@
```javascript
var Hamster = Ember.Object.extend({
hasStuff: Ember.computed.notEmpty('backpack.[]')
});
- var hamster = Hamster.create({backpack: ['Food', 'Sleeping Bag', 'Tent']});
+ var hamster = Hamster.create({ backpack: ['Food', 'Sleeping Bag', 'Tent'] });
- hamster.get('hasStuff'); // true
+ hamster.get('hasStuff'); // true
hamster.get('backpack').clear(); // []
- hamster.get('hasStuff'); // false
+ hamster.get('hasStuff'); // false
```
@method computed.notEmpty
@for Ember
@param {String} dependentKey
@@ -2147,16 +2145,16 @@
Creates a new property that is an alias for another property
on an object. Calls to `get` or `set` this property behave as
though they were called on the original property.
```javascript
- Person = Ember.Object.extend({
+ var Person = Ember.Object.extend({
name: 'Alex Matchneer',
nomen: Ember.computed.alias('name')
});
- alex = Person.create();
+ var alex = Person.create();
alex.get('nomen'); // 'Alex Matchneer'
alex.get('name'); // 'Alex Matchneer'
alex.set('nomen', '@machty');
@@ -2199,13 +2197,13 @@
var teddy = User.create({
firstName: 'Teddy',
lastName: 'Zeenny'
});
- teddy.get('nickName'); // 'Teddy'
+ teddy.get('nickName'); // 'Teddy'
teddy.set('nickName', 'TeddyBear'); // 'TeddyBear'
- teddy.get('firstName'); // 'Teddy'
+ teddy.get('firstName'); // 'Teddy'
```
@method computed.oneWay
@for Ember
@param {String} dependentKey
@@ -2238,14 +2236,14 @@
var teddy = User.create({
firstName: 'Teddy',
lastName: 'Zeenny'
});
- teddy.get('nickName'); // 'Teddy'
+ teddy.get('nickName'); // 'Teddy'
teddy.set('nickName', 'TeddyBear'); // throws Exception
// throw new Ember.Error('Cannot Set: nickName on: <User:ember27288>' );`
- teddy.get('firstName'); // 'Teddy'
+ teddy.get('firstName'); // 'Teddy'
```
@method computed.readOnly
@for Ember
@param {String} dependentKey
@@ -2268,16 +2266,16 @@
```javascript
var Hamster = Ember.Object.extend({
wishList: Ember.computed.defaultTo('favoriteFood')
});
- var hamster = Hamster.create({favoriteFood: 'Banana'});
+ var hamster = Hamster.create({ favoriteFood: 'Banana' });
- hamster.get('wishList'); // 'Banana'
+ hamster.get('wishList'); // 'Banana'
hamster.set('wishList', 'More Unit Tests');
- hamster.get('wishList'); // 'More Unit Tests'
- hamster.get('favoriteFood'); // 'Banana'
+ hamster.get('wishList'); // 'More Unit Tests'
+ hamster.get('favoriteFood'); // 'Banana'
```
@method computed.defaultTo
@for Ember
@param {String} defaultPath
@@ -2324,11 +2322,11 @@
The core Runtime framework is based on the jQuery API with a number of
performance optimizations.
@class Ember
@static
- @version 1.6.0-beta.5
+ @version 1.6.0
*/
if ('undefined' === typeof Ember) {
// Create core object. Make it act like an instance of Ember.Namespace so that
// objects assigned to it are given a sane string representation.
@@ -2351,14 +2349,14 @@
/**
@property VERSION
@type String
- @default '1.6.0-beta.5'
+ @default '1.6.0'
@static
*/
- Ember.VERSION = '1.6.0-beta.5';
+ Ember.VERSION = '1.6.0';
/**
Standard environmental variables. You can define these in a global `EmberENV`
variable before loading Ember to control various configuration settings.
@@ -3181,16 +3179,18 @@
a specified event or events are triggered.
``` javascript
var Job = Ember.Object.extend({
- logCompleted: Ember.on('completed', function(){
+ logCompleted: Ember.on('completed', function() {
console.log('Job completed!');
})
});
+
var job = Job.create();
- Ember.sendEvent(job, 'completed'); // Logs "Job completed!"
+
+ Ember.sendEvent(job, 'completed'); // Logs 'Job completed!'
```
@method on
@for Ember
@param {String} eventNames*
@@ -5093,11 +5093,14 @@
return 'Tomhuda Katzdale';
},
moniker: Ember.aliasMethod('name')
});
- var goodGuy = App.Person.create()
+ var goodGuy = App.Person.create();
+
+ goodGuy.name(); // 'Tomhuda Katzdale'
+ goodGuy.moniker(); // 'Tomhuda Katzdale'
```
@method aliasMethod
@for Ember
@param {String} methodName name of the method to alias
@@ -5204,11 +5207,10 @@
A `beforeObserver` is an alternative form of `.observesBefore()`.
```javascript
App.PersonView = Ember.View.extend({
-
friends: [{ name: 'Tom' }, { name: 'Stefan' }, { name: 'Kris' }],
valueWillChange: Ember.beforeObserver('content.value', function(obj, keyName) {
this.changingFrom = obj.get(keyName);
}),
@@ -6905,11 +6907,11 @@
// the debouncee is no longer being watched
run.debounce(myContext, myFunc, 150, true);
// console logs 'debounce ran.' one time immediately.
- // 150ms passes and nothing else is logged tot he console and
+ // 150ms passes and nothing else is logged to the console and
// the debouncee is no longer being watched
```
@method debounce
@@ -7002,15 +7004,17 @@
Set a list of properties on an object. These properties are set inside
a single `beginPropertyChanges` and `endPropertyChanges` batch, so
observers will be buffered.
```javascript
+ var anObject = Ember.Object.create();
+
anObject.setProperties({
- firstName: "Stanley",
- lastName: "Stuart",
- age: "21"
- })
+ firstName: 'Stanley',
+ lastName: 'Stuart',
+ age: 21
+ });
```
@method setProperties
@param self
@param {Object} hash
@@ -7396,13 +7400,13 @@
Unlike `Ember.typeOf` this method returns true even if the passed object is
not formally array but appears to be array-like (i.e. implements `Ember.Array`)
```javascript
- Ember.isArray(); // false
- Ember.isArray([]); // true
- Ember.isArray( Ember.ArrayProxy.create({ content: [] }) ); // true
+ Ember.isArray(); // false
+ Ember.isArray([]); // true
+ Ember.isArray(Ember.ArrayProxy.create({ content: [] })); // true
```
@method isArray
@for Ember
@param {Object} obj The object to test
@@ -7433,17 +7437,18 @@
Forces the passed object to be part of an array. If the object is already
an array or array-like, returns the object. Otherwise adds the object to
an array. If obj is `null` or `undefined`, returns an empty array.
```javascript
- Ember.makeArray(); // []
- Ember.makeArray(null); // []
- Ember.makeArray(undefined); // []
- Ember.makeArray('lindsay'); // ['lindsay']
- Ember.makeArray([1,2,42]); // [1,2,42]
+ Ember.makeArray(); // []
+ Ember.makeArray(null); // []
+ Ember.makeArray(undefined); // []
+ Ember.makeArray('lindsay'); // ['lindsay']
+ Ember.makeArray([1, 2, 42]); // [1, 2, 42]
var controller = Ember.ArrayProxy.create({ content: [] });
+
Ember.makeArray(controller) === controller; // true
```
@method makeArray
@for Ember
@@ -7457,11 +7462,12 @@
/**
Checks to see if the `methodName` exists on the `obj`.
```javascript
- var foo = {bar: Ember.K, baz: null};
+ var foo = { bar: Ember.K, baz: null };
+
Ember.canInvoke(foo, 'bar'); // true
Ember.canInvoke(foo, 'baz'); // false
Ember.canInvoke(foo, 'bat'); // false
```
@@ -7479,12 +7485,13 @@
Checks to see if the `methodName` exists on the `obj`,
and if it does, invokes it with the arguments passed.
```javascript
var d = new Date('03/15/2013');
- Ember.tryInvoke(d, 'getTime'); // 1363320000000
- Ember.tryInvoke(d, 'setFullYear', [2014]); // 1394856000000
+
+ Ember.tryInvoke(d, 'getTime'); // 1363320000000
+ Ember.tryInvoke(d, 'setFullYear', [2014]); // 1394856000000
Ember.tryInvoke(d, 'noSuchMethod', [2014]); // undefined
```
@method tryInvoke
@for Ember
@@ -7512,21 +7519,23 @@
return count !== 1;
})();
/**
- Provides try { } finally { } functionality, while working
+ Provides try/finally functionality, while working
around Safari's double finally bug.
```javascript
var tryable = function() {
someResource.lock();
runCallback(); // May throw error.
};
+
var finalizer = function() {
someResource.unlock();
};
+
Ember.tryFinally(tryable, finalizer);
```
@method tryFinally
@for Ember
@@ -7574,16 +7583,16 @@
return (finalResult === undefined) ? result : finalResult;
};
}
/**
- Provides try { } catch finally { } functionality, while working
+ Provides try/catch/finally functionality, while working
around Safari's double finally bug.
```javascript
var tryable = function() {
- for (i=0, l=listeners.length; i<l; i++) {
+ for (i = 0, l = listeners.length; i < l; i++) {
listener = listeners[i];
beforeValues[i] = listener.before(name, time(), payload);
}
return callback.call(binding);
@@ -7593,15 +7602,16 @@
payload = payload || {};
payload.exception = e;
};
var finalizer = function() {
- for (i=0, l=listeners.length; i<l; i++) {
+ for (i = 0, l = listeners.length; i < l; i++) {
listener = listeners[i];
listener.after(name, time(), payload, beforeValues[i]);
}
};
+
Ember.tryCatchFinally(tryable, catchable, finalizer);
```
@method tryCatchFinally
@for Ember
@@ -7702,19 +7712,19 @@
Ember.typeOf(101); // 'number'
Ember.typeOf(new Number(101)); // 'number'
Ember.typeOf(true); // 'boolean'
Ember.typeOf(new Boolean(true)); // 'boolean'
Ember.typeOf(Ember.makeArray); // 'function'
- Ember.typeOf([1,2,90]); // 'array'
+ Ember.typeOf([1, 2, 90]); // 'array'
Ember.typeOf(/abc/); // 'regexp'
Ember.typeOf(new Date()); // 'date'
Ember.typeOf(Ember.Object.extend()); // 'class'
Ember.typeOf(Ember.Object.create()); // 'instance'
Ember.typeOf(new Error('teamocil')); // 'error'
- // "normal" JavaScript object
- Ember.typeOf({a: 'b'}); // 'object'
+ // 'normal' JavaScript object
+ Ember.typeOf({ a: 'b' }); // 'object'
```
@method typeOf
@for Ember
@param {Object} item the item to check
@@ -11241,11 +11251,11 @@
container.resolve('api:twitter') // => Twitter
```
Optionally the container can be provided with a custom resolver.
If provided, `resolve` will first provide the custom resolver
- the oppertunity to resolve the fullName, otherwise it will fallback
+ the opportunity to resolve the fullName, otherwise it will fallback
to the registry.
```javascript
var container = new Container();
container.resolver = function(fullName) {
@@ -11328,11 +11338,11 @@
twitter instanceof Twitter; // => true
// by default the container will return singletons
var twitter2 = container.lookup('api:twitter');
- twitter instanceof Twitter; // => true
+ twitter2 instanceof Twitter; // => true
twitter === twitter2; //=> true
```
If singletons are not wanted an optional flag can be provided at lookup.
@@ -12222,11 +12232,11 @@
The `initialize` function has the following signature:
```javascript
- function (array, changeMeta, instanceMeta)
+ function(array, changeMeta, instanceMeta)
```
`array` - The initial value of the arrayComputed, an empty array.
`changeMeta` - An object which contains meta information about the
@@ -12242,11 +12252,11 @@
The `removedItem` and `addedItem` functions both have the following signature:
```javascript
- function (accumulatedValue, item, changeMeta, instanceMeta)
+ function(accumulatedValue, item, changeMeta, instanceMeta)
```
`accumulatedValue` - The value returned from the last time
`removedItem` or `addedItem` was called or an empty array.
@@ -12415,12 +12425,16 @@
// We suspend observers to ignore replacements from `reset` when totally
// recomputing. Unfortunately we cannot properly suspend the observers
// because we only have the key; instead we make the observers no-ops
this.suspended = false;
- // This is used to coalesce item changes from property observers.
+ // This is used to coalesce item changes from property observers within a
+ // single item.
this.changedItems = {};
+ // This is used to coalesce item changes for multiple items that depend on
+ // some shared state.
+ this.changedItemCount = 0;
}
function ItemPropertyObserverContext (dependentArray, index, trackedArray) {
Ember.assert("Internal error: trackedArray is null or undefined", trackedArray);
@@ -12658,16 +12672,19 @@
observerContext: observerContext,
obj: obj,
previousValues: {}
};
}
+ ++this.changedItemCount;
this.changedItems[guid].previousValues[keyName] = get(obj, keyName);
},
itemPropertyDidChange: function(obj, keyName, array, observerContext) {
- this.flushChanges();
+ if (--this.changedItemCount === 0) {
+ this.flushChanges();
+ }
},
flushChanges: function() {
var changedItems = this.changedItems, key, c, changeMeta;
@@ -12999,11 +13016,11 @@
The `initialize` function has the following signature:
```javascript
- function (initialValue, changeMeta, instanceMeta)
+ function(initialValue, changeMeta, instanceMeta)
```
`initialValue` - The value of the `initialValue` property from the
options object.
@@ -13020,11 +13037,11 @@
The `removedItem` and `addedItem` functions both have the following signature:
```javascript
- function (accumulatedValue, item, changeMeta, instanceMeta)
+ function(accumulatedValue, item, changeMeta, instanceMeta)
```
`accumulatedValue` - The value returned from the last time
`removedItem` or `addedItem` was called or `initialValue`.
@@ -13070,19 +13087,19 @@
important that the *same* array be returned to avoid accidentally triggering observers.
Example
```javascript
- Ember.computed.max = function (dependentKey) {
+ Ember.computed.max = function(dependentKey) {
return Ember.reduceComputed(dependentKey, {
initialValue: -Infinity,
- addedItem: function (accumulatedValue, item, changeMeta, instanceMeta) {
+ addedItem: function(accumulatedValue, item, changeMeta, instanceMeta) {
return Math.max(accumulatedValue, item);
},
- removedItem: function (accumulatedValue, item, changeMeta, instanceMeta) {
+ removedItem: function(accumulatedValue, item, changeMeta, instanceMeta) {
if (item < accumulatedValue) {
return accumulatedValue;
}
}
});
@@ -13112,14 +13129,14 @@
return Ember.compare(reversedNameA, reversedNameB);
})
});
App.PersonController = Ember.ObjectController.extend({
- reversedName: function () {
+ reversedName: function() {
return reverse(get(this, 'name'));
}.property('name')
- })
+ });
```
Dependent keys whose values are not arrays are treated as regular
dependencies: when they change, the computed property is completely
recalculated. It is sometimes useful to have dependent arrays with similar
@@ -13246,16 +13263,17 @@
A computed property that calculates the maximum value in the
dependent array. This will return `-Infinity` when the dependent
array is empty.
```javascript
- App.Person = Ember.Object.extend({
+ var Person = Ember.Object.extend({
childAges: Ember.computed.mapBy('children', 'age'),
maxChildAge: Ember.computed.max('childAges')
});
- var lordByron = App.Person.create({children: []});
+ var lordByron = Person.create({ children: [] });
+
lordByron.get('maxChildAge'); // -Infinity
lordByron.get('children').pushObject({
name: 'Augusta Ada Byron', age: 7
});
lordByron.get('maxChildAge'); // 7
@@ -13294,16 +13312,17 @@
A computed property that calculates the minimum value in the
dependent array. This will return `Infinity` when the dependent
array is empty.
```javascript
- App.Person = Ember.Object.extend({
+ var Person = Ember.Object.extend({
childAges: Ember.computed.mapBy('children', 'age'),
minChildAge: Ember.computed.min('childAges')
});
- var lordByron = App.Person.create({children: []});
+ var lordByron = Person.create({ children: [] });
+
lordByron.get('minChildAge'); // Infinity
lordByron.get('children').pushObject({
name: 'Augusta Ada Byron', age: 7
});
lordByron.get('minChildAge'); // 7
@@ -13349,19 +13368,20 @@
```
Example
```javascript
- App.Hamster = Ember.Object.extend({
+ var Hamster = Ember.Object.extend({
excitingChores: Ember.computed.map('chores', function(chore) {
return chore.toUpperCase() + '!';
})
});
- var hamster = App.Hamster.create({
+ var hamster = Hamster.create({
chores: ['clean', 'write more unit tests']
});
+
hamster.get('excitingChores'); // ['CLEAN!', 'WRITE MORE UNIT TESTS!']
```
@method computed.map
@for Ember
@@ -13387,17 +13407,18 @@
/**
Returns an array mapped to the specified key.
```javascript
- App.Person = Ember.Object.extend({
+ var Person = Ember.Object.extend({
childAges: Ember.computed.mapBy('children', 'age')
});
- var lordByron = App.Person.create({children: []});
+ var lordByron = Person.create({ children: [] });
+
lordByron.get('childAges'); // []
- lordByron.get('children').pushObject({name: 'Augusta Ada Byron', age: 7});
+ lordByron.get('children').pushObject({ name: 'Augusta Ada Byron', age: 7 });
lordByron.get('childAges'); // [7]
lordByron.get('children').pushObjects([{
name: 'Allegra Byron',
age: 5
}, {
@@ -13436,21 +13457,24 @@
```javascript
function(item);
```
```javascript
- App.Hamster = Ember.Object.extend({
+ var Hamster = Ember.Object.extend({
remainingChores: Ember.computed.filter('chores', function(chore) {
return !chore.done;
})
});
- var hamster = App.Hamster.create({chores: [
- {name: 'cook', done: true},
- {name: 'clean', done: true},
- {name: 'write more unit tests', done: false}
- ]});
+ var hamster = Hamster.create({
+ chores: [
+ { name: 'cook', done: true },
+ { name: 'clean', done: true },
+ { name: 'write more unit tests', done: false }
+ ]
+ });
+
hamster.get('remainingChores'); // [{name: 'write more unit tests', done: false}]
```
@method computed.filter
@for Ember
@@ -13491,20 +13515,23 @@
/**
Filters the array by the property and value
```javascript
- App.Hamster = Ember.Object.extend({
+ var Hamster = Ember.Object.extend({
remainingChores: Ember.computed.filterBy('chores', 'done', false)
});
- var hamster = App.Hamster.create({chores: [
- {name: 'cook', done: true},
- {name: 'clean', done: true},
- {name: 'write more unit tests', done: false}
- ]});
- hamster.get('remainingChores'); // [{name: 'write more unit tests', done: false}]
+ var hamster = Hamster.create({
+ chores: [
+ { name: 'cook', done: true },
+ { name: 'clean', done: true },
+ { name: 'write more unit tests', done: false }
+ ]
+ });
+
+ hamster.get('remainingChores'); // [{ name: 'write more unit tests', done: false }]
```
@method computed.filterBy
@for Ember
@param {String} dependentKey
@@ -13543,20 +13570,23 @@
elements from one or more dependent arrays.
Example
```javascript
- App.Hamster = Ember.Object.extend({
+ var Hamster = Ember.Object.extend({
uniqueFruits: Ember.computed.uniq('fruits')
});
- var hamster = App.Hamster.create({fruits: [
- 'banana',
- 'grape',
- 'kale',
- 'banana'
- ]});
+ var hamster = Hamster.create({
+ fruits: [
+ 'banana',
+ 'grape',
+ 'kale',
+ 'banana'
+ ]
+ });
+
hamster.get('uniqueFruits'); // ['banana', 'grape', 'kale']
```
@method computed.uniq
@for Ember
@@ -13688,19 +13718,22 @@
dependent array.
Example
```javascript
- App.Hamster = Ember.Object.extend({
+ var Hamster = Ember.Object.extend({
likes: ['banana', 'grape', 'kale'],
wants: Ember.computed.setDiff('likes', 'fruits')
});
- var hamster = App.Hamster.create({fruits: [
- 'grape',
- 'kale',
- ]});
+ var hamster = Hamster.create({
+ fruits: [
+ 'grape',
+ 'kale',
+ ]
+ });
+
hamster.get('wants'); // ['banana']
```
@method computed.setDiff
@for Ember
@@ -13828,22 +13861,24 @@
if (a.priority > b.priority) {
return 1;
} else if (a.priority < b.priority) {
return -1;
}
+
return 0;
}),
});
+
var todoList = ToDoList.create({todos: [
- {name: 'Unit Test', priority: 2},
- {name: 'Documentation', priority: 3},
- {name: 'Release', priority: 1}
+ { name: 'Unit Test', priority: 2 },
+ { name: 'Documentation', priority: 3 },
+ { name: 'Release', priority: 1 }
]});
- todoList.get('sortedTodos'); // [{name:'Documentation', priority:3}, {name:'Release', priority:1}, {name:'Unit Test', priority:2}]
- todoList.get('sortedTodosDesc'); // [{name:'Unit Test', priority:2}, {name:'Release', priority:1}, {name:'Documentation', priority:3}]
- todoList.get('priorityTodos'); // [{name:'Release', priority:1}, {name:'Unit Test', priority:2}, {name:'Documentation', priority:3}]
+ todoList.get('sortedTodos'); // [{ name:'Documentation', priority:3 }, { name:'Release', priority:1 }, { name:'Unit Test', priority:2 }]
+ todoList.get('sortedTodosDesc'); // [{ name:'Unit Test', priority:2 }, { name:'Release', priority:1 }, { name:'Documentation', priority:3 }]
+ todoList.get('priorityTodos'); // [{ name:'Release', priority:1 }, { name:'Unit Test', priority:2 }, { name:'Documentation', priority:3 }]
```
@method computed.sort
@for Ember
@param {String} dependentKey
@@ -14442,11 +14477,11 @@
respect that method.
```javascript
Ember.isEqual('hello', 'hello'); // true
Ember.isEqual(1, 2); // false
- Ember.isEqual([4,2], [4,2]); // false
+ Ember.isEqual([4, 2], [4, 2]); // false
```
@method isEqual
@for Ember
@param {Object} a first object to compare
@@ -15813,41 +15848,32 @@
var Mixin = __dependency3__.Mixin;
var computed = __dependency4__.computed;
var run = __dependency5__["default"];
var RSVP = __dependency6__["default"];
- if (Ember.FEATURES['ember-runtime-test-friendly-promises']) {
+ var asyncStart = function() {
+ if (Ember.Test && Ember.Test.adapter) {
+ Ember.Test.adapter.asyncStart();
+ }
+ };
- var asyncStart = function() {
- if (Ember.Test && Ember.Test.adapter) {
- Ember.Test.adapter.asyncStart();
- }
- };
+ var asyncEnd = function() {
+ if (Ember.Test && Ember.Test.adapter) {
+ Ember.Test.adapter.asyncEnd();
+ }
+ };
- var asyncEnd = function() {
- if (Ember.Test && Ember.Test.adapter) {
- Ember.Test.adapter.asyncEnd();
- }
- };
+ RSVP.configure('async', function(callback, promise) {
+ var async = !run.currentRunLoop;
- RSVP.configure('async', function(callback, promise) {
- var async = !run.currentRunLoop;
+ if (Ember.testing && async) { asyncStart(); }
- if (Ember.testing && async) { asyncStart(); }
-
- run.backburner.schedule('actions', function(){
- if (Ember.testing && async) { asyncEnd(); }
- callback(promise);
- });
+ run.backburner.schedule('actions', function(){
+ if (Ember.testing && async) { asyncEnd(); }
+ callback(promise);
});
- } else {
- RSVP.configure('async', function(callback, promise) {
- run.backburner.schedule('actions', function(){
- callback(promise);
- });
- });
- }
+ });
RSVP.Promise.prototype.fail = function(callback, label){
Ember.deprecate('RSVP.Promise.fail has been renamed as RSVP.Promise.catch');
return this['catch'](callback, label);
};
@@ -18576,11 +18602,11 @@
}
return this._super();
},
- isSorted: computed.bool('sortProperties'),
+ isSorted: computed.notEmpty('sortProperties'),
/**
Overrides the default arrangedContent from arrayProxy in order to sort by sortFunction.
Also sets up observers for each sortProperty on each item in the content Array.
@@ -20312,11 +20338,11 @@
The provided `callback` will be called with the `name` passed
resolved from a string into the object:
``` javascript
- Ember.onLoad('Ember.Handlebars' function(hbars){
+ Ember.onLoad('Ember.Handlebars' function(hbars) {
hbars.registerHelper(...);
});
```
@method onLoad
@@ -20727,14 +20753,15 @@
```js
var Pagination = Ember.CollectionView.extend({
tagName: 'ul',
classNames: ['pagination'],
+
init: function() {
this._super();
if (!this.get('content')) {
- this.set('content', Ember.A([]));
+ this.set('content', Ember.A());
}
}
});
```
@@ -22453,11 +22480,11 @@
container.resolve('api:twitter') // => Twitter
```
Optionally the container can be provided with a custom resolver.
If provided, `resolve` will first provide the custom resolver
- the oppertunity to resolve the fullName, otherwise it will fallback
+ the opportunity to resolve the fullName, otherwise it will fallback
to the registry.
```javascript
var container = new Container();
container.resolver = function(fullName) {
@@ -22540,10 +22567,10 @@
twitter instanceof Twitter; // => true
// by default the container will return singletons
var twitter2 = container.lookup('api:twitter');
- twitter instanceof Twitter; // => true
+ twitter2 instanceof Twitter; // => true
twitter === twitter2; //=> true
```
If singletons are not wanted an optional flag can be provided at lookup.