From b8ef428c57505832f3be33c61cb87ef1253d0a70 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Sun, 14 Jun 2015 17:17:12 -0400 Subject: [PATCH] =?UTF-8?q?[CLEANUP=20Beta]=20=20=20(=E2=95=AF=C2=B0?= =?UTF-8?q?=E2=96=A1=C2=B0=EF=BC=89=E2=95=AF=EF=B8=B5=20p=C7=9D=C9=B9?= =?UTF-8?q?=C9=B9=C7=9D=C9=9F=C7=9Dp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove Ember.Deferred & Ember.DeferredMixin --- .../lib/system/application.js | 5 +- packages/ember-runtime/lib/main.js | 7 - packages/ember-runtime/lib/mixins/deferred.js | 79 ---- packages/ember-runtime/lib/system/deferred.js | 20 - .../tests/mixins/deferred_test.js | 367 ------------------ .../tests/system/deferred_test.js | 38 -- 6 files changed, 1 insertion(+), 515 deletions(-) delete mode 100644 packages/ember-runtime/lib/mixins/deferred.js delete mode 100644 packages/ember-runtime/lib/system/deferred.js delete mode 100644 packages/ember-runtime/tests/mixins/deferred_test.js delete mode 100644 packages/ember-runtime/tests/system/deferred_test.js diff --git a/packages/ember-application/lib/system/application.js b/packages/ember-application/lib/system/application.js index 0156e5fe9f5..d7099eaca72 100644 --- a/packages/ember-application/lib/system/application.js +++ b/packages/ember-application/lib/system/application.js @@ -11,7 +11,6 @@ import { get } from "ember-metal/property_get"; import { set } from "ember-metal/property_set"; import { runLoadHooks } from "ember-runtime/system/lazy_load"; import Namespace from "ember-runtime/system/namespace"; -import DeferredMixin from "ember-runtime/mixins/deferred"; import DefaultResolver from "ember-application/system/resolver"; import create from "ember-metal/platform/create"; import run from "ember-metal/run_loop"; @@ -199,7 +198,7 @@ var librariesRegistered = false; @public */ -var Application = Namespace.extend(DeferredMixin, { +var Application = Namespace.extend({ _suppressDeferredDeprecation: true, /** @@ -738,8 +737,6 @@ var Application = Namespace.extend(DeferredMixin, { Ember.Namespace.processAll(); Ember.BOOTED = true; } - - this.resolve(this); } this._bootResolver.resolve(); diff --git a/packages/ember-runtime/lib/main.js b/packages/ember-runtime/lib/main.js index d0a99f32e13..333593780b9 100644 --- a/packages/ember-runtime/lib/main.js +++ b/packages/ember-runtime/lib/main.js @@ -20,9 +20,7 @@ import ObjectProxy from 'ember-runtime/system/object_proxy'; import CoreObject from 'ember-runtime/system/core_object'; import NativeArray from 'ember-runtime/system/native_array'; -import Set from 'ember-runtime/system/set'; import EmberStringUtils from 'ember-runtime/system/string'; -import Deferred from 'ember-runtime/system/deferred'; import { onLoad, runLoadHooks @@ -40,7 +38,6 @@ import _ProxyMixin from 'ember-runtime/mixins/-proxy'; import Observable from 'ember-runtime/mixins/observable'; import ActionHandler from 'ember-runtime/mixins/action_handler'; -import DeferredMixin from 'ember-runtime/mixins/deferred'; import MutableEnumerable from 'ember-runtime/mixins/mutable_enumerable'; import MutableArray from 'ember-runtime/mixins/mutable_array'; import TargetActionSupport from 'ember-runtime/mixins/target_action_support'; @@ -105,8 +102,6 @@ Ember.SortableMixin = SortableMixin; Ember.Freezable = Freezable; Ember.FROZEN_ERROR = FROZEN_ERROR; -Ember.DeferredMixin = DeferredMixin; - Ember.MutableEnumerable = MutableEnumerable; Ember.MutableArray = MutableArray; @@ -158,8 +153,6 @@ Ember.CoreObject = CoreObject; Ember.NativeArray = NativeArray; // ES6TODO: Currently we must rely on the global from ember-metal/core to avoid circular deps // Ember.A = A; -Ember.Set = Set; -Ember.Deferred = Deferred; Ember.onLoad = onLoad; Ember.runLoadHooks = runLoadHooks; diff --git a/packages/ember-runtime/lib/mixins/deferred.js b/packages/ember-runtime/lib/mixins/deferred.js deleted file mode 100644 index 09efc9c7891..00000000000 --- a/packages/ember-runtime/lib/mixins/deferred.js +++ /dev/null @@ -1,79 +0,0 @@ -import Ember from "ember-metal/core"; // Ember.Test -import { get } from "ember-metal/property_get"; -import { Mixin } from "ember-metal/mixin"; -import { computed } from "ember-metal/computed"; -import RSVP from "ember-runtime/ext/rsvp"; - -/** -@module ember -@submodule ember-runtime -*/ - - -/** - @class Deferred - @namespace Ember - @private -*/ -export default Mixin.create({ - /** - Add handlers to be called when the Deferred object is resolved or rejected. - - @method then - @param {Function} resolve a callback function to be called when done - @param {Function} reject a callback function to be called when failed - @private - */ - then(resolve, reject, label) { - var deferred, promise, entity; - - entity = this; - deferred = get(this, '_deferred'); - promise = deferred.promise; - - function fulfillmentHandler(fulfillment) { - if (fulfillment === promise) { - return resolve(entity); - } else { - return resolve(fulfillment); - } - } - - return promise.then(resolve && fulfillmentHandler, reject, label); - }, - - /** - Resolve a Deferred object and call any `doneCallbacks` with the given args. - - @method resolve - @private - */ - resolve(value) { - var deferred, promise; - - deferred = get(this, '_deferred'); - promise = deferred.promise; - - if (value === this) { - deferred.resolve(promise); - } else { - deferred.resolve(value); - } - }, - - /** - Reject a Deferred object and call any `failCallbacks` with the given args. - - @method reject - @private - */ - reject(value) { - get(this, '_deferred').reject(value); - }, - - _deferred: computed(function() { - Ember.deprecate('Usage of Ember.DeferredMixin or Ember.Deferred is deprecated.', this._suppressDeferredDeprecation, { url: 'http://emberjs.com/guides/deprecations/#toc_deprecate-ember-deferredmixin-and-ember-deferred' }); - - return RSVP.defer('Ember: DeferredMixin - ' + this); - }) -}); diff --git a/packages/ember-runtime/lib/system/deferred.js b/packages/ember-runtime/lib/system/deferred.js deleted file mode 100644 index 83f3d68e493..00000000000 --- a/packages/ember-runtime/lib/system/deferred.js +++ /dev/null @@ -1,20 +0,0 @@ -import Ember from 'ember-metal/core'; -import DeferredMixin from "ember-runtime/mixins/deferred"; -import EmberObject from "ember-runtime/system/object"; - -var Deferred = EmberObject.extend(DeferredMixin, { - init() { - Ember.deprecate('Usage of Ember.Deferred is deprecated.', false, { url: 'http://emberjs.com/guides/deprecations/#toc_deprecate-ember-deferredmixin-and-ember-deferred' }); - this._super(...arguments); - } -}); - -Deferred.reopenClass({ - promise(callback, binding) { - var deferred = Deferred.create(); - callback.call(binding, deferred); - return deferred; - } -}); - -export default Deferred; diff --git a/packages/ember-runtime/tests/mixins/deferred_test.js b/packages/ember-runtime/tests/mixins/deferred_test.js deleted file mode 100644 index 686ead6a241..00000000000 --- a/packages/ember-runtime/tests/mixins/deferred_test.js +++ /dev/null @@ -1,367 +0,0 @@ -/* global EmberDev */ - -import Ember from 'ember-metal/core'; -import run from 'ember-metal/run_loop'; -import EmberObject from 'ember-runtime/system/object'; -import Deferred from "ember-runtime/mixins/deferred"; - -var originalDeprecate; - -QUnit.module("Deferred", { - setup() { - originalDeprecate = Ember.deprecate; - Ember.deprecate = function() { }; - }, - - teardown() { - Ember.deprecate = originalDeprecate; - } -}); - -QUnit.test("can resolve deferred", function() { - var deferred; - var count = 0; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function(a) { - count++; - }); - - run(deferred, 'resolve', deferred); - - equal(count, 1, "was fulfilled"); -}); - -QUnit.test("can reject deferred", function() { - - var deferred; - var count = 0; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(null, function() { - count++; - }); - - run(deferred, 'reject'); - - equal(count, 1, "fail callback was called"); -}); - -QUnit.test("can resolve with then", function() { - - var deferred; - var count1 = 0; - var count2 = 0; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function() { - count1++; - }, function() { - count2++; - }); - - run(deferred, 'resolve', deferred); - - equal(count1, 1, "then were resolved"); - equal(count2, 0, "then was not rejected"); -}); - -QUnit.test("can reject with then", function() { - - var deferred; - var count1 = 0; - var count2 = 0; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function() { - count1++; - }, function() { - count2++; - }); - - run(deferred, 'reject'); - - equal(count1, 0, "then was not resolved"); - equal(count2, 1, "then were rejected"); -}); - -QUnit.test("can call resolve multiple times", function() { - - var deferred; - var count = 0; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function() { - count++; - }); - - run(function() { - deferred.resolve(deferred); - deferred.resolve(deferred); - deferred.resolve(deferred); - }); - - equal(count, 1, "calling resolve multiple times has no effect"); -}); - -QUnit.test("resolve prevent reject", function() { - var deferred; - var resolved = false; - var rejected = false; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function() { - resolved = true; - }, function() { - rejected = true; - }); - - run(deferred, 'resolve', deferred); - run(deferred, 'reject'); - - equal(resolved, true, "is resolved"); - equal(rejected, false, "is not rejected"); -}); - -QUnit.test("reject prevent resolve", function() { - var deferred; - var resolved = false; - var rejected = false; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function() { - resolved = true; - }, function() { - rejected = true; - }); - - run(deferred, 'reject'); - run(deferred, 'reject', deferred); - - equal(resolved, false, "is not resolved"); - equal(rejected, true, "is rejected"); -}); - -QUnit.test("will call callbacks if they are added after resolution", function() { - - var deferred; - var count1 = 0; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - run(deferred, 'resolve', 'toto'); - - run(function() { - deferred.then(function(context) { - if (context === 'toto') { - count1++; - } - }); - - deferred.then(function(context) { - if (context === 'toto') { - count1++; - } - }); - }); - - equal(count1, 2, "callbacks called after resolution"); -}); - -QUnit.test("then is chainable", function() { - var deferred; - var count = 0; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function() { - eval('error'); // Use eval to pass JSHint - }).then(null, function() { - count++; - }); - - run(deferred, 'resolve', deferred); - - equal(count, 1, "chained callback was called"); -}); - - - -QUnit.test("can self fulfill", function() { - expect(1); - var deferred; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function(value) { - equal(value, deferred, "successfully resolved to itself"); - }); - - run(deferred, 'resolve', deferred); -}); - - -QUnit.test("can self reject", function() { - expect(1); - var deferred; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function() { - ok(false, 'should not fulfill'); - }, function(value) { - equal(value, deferred, "successfully rejected to itself"); - }); - - run(deferred, 'reject', deferred); -}); - -QUnit.test("can fulfill to a custom value", function() { - expect(1); - var deferred; - var obj = {}; - - run(function() { - deferred = EmberObject.createWithMixins(Deferred); - }); - - deferred.then(function(value) { - equal(value, obj, "successfully resolved to given value"); - }); - - run(deferred, 'resolve', obj); -}); - - -QUnit.test("can chain self fulfilling objects", function() { - expect(2); - var firstDeferred, secondDeferred; - - run(function() { - firstDeferred = EmberObject.createWithMixins(Deferred); - secondDeferred = EmberObject.createWithMixins(Deferred); - }); - - firstDeferred.then(function(value) { - equal(value, firstDeferred, "successfully resolved to the first deferred"); - return secondDeferred; - }).then(function(value) { - equal(value, secondDeferred, "successfully resolved to the second deferred"); - }); - - run(function() { - firstDeferred.resolve(firstDeferred); - secondDeferred.resolve(secondDeferred); - }); -}); - -QUnit.test("can do multi level assimilation", function() { - expect(1); - var firstDeferred, secondDeferred; - var firstDeferredResolved = false; - - run(function() { - firstDeferred = EmberObject.createWithMixins(Deferred); - secondDeferred = EmberObject.createWithMixins(Deferred); - }); - - firstDeferred.then(function() { - firstDeferredResolved = true; - }); - - secondDeferred.then(function() { - ok(firstDeferredResolved, "first deferred already resolved"); - }); - - run(secondDeferred, 'resolve', firstDeferred); - run(firstDeferred, 'resolve', firstDeferred); -}); - - -QUnit.test("can handle rejection without rejection handler", function() { - expect(2); - - var reason = 'some reason'; - - var deferred = run(function() { - return EmberObject.createWithMixins(Deferred); - }); - - deferred.then().then(function() { - ok(false, 'expected rejection, got fulfillment'); - }, function(actualReason) { - ok(true, 'expected fulfillment'); - equal(actualReason, reason); - }); - - run(deferred, 'reject', reason); -}); - -QUnit.test("can handle fulfillment without fulfillment handler", function() { - expect(2); - - var fulfillment = 'some fulfillment'; - - var deferred = run(function() { - return EmberObject.createWithMixins(Deferred); - }); - - deferred.then().then(function(actualFulfillment) { - ok(true, 'expected fulfillment'); - equal(fulfillment, actualFulfillment); - }, function(reason) { - ok(false, 'expected fulfillment, got reason' + reason); - }); - - run(deferred, 'resolve', fulfillment); -}); - -if (!EmberDev.runningProdBuild) { - QUnit.test("causes a deprecation warning when used", function() { - var deferred, deprecationMade; - var obj = {}; - - Ember.deprecate = function(message) { - deprecationMade = message; - }; - - deferred = EmberObject.createWithMixins(Deferred); - equal(deprecationMade, undefined, 'no deprecation was made on init'); - - deferred.then(function(value) { - equal(value, obj, "successfully resolved to given value"); - }); - equal(deprecationMade, 'Usage of Ember.DeferredMixin or Ember.Deferred is deprecated.'); - - run(deferred, 'resolve', obj); - }); -} diff --git a/packages/ember-runtime/tests/system/deferred_test.js b/packages/ember-runtime/tests/system/deferred_test.js deleted file mode 100644 index 9f93f33751e..00000000000 --- a/packages/ember-runtime/tests/system/deferred_test.js +++ /dev/null @@ -1,38 +0,0 @@ -import run from 'ember-metal/run_loop'; -import Deferred from "ember-runtime/system/deferred"; - -QUnit.module("Ember.Deferred all-in-one"); - -asyncTest("Can resolve a promise", function() { - var value = { value: true }; - - ignoreDeprecation(function() { - var promise = Deferred.promise(function(deferred) { - setTimeout(function() { - run(function() { deferred.resolve(value); }); - }); - }); - - promise.then(function(resolveValue) { - QUnit.start(); - equal(resolveValue, value, "The resolved value should be correct"); - }); - }); -}); - -asyncTest("Can reject a promise", function() { - var rejected = { rejected: true }; - - ignoreDeprecation(function() { - var promise = Deferred.promise(function(deferred) { - setTimeout(function() { - run(function() { deferred.reject(rejected); }); - }); - }); - - promise.then(null, function(rejectedValue) { - QUnit.start(); - equal(rejectedValue, rejected, "The resolved value should be correct"); - }); - }); -});