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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/dist/ember.debug.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * Portions Copyright 2008-2011 Apple Inc. All rights reserved.
7
7
  * @license Licensed under MIT license
8
8
  * See https://raw.github.com/emberjs/ember.js/master/LICENSE
9
- * @version 2.15.0-beta.1
9
+ * @version 2.15.0-beta.2
10
10
  */
11
11
 
12
12
  var enifed, requireModule, Ember;
@@ -8488,7 +8488,6 @@ enifed('@glimmer/util', ['exports'], function (exports) {
8488
8488
 
8489
8489
  // import Logger from './logger';
8490
8490
  // let alreadyWarned = false;
8491
- // import Logger from './logger';
8492
8491
  function debugAssert(test, msg) {
8493
8492
  // if (!alreadyWarned) {
8494
8493
  // alreadyWarned = true;
@@ -12294,7 +12293,7 @@ enifed('ember-application/system/engine-instance', ['exports', 'ember-babel', 'e
12294
12293
 
12295
12294
  var parent = (0, _engineParent.getEngineParent)(this);
12296
12295
 
12297
- var registrations = ['route:basic', 'event_dispatcher:main', 'service:-routing', 'service:-glimmer-environment'];
12296
+ var registrations = ['route:basic', 'service:-routing', 'service:-glimmer-environment'];
12298
12297
 
12299
12298
  registrations.forEach(function (key) {
12300
12299
  return _this2.register(key, parent.resolveRegistration(key));
@@ -12303,7 +12302,7 @@ enifed('ember-application/system/engine-instance', ['exports', 'ember-babel', 'e
12303
12302
  var env = parent.lookup('-environment:main');
12304
12303
  this.register('-environment:main', env, { instantiate: false });
12305
12304
 
12306
- var singletons = ['router:main', (0, _container.privatize)(_templateObject), '-view-registry:main', 'renderer:-' + (env.isInteractive ? 'dom' : 'inert'), 'service:-document'];
12305
+ var singletons = ['router:main', (0, _container.privatize)(_templateObject), '-view-registry:main', 'renderer:-' + (env.isInteractive ? 'dom' : 'inert'), 'service:-document', 'event_dispatcher:main'];
12307
12306
 
12308
12307
  singletons.forEach(function (key) {
12309
12308
  return _this2.register(key, parent.lookup(key), { instantiate: false });
@@ -13485,6 +13484,7 @@ enifed('ember-debug/deprecate', ['exports', 'ember-debug/error', 'ember-console'
13485
13484
  @public
13486
13485
  @static
13487
13486
  @method registerDeprecationHandler
13487
+ @for Ember.Debug
13488
13488
  @param handler {Function} A function to handle deprecation calls.
13489
13489
  @since 2.1.0
13490
13490
  */
@@ -13671,13 +13671,7 @@ enifed("ember-debug/error", ["exports", "ember-babel"], function (exports, _embe
13671
13671
  }
13672
13672
 
13673
13673
  var error = Error.call(_this, message);
13674
-
13675
- if (Error.captureStackTrace) {
13676
- Error.captureStackTrace(_this, EmberError);
13677
- } else {
13678
- _this.stack = error.stack;
13679
- }
13680
-
13674
+ _this.stack = error.stack;
13681
13675
  _this.description = error.description;
13682
13676
  _this.fileName = error.fileName;
13683
13677
  _this.lineNumber = error.lineNumber;
@@ -14148,6 +14142,7 @@ enifed('ember-debug/warn', ['exports', 'ember-console', 'ember-debug/deprecate',
14148
14142
  @public
14149
14143
  @static
14150
14144
  @method registerWarnHandler
14145
+ @for Ember.Debug
14151
14146
  @param handler {Function} A function to handle warnings.
14152
14147
  @since 2.1.0
14153
14148
  */
@@ -16337,6 +16332,34 @@ enifed('ember-glimmer/component', ['exports', 'ember-utils', 'ember-views', 'emb
16337
16332
  See [Ember.Templates.helpers.yield](/api/classes/Ember.Templates.helpers.html#method_yield)
16338
16333
  for more information.
16339
16334
 
16335
+ Layout can be used to wrap content in a component. In addition
16336
+ to wrapping content in a Component's template, you can also use
16337
+ the public layout API in your Component JavaScript.
16338
+
16339
+ ```app/templates/components/person-profile.hbs
16340
+ <h1>Person's Title</h1>
16341
+ <div class='details'>{{yield}}</div>
16342
+ ```
16343
+
16344
+ ```app/components/person-profile.js
16345
+ import Ember from 'ember';
16346
+ import layout from '../templates/components/person-profile';
16347
+
16348
+ export default Ember.Component.extend({
16349
+ layout
16350
+ });
16351
+ ```
16352
+
16353
+ The above will result in the following HTML output:
16354
+
16355
+ ```html
16356
+ <h1>Person's Title</h1>
16357
+ <div class="details">
16358
+ <h2>Chief Basket Weaver</h2>
16359
+ <h3>Fisherman Industries</h3>
16360
+ </div>
16361
+ ```
16362
+
16340
16363
 
16341
16364
  ## Responding to Browser Events
16342
16365
 
@@ -17899,7 +17922,17 @@ enifed('ember-glimmer/helper', ['exports', 'ember-utils', 'ember-runtime', '@gli
17899
17922
  recompute: function () {
17900
17923
  this[RECOMPUTE_TAG].dirty();
17901
17924
  }
17902
- });
17925
+ }
17926
+
17927
+ /**
17928
+ Override this function when writing a class-based helper.
17929
+ @method compute
17930
+ @param {Array} params The positional arguments to the helper
17931
+ @param {Object} hash The named arguments to the helper
17932
+ @public
17933
+ @since 1.13.0
17934
+ */
17935
+ );
17903
17936
 
17904
17937
  Helper.reopenClass({
17905
17938
  isHelperFactory: true
@@ -18790,11 +18823,11 @@ enifed('ember-glimmer/helpers/get', ['exports', 'ember-babel', 'ember-metal', 'e
18790
18823
  }(_references.CachedReference);
18791
18824
  });
18792
18825
  enifed("ember-glimmer/helpers/hash", ["exports"], function (exports) {
18793
- "use strict";
18826
+ "use strict";
18794
18827
 
18795
- exports.default = function (vm, args) {
18796
- return args.named.capture();
18797
- };
18828
+ exports.default = function (vm, args) {
18829
+ return args.named.capture();
18830
+ };
18798
18831
  });
18799
18832
  enifed('ember-glimmer/helpers/if-unless', ['exports', 'ember-babel', 'ember-debug', 'ember-glimmer/utils/references', '@glimmer/reference'], function (exports, _emberBabel, _emberDebug, _references, _reference) {
18800
18833
  'use strict';
@@ -24964,10 +24997,7 @@ enifed('ember-metal', ['exports', 'ember-environment', 'ember-utils', 'ember-deb
24964
24997
  {
24965
24998
  counters.peekCalls++;
24966
24999
  }
24967
- // stop if we find a `null` value, since
24968
- // that means the meta was deleted
24969
- // any other truthy value is a "real" meta
24970
- if (meta === null || meta !== undefined) {
25000
+ if (meta !== undefined) {
24971
25001
  return meta;
24972
25002
  }
24973
25003
 
@@ -24979,14 +25009,10 @@ enifed('ember-metal', ['exports', 'ember-environment', 'ember-utils', 'ember-deb
24979
25009
  };
24980
25010
  } else {
24981
25011
  setMeta = function Fallback_setMeta(obj, meta) {
24982
- // if `null` already, just set it to the new value
24983
- // otherwise define property first
24984
- if (obj[META_FIELD] !== null) {
24985
- if (obj.__defineNonEnumerable) {
24986
- obj.__defineNonEnumerable(EMBER_META_PROPERTY);
24987
- } else {
24988
- Object.defineProperty(obj, META_FIELD, META_DESC);
24989
- }
25012
+ if (obj.__defineNonEnumerable) {
25013
+ obj.__defineNonEnumerable(EMBER_META_PROPERTY);
25014
+ } else {
25015
+ Object.defineProperty(obj, META_FIELD, META_DESC);
24990
25016
  }
24991
25017
 
24992
25018
  obj[META_FIELD] = meta;
@@ -25035,7 +25061,7 @@ enifed('ember-metal', ['exports', 'ember-environment', 'ember-utils', 'ember-deb
25035
25061
  var parent = void 0;
25036
25062
 
25037
25063
  // remove this code, in-favor of explicit parent
25038
- if (maybeMeta !== undefined && maybeMeta !== null) {
25064
+ if (maybeMeta !== undefined) {
25039
25065
  if (maybeMeta.source === obj) {
25040
25066
  return maybeMeta;
25041
25067
  }
@@ -30548,10 +30574,32 @@ enifed('ember-routing/location/history_location', ['exports', 'ember-metal', 'em
30548
30574
  Ember.HistoryLocation implements the location API using the browser's
30549
30575
  history.pushState API.
30550
30576
 
30577
+ Using `HistoryLocation` results in URLs that are indistinguishable from a
30578
+ standard URL. This relies upon the browser's `history` API.
30579
+
30580
+ Example:
30581
+
30582
+ ```javascript
30583
+ App.Router.map(function() {
30584
+ this.route('posts', function() {
30585
+ this.route('new');
30586
+ });
30587
+ });
30588
+
30589
+ App.Router.reopen({
30590
+ location: 'history'
30591
+ });
30592
+ ```
30593
+
30594
+ This will result in a posts.new url of `/posts/new`.
30595
+
30596
+ Keep in mind that your server must serve the Ember app at all the routes you
30597
+ define.
30598
+
30551
30599
  @class HistoryLocation
30552
30600
  @namespace Ember
30553
30601
  @extends Ember.Object
30554
- @private
30602
+ @protected
30555
30603
  */
30556
30604
  exports.default = _emberRuntime.Object.extend({
30557
30605
  implementation: 'history',
@@ -37559,17 +37607,29 @@ enifed('ember-runtime/mixins/array', ['exports', 'ember-utils', 'ember-metal', '
37559
37607
 
37560
37608
  var meta = (0, _emberMetal.peekMeta)(array);
37561
37609
  var cache = meta && meta.readableCache();
37610
+ if (cache !== undefined) {
37611
+ var length = (0, _emberMetal.get)(array, 'length');
37612
+ var addedAmount = addAmt === -1 ? 0 : addAmt;
37613
+ var removedAmount = removeAmt === -1 ? 0 : removeAmt;
37614
+ var delta = addedAmount - removedAmount;
37615
+ var previousLength = length - delta;
37562
37616
 
37563
- if (cache) {
37564
- if (cache.firstObject !== undefined && objectAt(array, 0) !== _emberMetal.cacheFor.get(cache, 'firstObject')) {
37565
- (0, _emberMetal.propertyWillChange)(array, 'firstObject', meta);
37566
- (0, _emberMetal.propertyDidChange)(array, 'firstObject', meta);
37617
+ var normalStartIdx = startIdx < 0 ? previousLength + startIdx : startIdx;
37618
+ if (cache.firstObject !== undefined && normalStartIdx === 0) {
37619
+ (0, _emberMetal.propertyWillChange)(array, 'firstObject');
37620
+ (0, _emberMetal.propertyDidChange)(array, 'firstObject');
37567
37621
  }
37568
- if (cache.lastObject !== undefined && objectAt(array, (0, _emberMetal.get)(array, 'length') - 1) !== _emberMetal.cacheFor.get(cache, 'lastObject')) {
37569
- (0, _emberMetal.propertyWillChange)(array, 'lastObject', meta);
37570
- (0, _emberMetal.propertyDidChange)(array, 'lastObject', meta);
37622
+
37623
+ if (cache.lastObject !== undefined) {
37624
+ var previousLastIndex = previousLength - 1;
37625
+ var lastAffectedIndex = normalStartIdx + removedAmount;
37626
+ if (previousLastIndex < lastAffectedIndex) {
37627
+ (0, _emberMetal.propertyWillChange)(array, 'lastObject');
37628
+ (0, _emberMetal.propertyDidChange)(array, 'lastObject');
37629
+ }
37571
37630
  }
37572
37631
  }
37632
+
37573
37633
  return array;
37574
37634
  }
37575
37635
 
@@ -37761,7 +37821,7 @@ enifed('ember-runtime/mixins/array', ['exports', 'ember-utils', 'ember-metal', '
37761
37821
  function EachProxy(content) {
37762
37822
  this._content = content;
37763
37823
  this._keys = undefined;
37764
- this.__ember_meta__ = null;
37824
+ (0, _emberMetal.meta)(this);
37765
37825
  }
37766
37826
 
37767
37827
  EachProxy.prototype = {
@@ -44796,16 +44856,18 @@ enifed('ember-testing/test/promise', ['exports', 'ember-babel', 'ember-runtime',
44796
44856
  return _this;
44797
44857
  }
44798
44858
 
44799
- TestPromise.prototype.then = function then(onFulfillment) {
44859
+ TestPromise.prototype.then = function then(_onFulfillment) {
44800
44860
  var _RSVP$Promise$prototy;
44801
44861
 
44862
+ var onFulfillment = typeof _onFulfillment === 'function' ? function (result) {
44863
+ return isolate(_onFulfillment, result);
44864
+ } : undefined;
44865
+
44802
44866
  for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
44803
44867
  args[_key - 1] = arguments[_key];
44804
44868
  }
44805
44869
 
44806
- return (_RSVP$Promise$prototy = _RSVP$Promise.prototype.then).call.apply(_RSVP$Promise$prototy, [this, function (result) {
44807
- return isolate(onFulfillment, result);
44808
- }].concat(args));
44870
+ return (_RSVP$Promise$prototy = _RSVP$Promise.prototype.then).call.apply(_RSVP$Promise$prototy, [this, onFulfillment].concat(args));
44809
44871
  };
44810
44872
 
44811
44873
  return TestPromise;
@@ -48121,12 +48183,12 @@ enifed('ember/index', ['exports', 'require', 'ember-environment', 'node-module',
48121
48183
  enifed("ember/version", ["exports"], function (exports) {
48122
48184
  "use strict";
48123
48185
 
48124
- exports.default = "2.15.0-beta.1";
48186
+ exports.default = "2.15.0-beta.2";
48125
48187
  });
48126
48188
  enifed("handlebars", ["exports"], function (exports) {
48127
48189
  "use strict";
48128
48190
 
48129
- /* istanbul ignore next */
48191
+ // File ignored in coverage tests via setting in .istanbul.yml
48130
48192
  /* Jison generated parser */
48131
48193
  var handlebars = function () {
48132
48194
  var parser = { trace: function trace() {},
@@ -48889,7 +48951,10 @@ enifed("handlebars", ["exports"], function (exports) {
48889
48951
  // Work around issue under safari where we can't directly set the column value
48890
48952
  /* istanbul ignore next */
48891
48953
  if (Object.defineProperty) {
48892
- Object.defineProperty(this, 'column', { value: column });
48954
+ Object.defineProperty(this, 'column', {
48955
+ value: column,
48956
+ enumerable: true
48957
+ });
48893
48958
  } else {
48894
48959
  this.column = column;
48895
48960
  }
@@ -52924,100 +52989,106 @@ enifed('rsvp', ['exports', 'ember-babel', 'node-module'], function (exports, _em
52924
52989
  return child;
52925
52990
  }
52926
52991
 
52927
- function Enumerator(Constructor, input, abortOnReject, label) {
52928
- this._instanceConstructor = Constructor;
52929
- this.promise = new Constructor(noop, label);
52930
- this._abortOnReject = abortOnReject;
52931
-
52932
- this._init.apply(this, arguments);
52933
- }
52992
+ var Enumerator = function () {
52993
+ function Enumerator(Constructor, input, abortOnReject, label) {
52994
+ (0, _emberBabel.classCallCheck)(this, Enumerator);
52934
52995
 
52935
- Enumerator.prototype._init = function (Constructor, input) {
52936
- var len = input.length || 0;
52937
- this.length = len;
52938
- this._remaining = len;
52939
- this._result = new Array(len);
52996
+ this._instanceConstructor = Constructor;
52997
+ this.promise = new Constructor(noop, label);
52998
+ this._abortOnReject = abortOnReject;
52940
52999
 
52941
- this._enumerate(input);
52942
- if (this._remaining === 0) {
52943
- fulfill(this.promise, this._result);
53000
+ this._init.apply(this, arguments);
52944
53001
  }
52945
- };
52946
-
52947
- Enumerator.prototype._enumerate = function (input) {
52948
- var length = this.length;
52949
- var promise = this.promise;
52950
53002
 
52951
- for (var i = 0; promise._state === PENDING && i < length; i++) {
52952
- this._eachEntry(input[i], i);
52953
- }
52954
- };
53003
+ Enumerator.prototype._init = function _init(Constructor, input) {
53004
+ var len = input.length || 0;
53005
+ this.length = len;
53006
+ this._remaining = len;
53007
+ this._result = new Array(len);
52955
53008
 
52956
- Enumerator.prototype._settleMaybeThenable = function (entry, i) {
52957
- var c = this._instanceConstructor;
52958
- var resolve$$1 = c.resolve;
53009
+ this._enumerate(input);
53010
+ if (this._remaining === 0) {
53011
+ fulfill(this.promise, this._result);
53012
+ }
53013
+ };
52959
53014
 
52960
- if (resolve$$1 === resolve$1) {
52961
- var then$$1 = getThen(entry);
53015
+ Enumerator.prototype._enumerate = function _enumerate(input) {
53016
+ var length = this.length;
53017
+ var promise = this.promise;
52962
53018
 
52963
- if (then$$1 === then && entry._state !== PENDING) {
52964
- entry._onError = null;
52965
- this._settledAt(entry._state, i, entry._result);
52966
- } else if (typeof then$$1 !== 'function') {
52967
- this._remaining--;
52968
- this._result[i] = this._makeResult(FULFILLED, i, entry);
52969
- } else if (c === Promise) {
52970
- var promise = new c(noop);
52971
- handleMaybeThenable(promise, entry, then$$1);
52972
- this._willSettleAt(promise, i);
52973
- } else {
52974
- this._willSettleAt(new c(function (resolve$$1) {
52975
- return resolve$$1(entry);
52976
- }), i);
53019
+ for (var i = 0; promise._state === PENDING && i < length; i++) {
53020
+ this._eachEntry(input[i], i);
52977
53021
  }
52978
- } else {
52979
- this._willSettleAt(resolve$$1(entry), i);
52980
- }
52981
- };
53022
+ };
52982
53023
 
52983
- Enumerator.prototype._eachEntry = function (entry, i) {
52984
- if (isMaybeThenable(entry)) {
52985
- this._settleMaybeThenable(entry, i);
52986
- } else {
52987
- this._remaining--;
52988
- this._result[i] = this._makeResult(FULFILLED, i, entry);
52989
- }
52990
- };
53024
+ Enumerator.prototype._settleMaybeThenable = function _settleMaybeThenable(entry, i) {
53025
+ var c = this._instanceConstructor;
53026
+ var resolve$$1 = c.resolve;
52991
53027
 
52992
- Enumerator.prototype._settledAt = function (state, i, value) {
52993
- var promise = this.promise;
53028
+ if (resolve$$1 === resolve$1) {
53029
+ var then$$1 = getThen(entry);
52994
53030
 
52995
- if (promise._state === PENDING) {
52996
- if (this._abortOnReject && state === REJECTED) {
52997
- reject(promise, value);
53031
+ if (then$$1 === then && entry._state !== PENDING) {
53032
+ entry._onError = null;
53033
+ this._settledAt(entry._state, i, entry._result);
53034
+ } else if (typeof then$$1 !== 'function') {
53035
+ this._remaining--;
53036
+ this._result[i] = this._makeResult(FULFILLED, i, entry);
53037
+ } else if (c === Promise) {
53038
+ var promise = new c(noop);
53039
+ handleMaybeThenable(promise, entry, then$$1);
53040
+ this._willSettleAt(promise, i);
53041
+ } else {
53042
+ this._willSettleAt(new c(function (resolve$$1) {
53043
+ return resolve$$1(entry);
53044
+ }), i);
53045
+ }
53046
+ } else {
53047
+ this._willSettleAt(resolve$$1(entry), i);
53048
+ }
53049
+ };
53050
+
53051
+ Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {
53052
+ if (isMaybeThenable(entry)) {
53053
+ this._settleMaybeThenable(entry, i);
52998
53054
  } else {
52999
53055
  this._remaining--;
53000
- this._result[i] = this._makeResult(state, i, value);
53001
- if (this._remaining === 0) {
53002
- fulfill(promise, this._result);
53056
+ this._result[i] = this._makeResult(FULFILLED, i, entry);
53057
+ }
53058
+ };
53059
+
53060
+ Enumerator.prototype._settledAt = function _settledAt(state, i, value) {
53061
+ var promise = this.promise;
53062
+
53063
+ if (promise._state === PENDING) {
53064
+ if (this._abortOnReject && state === REJECTED) {
53065
+ reject(promise, value);
53066
+ } else {
53067
+ this._remaining--;
53068
+ this._result[i] = this._makeResult(state, i, value);
53069
+ if (this._remaining === 0) {
53070
+ fulfill(promise, this._result);
53071
+ }
53003
53072
  }
53004
53073
  }
53005
- }
53006
- };
53074
+ };
53007
53075
 
53008
- Enumerator.prototype._makeResult = function (state, i, value) {
53009
- return value;
53010
- };
53076
+ Enumerator.prototype._makeResult = function _makeResult(state, i, value) {
53077
+ return value;
53078
+ };
53011
53079
 
53012
- Enumerator.prototype._willSettleAt = function (promise, i) {
53013
- var enumerator = this;
53080
+ Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {
53081
+ var enumerator = this;
53014
53082
 
53015
- subscribe(promise, undefined, function (value) {
53016
- return enumerator._settledAt(FULFILLED, i, value);
53017
- }, function (reason) {
53018
- return enumerator._settledAt(REJECTED, i, reason);
53019
- });
53020
- };
53083
+ subscribe(promise, undefined, function (value) {
53084
+ return enumerator._settledAt(FULFILLED, i, value);
53085
+ }, function (reason) {
53086
+ return enumerator._settledAt(REJECTED, i, reason);
53087
+ });
53088
+ };
53089
+
53090
+ return Enumerator;
53091
+ }();
53021
53092
 
53022
53093
  function makeSettledResult(state, position, value) {
53023
53094
  if (state === FULFILLED) {
@@ -53333,117 +53404,56 @@ enifed('rsvp', ['exports', 'ember-babel', 'node-module'], function (exports, _em
53333
53404
  Useful for tooling.
53334
53405
  @constructor
53335
53406
  */
53336
- function Promise(resolver, label) {
53337
- this._id = counter++;
53338
- this._label = label;
53339
- this._state = undefined;
53340
- this._result = undefined;
53341
- this._subscribers = [];
53342
53407
 
53343
- config.instrument && instrument('created', this);
53408
+ var Promise = function () {
53409
+ function Promise(resolver, label) {
53410
+ (0, _emberBabel.classCallCheck)(this, Promise);
53344
53411
 
53345
- if (noop !== resolver) {
53346
- typeof resolver !== 'function' && needsResolver();
53347
- this instanceof Promise ? initializePromise(this, resolver) : needsNew();
53348
- }
53349
- }
53412
+ this._id = counter++;
53413
+ this._label = label;
53414
+ this._state = undefined;
53415
+ this._result = undefined;
53416
+ this._subscribers = [];
53350
53417
 
53351
- Promise.prototype._onError = function (reason) {
53352
- var _this = this;
53418
+ config.instrument && instrument('created', this);
53353
53419
 
53354
- config.after(function () {
53355
- if (_this._onError) {
53356
- config.trigger('error', reason, _this._label);
53420
+ if (noop !== resolver) {
53421
+ typeof resolver !== 'function' && needsResolver();
53422
+ this instanceof Promise ? initializePromise(this, resolver) : needsNew();
53357
53423
  }
53358
- });
53359
- };
53360
-
53361
- /**
53362
- `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
53363
- as the catch block of a try/catch statement.
53364
-
53365
- ```js
53366
- function findAuthor(){
53367
- throw new Error('couldn\'t find that author');
53368
53424
  }
53369
-
53370
- // synchronous
53371
- try {
53372
- findAuthor();
53373
- } catch(reason) {
53374
- // something went wrong
53375
- }
53376
-
53377
- // async with promises
53378
- findAuthor().catch(function(reason){
53379
- // something went wrong
53380
- });
53381
- ```
53382
-
53383
- @method catch
53384
- @param {Function} onRejection
53385
- @param {String} label optional string for labeling the promise.
53386
- Useful for tooling.
53387
- @return {Promise}
53388
- */
53389
- Promise.prototype.catch = function (onRejection, label) {
53390
- return this.then(undefined, onRejection, label);
53391
- };
53392
53425
 
53393
- /**
53394
- `finally` will be invoked regardless of the promise's fate just as native
53395
- try/catch/finally behaves
53396
-
53397
- Synchronous example:
53398
-
53399
- ```js
53400
- findAuthor() {
53401
- if (Math.random() > 0.5) {
53402
- throw new Error();
53403
- }
53404
- return new Author();
53405
- }
53406
-
53407
- try {
53408
- return findAuthor(); // succeed or fail
53409
- } catch(error) {
53410
- return findOtherAuthor();
53411
- } finally {
53412
- // always runs
53413
- // doesn't affect the return value
53414
- }
53415
- ```
53416
-
53417
- Asynchronous example:
53418
-
53419
- ```js
53420
- findAuthor().catch(function(reason){
53421
- return findOtherAuthor();
53422
- }).finally(function(){
53423
- // author was either found, or not
53424
- });
53425
- ```
53426
-
53427
- @method finally
53428
- @param {Function} callback
53429
- @param {String} label optional string for labeling the promise.
53430
- Useful for tooling.
53431
- @return {Promise}
53432
- */
53433
- Promise.prototype.finally = function (callback, label) {
53434
- var promise = this;
53435
- var constructor = promise.constructor;
53426
+ Promise.prototype._onError = function _onError(reason) {
53427
+ var _this = this;
53436
53428
 
53437
- return promise.then(function (value) {
53438
- return constructor.resolve(callback()).then(function () {
53439
- return value;
53440
- });
53441
- }, function (reason) {
53442
- return constructor.resolve(callback()).then(function () {
53443
- throw reason;
53429
+ config.after(function () {
53430
+ if (_this._onError) {
53431
+ config.trigger('error', reason, _this._label);
53432
+ }
53444
53433
  });
53445
- }, label);
53446
- };
53434
+ };
53435
+
53436
+ Promise.prototype.catch = function _catch(onRejection, label) {
53437
+ return this.then(undefined, onRejection, label);
53438
+ };
53439
+
53440
+ Promise.prototype.finally = function _finally(callback, label) {
53441
+ var promise = this;
53442
+ var constructor = promise.constructor;
53443
+
53444
+ return promise.then(function (value) {
53445
+ return constructor.resolve(callback()).then(function () {
53446
+ return value;
53447
+ });
53448
+ }, function (reason) {
53449
+ return constructor.resolve(callback()).then(function () {
53450
+ throw reason;
53451
+ });
53452
+ }, label);
53453
+ };
53454
+
53455
+ return Promise;
53456
+ }();
53447
53457
 
53448
53458
  Promise.cast = resolve$1; // deprecated
53449
53459
  Promise.all = all;