ember-source 1.2.0.beta.1 → 1.2.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ember-source might be problematic. Click here for more details.

@@ -10,7 +10,7 @@ var Ember = { assert: function() {}, FEATURES: { isEnabled: function() {} } };
10
10
  // ==========================================================================
11
11
 
12
12
 
13
- // Version: 1.2.0-beta.1
13
+ // Version: 1.2.0-beta.2
14
14
 
15
15
  (function() {
16
16
  /*global __fail__*/
@@ -8,7 +8,7 @@
8
8
  // ==========================================================================
9
9
 
10
10
 
11
- // Version: 1.2.0-beta.1
11
+ // Version: 1.2.0-beta.2
12
12
 
13
13
  (function() {
14
14
  /*global __fail__*/
@@ -194,7 +194,7 @@ if (!Ember.testing) {
194
194
  // ==========================================================================
195
195
 
196
196
 
197
- // Version: 1.2.0-beta.1
197
+ // Version: 1.2.0-beta.2
198
198
 
199
199
  (function() {
200
200
  var define, requireModule;
@@ -259,7 +259,7 @@ var define, requireModule;
259
259
 
260
260
  @class Ember
261
261
  @static
262
- @version 1.2.0-beta.1
262
+ @version 1.2.0-beta.2
263
263
  */
264
264
 
265
265
  if ('undefined' === typeof Ember) {
@@ -286,10 +286,10 @@ Ember.toString = function() { return "Ember"; };
286
286
  /**
287
287
  @property VERSION
288
288
  @type String
289
- @default '1.2.0-beta.1'
289
+ @default '1.2.0-beta.2'
290
290
  @final
291
291
  */
292
- Ember.VERSION = '1.2.0-beta.1';
292
+ Ember.VERSION = '1.2.0-beta.2';
293
293
 
294
294
  /**
295
295
  Standard environmental variables. You can define these in a global `ENV`
@@ -329,15 +329,28 @@ Ember.FEATURES = Ember.ENV.FEATURES || {};
329
329
  Test that a feature is enabled. Parsed by Ember's build tools to leave
330
330
  experimental features out of beta/stable builds.
331
331
 
332
- You can define an `ENV.ENABLE_ALL_FEATURES` config to force all features to
333
- be enabled.
332
+ You can define the following configuration options:
333
+
334
+ * `ENV.ENABLE_ALL_FEATURES` - force all features to be enabled.
335
+ * `ENV.ENABLE_OPTIONAL_FEATURES` - enable any features that have not been explicitly
336
+ enabled/disabled.
334
337
 
335
338
  @method isEnabled
336
339
  @param {string} feature
337
340
  */
338
341
 
339
342
  Ember.FEATURES.isEnabled = function(feature) {
340
- return Ember.ENV.ENABLE_ALL_FEATURES || Ember.FEATURES[feature];
343
+ var featureValue = Ember.FEATURES[feature];
344
+
345
+ if (Ember.ENV.ENABLE_ALL_FEATURES) {
346
+ return true;
347
+ } else if (featureValue === true || featureValue === false || featureValue === undefined) {
348
+ return featureValue;
349
+ } else if (Ember.ENV.ENABLE_OPTIONAL_FEATURES) {
350
+ return true;
351
+ } else {
352
+ return false;
353
+ }
341
354
  };
342
355
 
343
356
  // ..........................................................
@@ -3956,38 +3969,9 @@ Ember.finishChains = function(obj) {
3956
3969
 
3957
3970
  (function() {
3958
3971
  /**
3959
- @module ember-metal
3972
+ @module ember-metal
3960
3973
  */
3961
3974
 
3962
- var forEach = Ember.EnumerableUtils.forEach,
3963
- IS_BRACE_EXPANSION = /^\{([^.]*)\}$/;
3964
-
3965
- /**
3966
- Expands `pattern`, invoking `callback` for each expansion.
3967
-
3968
- The only pattern supported is brace-expansion, anything else will be passed
3969
- once to `callback` directly. Furthermore, brace-expansion is only applied to
3970
- the entire pattern, not to substrings.
3971
-
3972
- Example
3973
- ```js
3974
- function echo(arg){ console.log(arg); }
3975
-
3976
- Ember.expandProperties('foo.bar', echo); //=> 'foo.bar'
3977
- Ember.expandProperties('{foo,bar}', echo); //=> 'foo', 'bar'
3978
- Ember.expandProperties('foo.{bar,baz}', echo); //=> 'foo.{bar,baz}'
3979
- ```
3980
-
3981
- @method
3982
- @private
3983
- @param {string} pattern The property pattern to expand.
3984
- @param {function} callback The callback to invoke. It is invoked once per
3985
- expansion, and is passed the expansion.
3986
- */
3987
- Ember.expandProperties = function (pattern, callback) {
3988
-
3989
- callback(pattern);
3990
- };
3991
3975
 
3992
3976
  })();
3993
3977
 
@@ -4047,7 +4031,6 @@ Ember.unwatchPath = function(obj, keyPath) {
4047
4031
  var metaFor = Ember.meta, // utils.js
4048
4032
  GUID_KEY = Ember.GUID_KEY, // utils.js
4049
4033
  META_KEY = Ember.META_KEY, // utils.js
4050
- expandProperties = Ember.expandProperties,
4051
4034
  removeChainWatcher = Ember.removeChainWatcher,
4052
4035
  watchKey = Ember.watchKey, // watch_key.js
4053
4036
  unwatchKey = Ember.unwatchKey,
@@ -4057,6 +4040,7 @@ var metaFor = Ember.meta, // utils.js
4057
4040
  generateGuid = Ember.generateGuid,
4058
4041
  IS_PATH = /[\.\*]/;
4059
4042
 
4043
+
4060
4044
  // returns true if the passed path is just a keyName
4061
4045
  function isKeyName(path) {
4062
4046
  return path==='*' || !IS_PATH.test(path);
@@ -4080,13 +4064,13 @@ Ember.watch = function(obj, _keyPath) {
4080
4064
  // can't watch length on Array - it is special...
4081
4065
  if (_keyPath === 'length' && typeOf(obj) === 'array') { return; }
4082
4066
 
4083
- expandProperties(_keyPath, function (keyPath) {
4084
- if (isKeyName(keyPath)) {
4085
- watchKey(obj, keyPath);
4067
+
4068
+ if (isKeyName(_keyPath)) {
4069
+ watchKey(obj, _keyPath);
4086
4070
  } else {
4087
- watchPath(obj, keyPath);
4071
+ watchPath(obj, _keyPath);
4088
4072
  }
4089
- });
4073
+
4090
4074
  };
4091
4075
 
4092
4076
  Ember.isWatching = function isWatching(obj, key) {
@@ -4100,13 +4084,13 @@ Ember.unwatch = function(obj, _keyPath) {
4100
4084
  // can't watch length on Array - it is special...
4101
4085
  if (_keyPath === 'length' && typeOf(obj) === 'array') { return; }
4102
4086
 
4103
- expandProperties(_keyPath, function (keyPath) {
4104
- if (isKeyName(keyPath)) {
4105
- unwatchKey(obj, keyPath);
4087
+
4088
+ if (isKeyName(_keyPath)) {
4089
+ unwatchKey(obj, _keyPath);
4106
4090
  } else {
4107
- unwatchPath(obj, keyPath);
4091
+ unwatchPath(obj, _keyPath);
4108
4092
  }
4109
- });
4093
+
4110
4094
  };
4111
4095
 
4112
4096
  /**
@@ -4192,13 +4176,13 @@ Ember.warn("The CP_DEFAULT_CACHEABLE flag has been removed and computed properti
4192
4176
  var get = Ember.get,
4193
4177
  set = Ember.set,
4194
4178
  metaFor = Ember.meta,
4195
- expandProperties = Ember.expandProperties,
4196
4179
  a_slice = [].slice,
4197
4180
  o_create = Ember.create,
4198
4181
  META_KEY = Ember.META_KEY,
4199
4182
  watch = Ember.watch,
4200
4183
  unwatch = Ember.unwatch;
4201
4184
 
4185
+
4202
4186
  // ..........................................................
4203
4187
  // DEPENDENT KEYS
4204
4188
  //
@@ -4452,13 +4436,14 @@ ComputedPropertyPrototype.readOnly = function(readOnly) {
4452
4436
  @chainable
4453
4437
  */
4454
4438
  ComputedPropertyPrototype.property = function() {
4455
- function addArg(arg) {
4456
- args.push(arg);
4457
- }
4439
+ var addArg;
4458
4440
 
4441
+
4459
4442
  var args = [];
4460
4443
  for (var i = 0, l = arguments.length; i < l; i++) {
4461
- expandProperties(arguments[i], addArg);
4444
+
4445
+ args.push(arguments[i]);
4446
+
4462
4447
  }
4463
4448
  this._dependentKeys = args;
4464
4449
  return this;
@@ -5312,8 +5297,8 @@ Ember.computed.defaultTo = function(defaultPath) {
5312
5297
  */
5313
5298
 
5314
5299
  var AFTER_OBSERVERS = ':change',
5315
- BEFORE_OBSERVERS = ':before',
5316
- expandProperties = Ember.expandProperties;
5300
+ BEFORE_OBSERVERS = ':before';
5301
+
5317
5302
 
5318
5303
  function changeEvent(keyName) {
5319
5304
  return keyName+AFTER_OBSERVERS;
@@ -5331,10 +5316,10 @@ function beforeEvent(keyName) {
5331
5316
  @param {Function|String} [method]
5332
5317
  */
5333
5318
  Ember.addObserver = function(obj, _path, target, method) {
5334
- expandProperties(_path, function (path) {
5335
- Ember.addListener(obj, changeEvent(path), target, method);
5336
- Ember.watch(obj, path);
5337
- });
5319
+
5320
+ Ember.addListener(obj, changeEvent(_path), target, method);
5321
+ Ember.watch(obj, _path);
5322
+
5338
5323
 
5339
5324
  return this;
5340
5325
  };
@@ -5351,10 +5336,10 @@ Ember.observersFor = function(obj, path) {
5351
5336
  @param {Function|String} [method]
5352
5337
  */
5353
5338
  Ember.removeObserver = function(obj, _path, target, method) {
5354
- expandProperties(_path, function (path) {
5355
- Ember.unwatch(obj, path);
5356
- Ember.removeListener(obj, changeEvent(path), target, method);
5357
- });
5339
+
5340
+ Ember.unwatch(obj, _path);
5341
+ Ember.removeListener(obj, changeEvent(_path), target, method);
5342
+
5358
5343
  return this;
5359
5344
  };
5360
5345
 
@@ -5366,10 +5351,10 @@ Ember.removeObserver = function(obj, _path, target, method) {
5366
5351
  @param {Function|String} [method]
5367
5352
  */
5368
5353
  Ember.addBeforeObserver = function(obj, _path, target, method) {
5369
- expandProperties(_path, function (path) {
5370
- Ember.addListener(obj, beforeEvent(path), target, method);
5371
- Ember.watch(obj, path);
5372
- });
5354
+
5355
+ Ember.addListener(obj, beforeEvent(_path), target, method);
5356
+ Ember.watch(obj, _path);
5357
+
5373
5358
  return this;
5374
5359
  };
5375
5360
 
@@ -5409,10 +5394,10 @@ Ember.beforeObserversFor = function(obj, path) {
5409
5394
  @param {Function|String} [method]
5410
5395
  */
5411
5396
  Ember.removeBeforeObserver = function(obj, _path, target, method) {
5412
- expandProperties(_path, function (path) {
5413
- Ember.unwatch(obj, path);
5414
- Ember.removeListener(obj, beforeEvent(path), target, method);
5415
- });
5397
+
5398
+ Ember.unwatch(obj, _path);
5399
+ Ember.removeListener(obj, beforeEvent(_path), target, method);
5400
+
5416
5401
  return this;
5417
5402
  };
5418
5403
 
@@ -7158,9 +7143,7 @@ function applyConcatenatedProperties(obj, key, value, values) {
7158
7143
  return Ember.makeArray(baseValue).concat(value);
7159
7144
  }
7160
7145
  } else {
7161
- // Make sure this mixin has its own array so it is not
7162
- // accidentally mutated by another child's interactions
7163
- return Ember.makeArray(value).slice();
7146
+ return Ember.makeArray(value);
7164
7147
  }
7165
7148
  }
7166
7149
 
@@ -11210,6 +11193,11 @@ function DependentArraysObserver(callbacks, cp, instanceMeta, context, propertyN
11210
11193
  // this to lazily recompute indexes for item property observers.
11211
11194
  this.trackedArraysByGuid = {};
11212
11195
 
11196
+ // We suspend observers to ignore replacements from `reset` when totally
11197
+ // recomputing. Unfortunately we cannot properly suspend the observers
11198
+ // because we only have the key; instead we make the observers no-ops
11199
+ this.suspended = false;
11200
+
11213
11201
  // This is used to coalesce item changes from property observers.
11214
11202
  this.changedItems = {};
11215
11203
  }
@@ -11263,6 +11251,13 @@ DependentArraysObserver.prototype = {
11263
11251
  });
11264
11252
  },
11265
11253
 
11254
+ suspendArrayObservers: function (callback, binding) {
11255
+ var oldSuspended = this.suspended;
11256
+ this.suspended = true;
11257
+ callback.call(binding);
11258
+ this.suspended = oldSuspended;
11259
+ },
11260
+
11266
11261
  setupPropertyObservers: function (dependentKey, itemPropertyKeys) {
11267
11262
  var dependentArray = get(this.instanceMeta.context, dependentKey),
11268
11263
  length = get(dependentArray, 'length'),
@@ -11368,19 +11363,22 @@ DependentArraysObserver.prototype = {
11368
11363
  },
11369
11364
 
11370
11365
  dependentArrayWillChange: function (dependentArray, index, removedCount, addedCount) {
11366
+ if (this.suspended) { return; }
11367
+
11371
11368
  var removedItem = this.callbacks.removedItem,
11372
11369
  changeMeta,
11373
11370
  guid = guidFor(dependentArray),
11374
11371
  dependentKey = this.dependentKeysByGuid[guid],
11375
11372
  itemPropertyKeys = this.cp._itemPropertyKeys[dependentKey] || [],
11376
11373
  length = get(dependentArray, 'length'),
11377
- normalizedIndex = normalizeIndex(length, index, 1),
11374
+ normalizedIndex = normalizeIndex(index, length, 0),
11375
+ normalizedRemoveCount = normalizeRemoveCount(normalizedIndex, length, removedCount),
11378
11376
  item,
11379
11377
  itemIndex,
11380
11378
  sliceIndex,
11381
11379
  observerContexts;
11382
11380
 
11383
- observerContexts = this.trackRemove(dependentKey, normalizedIndex, removedCount);
11381
+ observerContexts = this.trackRemove(dependentKey, normalizedIndex, normalizedRemoveCount);
11384
11382
 
11385
11383
  function removeObservers(propertyKey) {
11386
11384
  observerContexts[sliceIndex].destroyed = true;
@@ -11388,7 +11386,7 @@ DependentArraysObserver.prototype = {
11388
11386
  removeObserver(item, propertyKey, this, observerContexts[sliceIndex].observer);
11389
11387
  }
11390
11388
 
11391
- for (sliceIndex = removedCount - 1; sliceIndex >= 0; --sliceIndex) {
11389
+ for (sliceIndex = normalizedRemoveCount - 1; sliceIndex >= 0; --sliceIndex) {
11392
11390
  itemIndex = normalizedIndex + sliceIndex;
11393
11391
  if (itemIndex >= length) { break; }
11394
11392
 
@@ -11403,13 +11401,15 @@ DependentArraysObserver.prototype = {
11403
11401
  },
11404
11402
 
11405
11403
  dependentArrayDidChange: function (dependentArray, index, removedCount, addedCount) {
11404
+ if (this.suspended) { return; }
11405
+
11406
11406
  var addedItem = this.callbacks.addedItem,
11407
11407
  guid = guidFor(dependentArray),
11408
11408
  dependentKey = this.dependentKeysByGuid[guid],
11409
11409
  observerContexts = new Array(addedCount),
11410
11410
  itemPropertyKeys = this.cp._itemPropertyKeys[dependentKey],
11411
11411
  length = get(dependentArray, 'length'),
11412
- normalizedIndex = normalizeIndex(length, index, addedCount),
11412
+ normalizedIndex = normalizeIndex(index, length, addedCount),
11413
11413
  changeMeta,
11414
11414
  observerContext;
11415
11415
 
@@ -11470,7 +11470,7 @@ DependentArraysObserver.prototype = {
11470
11470
  }
11471
11471
  };
11472
11472
 
11473
- function normalizeIndex(length, index, newItemsOffset) {
11473
+ function normalizeIndex(index, length, newItemsOffset) {
11474
11474
  if (index < 0) {
11475
11475
  return Math.max(0, length + index);
11476
11476
  } else if (index < length) {
@@ -11480,6 +11480,10 @@ function normalizeIndex(length, index, newItemsOffset) {
11480
11480
  }
11481
11481
  }
11482
11482
 
11483
+ function normalizeRemoveCount(index, length, removedCount) {
11484
+ return Math.min(removedCount, length - index);
11485
+ }
11486
+
11483
11487
  function createChangeMeta(dependentArray, item, index, propertyName, property, previousValues) {
11484
11488
  var meta = {
11485
11489
  arrayChanged: dependentArray,
@@ -11598,30 +11602,32 @@ function ReduceComputedProperty(options) {
11598
11602
 
11599
11603
  reset.call(this, cp, propertyName);
11600
11604
 
11601
- forEach(cp._dependentKeys, function (dependentKey) {
11602
- var dependentArray = get(this, dependentKey),
11603
- previousDependentArray = meta.dependentArrays[dependentKey];
11604
-
11605
- if (dependentArray === previousDependentArray) {
11606
- // The array may be the same, but our item property keys may have
11607
- // changed, so we set them up again. We can't easily tell if they've
11608
- // changed: the array may be the same object, but with different
11609
- // contents.
11610
- if (cp._previousItemPropertyKeys[dependentKey]) {
11611
- delete cp._previousItemPropertyKeys[dependentKey];
11612
- meta.dependentArraysObserver.setupPropertyObservers(dependentKey, cp._itemPropertyKeys[dependentKey]);
11613
- }
11614
- } else {
11615
- meta.dependentArrays[dependentKey] = dependentArray;
11605
+ meta.dependentArraysObserver.suspendArrayObservers(function () {
11606
+ forEach(cp._dependentKeys, function (dependentKey) {
11607
+ var dependentArray = get(this, dependentKey),
11608
+ previousDependentArray = meta.dependentArrays[dependentKey];
11609
+
11610
+ if (dependentArray === previousDependentArray) {
11611
+ // The array may be the same, but our item property keys may have
11612
+ // changed, so we set them up again. We can't easily tell if they've
11613
+ // changed: the array may be the same object, but with different
11614
+ // contents.
11615
+ if (cp._previousItemPropertyKeys[dependentKey]) {
11616
+ delete cp._previousItemPropertyKeys[dependentKey];
11617
+ meta.dependentArraysObserver.setupPropertyObservers(dependentKey, cp._itemPropertyKeys[dependentKey]);
11618
+ }
11619
+ } else {
11620
+ meta.dependentArrays[dependentKey] = dependentArray;
11616
11621
 
11617
- if (previousDependentArray) {
11618
- meta.dependentArraysObserver.teardownObservers(previousDependentArray, dependentKey);
11619
- }
11622
+ if (previousDependentArray) {
11623
+ meta.dependentArraysObserver.teardownObservers(previousDependentArray, dependentKey);
11624
+ }
11620
11625
 
11621
- if (dependentArray) {
11622
- meta.dependentArraysObserver.setupObservers(dependentArray, dependentKey);
11626
+ if (dependentArray) {
11627
+ meta.dependentArraysObserver.setupObservers(dependentArray, dependentKey);
11628
+ }
11623
11629
  }
11624
- }
11630
+ }, this);
11625
11631
  }, this);
11626
11632
 
11627
11633
  forEach(cp._dependentKeys, function(dependentKey) {
@@ -15680,7 +15686,10 @@ function makeCtor() {
15680
15686
 
15681
15687
  Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin));
15682
15688
 
15683
- if (Ember.typeOf(properties) !== 'object') { continue; }
15689
+ if (properties === null || typeof properties !== 'object') {
15690
+ Ember.assert("Ember.Object.create only accepts objects.");
15691
+ continue;
15692
+ }
15684
15693
 
15685
15694
  var keyNames = Ember.keys(properties);
15686
15695
  for (var j = 0, ll = keyNames.length; j < ll; j++) {
@@ -15872,7 +15881,7 @@ CoreObject.PrototypeMixin = Mixin.create({
15872
15881
  This feature is available for you to use throughout the Ember object model,
15873
15882
  although typical app developers are likely to use it infrequently. Since
15874
15883
  it changes expectations about behavior of properties, you should properly
15875
- document its usage in each individual concatenated property (to not
15884
+ document its usage in each individual concatenated property (to not
15876
15885
  mislead your users to think they can override the property in a subclass).
15877
15886
 
15878
15887
  @property concatenatedProperties
@@ -16173,10 +16182,10 @@ var ClassMixin = Mixin.create({
16173
16182
  },
16174
16183
 
16175
16184
  /**
16176
-
16185
+
16177
16186
  Augments a constructor's prototype with additional
16178
16187
  properties and functions:
16179
-
16188
+
16180
16189
  ```javascript
16181
16190
  MyObject = Ember.Object.extend({
16182
16191
  name: 'an object'
@@ -16196,7 +16205,7 @@ var ClassMixin = Mixin.create({
16196
16205
 
16197
16206
  o.say("goodbye"); // logs "goodbye"
16198
16207
  ```
16199
-
16208
+
16200
16209
  To add functions and properties to the constructor itself,
16201
16210
  see `reopenClass`
16202
16211
 
@@ -16210,7 +16219,7 @@ var ClassMixin = Mixin.create({
16210
16219
 
16211
16220
  /**
16212
16221
  Augments a constructor's own properties and functions:
16213
-
16222
+
16214
16223
  ```javascript
16215
16224
  MyObject = Ember.Object.extend({
16216
16225
  name: 'an object'
@@ -16220,12 +16229,12 @@ var ClassMixin = Mixin.create({
16220
16229
  MyObject.reopenClass({
16221
16230
  canBuild: false
16222
16231
  });
16223
-
16232
+
16224
16233
  MyObject.canBuild; // false
16225
16234
  o = MyObject.create();
16226
16235
  ```
16227
16236
 
16228
- In other words, this creates static properties and functions for the class. These are only available on the class
16237
+ In other words, this creates static properties and functions for the class. These are only available on the class
16229
16238
  and not on any instance of that class.
16230
16239
 
16231
16240
  ```javascript
@@ -16255,15 +16264,15 @@ var ClassMixin = Mixin.create({
16255
16264
  alert(App.Person.species); // "Homo sapiens"
16256
16265
  ```
16257
16266
 
16258
- Note that `species` and `createPerson` are *not* valid on the `tom` and `yehuda`
16267
+ Note that `species` and `createPerson` are *not* valid on the `tom` and `yehuda`
16259
16268
  variables. They are only valid on `App.Person`.
16260
-
16269
+
16261
16270
  To add functions and properties to instances of
16262
16271
  a constructor by extending the constructor's prototype
16263
16272
  see `reopen`
16264
-
16273
+
16265
16274
  @method reopenClass
16266
- */
16275
+ */
16267
16276
  reopenClass: function() {
16268
16277
  reopen.apply(this.ClassMixin, arguments);
16269
16278
  applyMixin(this, arguments, false);