Commit b2adfc96 authored by Romain Courteaud's avatar Romain Courteaud

Remove notification support.

This functionnality has never been used.

Revert "Queue notifications are now enabled"
This reverts commit 58953a31.

Revert "notifications are not propagated to parents fixed"
This reverts commit 41eba17a.

Revert "add notifier to `all` and `any`"
This reverts commit 34a4233b.

Revert "Add Promise progress"
This reverts commit a79070b4.
parent 70a3e64c
...@@ -19,7 +19,7 @@ function promiseAtLeast(expected_count, promises) { ...@@ -19,7 +19,7 @@ function promiseAtLeast(expected_count, promises) {
} }
} }
return new Promise(function(resolve, reject, notify) { return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length, var results = [], remaining = promises.length,
promise, remaining_count = promises.length - expected_count; promise, remaining_count = promises.length - expected_count;
...@@ -49,12 +49,6 @@ function promiseAtLeast(expected_count, promises) { ...@@ -49,12 +49,6 @@ function promiseAtLeast(expected_count, promises) {
} }
} }
function notifier(index) {
return function(value) {
notify({"index": index, "value": value});
};
}
function cancelAll(rejectionValue) { function cancelAll(rejectionValue) {
reject(rejectionValue); reject(rejectionValue);
canceller(); canceller();
...@@ -64,7 +58,7 @@ function promiseAtLeast(expected_count, promises) { ...@@ -64,7 +58,7 @@ function promiseAtLeast(expected_count, promises) {
promise = promises[i]; promise = promises[i];
if (promise && typeof promise.then === 'function') { if (promise && typeof promise.then === 'function') {
promise.then(resolver(i), cancelAll, notifier(i)); promise.then(resolver(i), cancelAll);
} else { } else {
resolveAll(i, promise); resolveAll(i, promise);
} }
......
...@@ -39,11 +39,6 @@ var Promise = function(resolver, canceller) { ...@@ -39,11 +39,6 @@ var Promise = function(resolver, canceller) {
reject(promise, value); reject(promise, value);
}; };
var notifyPromise = function(value) {
if (resolved) { return; }
notify(promise, value);
};
this.on('promise:failed', function(event) { this.on('promise:failed', function(event) {
this.trigger('error', { detail: event.detail }); this.trigger('error', { detail: event.detail });
}, this); }, this);
...@@ -67,7 +62,7 @@ var Promise = function(resolver, canceller) { ...@@ -67,7 +62,7 @@ var Promise = function(resolver, canceller) {
}; };
try { try {
resolver(resolvePromise, rejectPromise, notifyPromise); resolver(resolvePromise, rejectPromise);
} catch(e) { } catch(e) {
rejectPromise(e); rejectPromise(e);
} }
...@@ -112,22 +107,6 @@ var invokeCallback = function(type, promise, callback, event) { ...@@ -112,22 +107,6 @@ var invokeCallback = function(type, promise, callback, event) {
} }
}; };
var invokeNotifyCallback = function(promise, callback, event) {
var value;
if (typeof callback === 'function') {
try {
value = callback(event.detail);
} catch (e) {
// stop propagating
return;
}
notify(promise, value);
} else {
notify(promise, event.detail);
}
};
Promise.prototype = { Promise.prototype = {
constructor: Promise, constructor: Promise,
...@@ -136,7 +115,7 @@ Promise.prototype = { ...@@ -136,7 +115,7 @@ Promise.prototype = {
rejectedReason: undefined, rejectedReason: undefined,
fulfillmentValue: undefined, fulfillmentValue: undefined,
then: function(done, fail, progress) { then: function(done, fail) {
this.off('error', onerror); this.off('error', onerror);
var thenPromise = new this.constructor(function() {}, var thenPromise = new this.constructor(function() {},
...@@ -164,10 +143,6 @@ Promise.prototype = { ...@@ -164,10 +143,6 @@ Promise.prototype = {
invokeCallback('reject', thenPromise, fail, event); invokeCallback('reject', thenPromise, fail, event);
}); });
this.on('promise:notified', function (event) {
invokeNotifyCallback(thenPromise, progress, event);
});
return thenPromise; return thenPromise;
}, },
...@@ -203,11 +178,6 @@ function handleThenable(promise, value) { ...@@ -203,11 +178,6 @@ function handleThenable(promise, value) {
then = value.then; then = value.then;
if (isFunction(then)) { if (isFunction(then)) {
if (isFunction(value.on)) {
value.on('promise:notified', function (event) {
notify(promise, event.detail);
});
}
promise.on('promise:cancelled', function(event) { promise.on('promise:cancelled', function(event) {
if (isFunction(value.cancel)) { if (isFunction(value.cancel)) {
value.cancel(); value.cancel();
...@@ -260,10 +230,4 @@ function reject(promise, value) { ...@@ -260,10 +230,4 @@ function reject(promise, value) {
}); });
} }
function notify(promise, value) {
config.async(function() {
promise.trigger('promise:notified', { detail: value });
});
}
export { Promise }; export { Promise };
...@@ -18,7 +18,6 @@ var Queue = function() { ...@@ -18,7 +18,6 @@ var Queue = function() {
promise, promise,
fulfill, fulfill,
reject, reject,
notify,
resolved; resolved;
if (!(this instanceof Queue)) { if (!(this instanceof Queue)) {
...@@ -31,7 +30,7 @@ var Queue = function() { ...@@ -31,7 +30,7 @@ var Queue = function() {
} }
} }
promise = new Promise(function(done, fail, progress) { promise = new Promise(function(done, fail) {
fulfill = function (fulfillmentValue) { fulfill = function (fulfillmentValue) {
if (resolved) {return;} if (resolved) {return;}
queue.isFulfilled = true; queue.isFulfilled = true;
...@@ -46,7 +45,6 @@ var Queue = function() { ...@@ -46,7 +45,6 @@ var Queue = function() {
resolved = true; resolved = true;
return fail(rejectedReason); return fail(rejectedReason);
}; };
notify = progress;
}, canceller); }, canceller);
promise_list.push(resolve()); promise_list.push(resolve());
...@@ -70,7 +68,7 @@ var Queue = function() { ...@@ -70,7 +68,7 @@ var Queue = function() {
return promise.then.apply(promise, arguments); return promise.then.apply(promise, arguments);
}; };
queue.push = function(done, fail, progress) { queue.push = function(done, fail) {
var last_promise = promise_list[promise_list.length - 1], var last_promise = promise_list[promise_list.length - 1],
next_promise; next_promise;
...@@ -78,11 +76,11 @@ var Queue = function() { ...@@ -78,11 +76,11 @@ var Queue = function() {
throw new ResolvedQueueError(); throw new ResolvedQueueError();
} }
next_promise = last_promise.then(done, fail, progress); next_promise = last_promise.then(done, fail);
promise_list.push(next_promise); promise_list.push(next_promise);
// Handle pop // Handle pop
last_promise = next_promise.then(function (fulfillmentValue) { promise_list.push(next_promise.then(function (fulfillmentValue) {
promise_list.splice(0, 2); promise_list.splice(0, 2);
if (promise_list.length === 0) { if (promise_list.length === 0) {
fulfill(fulfillmentValue); fulfill(fulfillmentValue);
...@@ -96,13 +94,7 @@ var Queue = function() { ...@@ -96,13 +94,7 @@ var Queue = function() {
} else { } else {
throw rejectedReason; throw rejectedReason;
} }
}, function (notificationValue) { }));
if (promise_list[promise_list.length - 1] === last_promise) {
notify(notificationValue);
}
return notificationValue;
});
promise_list.push(last_promise);
return this; return this;
}; };
......
...@@ -178,89 +178,6 @@ describe("RSVP extensions", function() { ...@@ -178,89 +178,6 @@ describe("RSVP extensions", function() {
}); });
it('notify should exist', function (done) {
var exists, promise = new RSVP.Promise(function (resolve, reject, notify) {
exists = typeof notify === 'function';
});
setTimeout(function () {
assert(exists);
done();
}, 20);
});
it('should notify if `notify` is called with a value', function (done) {
var promise = new RSVP.Promise(function (resolve, reject, notify) {
notify('foo');
});
promise.then(null, null, function (foo) {
assert.equal(foo, 'foo');
done();
});
});
it('should notify twice before resolve', function (done) {
var notified = 0, promise = new RSVP.Promise(function (resolve, reject, notify) {
notify('foo');
notify('bar');
resolve('end');
notify('should not be notified');
});
promise.then(function () {
var currently_notified = notified;
setTimeout(function () {
assert.equal(currently_notified, 2);
assert.equal(notified, 2);
done();
}, 50);
}, null, function () {
notified += 1;
});
});
it('notify should propagate on two then', function (done) {
var last_notified = false, promise = new RSVP.Promise(function (resolve, reject, notify) {
notify('foo');
});
promise.then(null, null, function (foo) {
assert.equal(foo, 'foo');
return 'bar';
}).then(null, null, function (bar) {
assert.equal(bar, 'bar');
setTimeout(function () {
assert(!last_notified);
done();
}, 50);
throw 'baz';
}).then(null, null, function () {
last_notified = true;
});
});
it('notify should propagate to parent `then`', function (done) {
var i = 0, responses = [];
new RSVP.Promise(function (resolve) {
resolve();
}).then(function () {
return new RSVP.Promise(function (resolve, reject, notify) {
notify(1);
notify(2);
resolve(3);
});
}).then(function (answer) {
responses.push(answer);
}, null, function (notification) {
responses.push(notification);
});
setTimeout(function () {
assert(responses[0] === 1, "Notified once");
assert(responses[1] === 2, "Notified twice");
assert(responses[2] === 3, "Fulfilled after notifications");
done();
}, 50);
});
describe('assimilation', function() { describe('assimilation', function() {
it('should assimilate if `resolve` is called with a fulfilled promise', function(done) { it('should assimilate if `resolve` is called with a fulfilled promise', function(done) {
var originalPromise = new RSVP.Promise(function(resolve) { resolve('original value'); }); var originalPromise = new RSVP.Promise(function(resolve) { resolve('original value'); });
...@@ -871,43 +788,6 @@ describe("RSVP extensions", function() { ...@@ -871,43 +788,6 @@ describe("RSVP extensions", function() {
}, 20); }, 20);
}); });
specify('notifies promises progress', function(done) {
var firstResolver, secondResolver, count = 0, expected = {};
var first = new RSVP.Promise(function(resolve, reject, notify) {
firstResolver = { resolve: resolve, reject: reject, notify: notify };
});
var second = new RSVP.Promise(function(resolve, reject, notify) {
secondResolver = { resolve: resolve, reject: reject, notify: notify };
});
expected.index = [0, 1, 1];
expected.value = [1, 2, 3];
setTimeout(function() {
firstResolver.notify(1);
secondResolver.notify(2);
}, 0);
setTimeout(function() {
secondResolver.notify(3);
}, 30);
var all_promise = RSVP.all([first, second]).
then(null, null, function (value) {
count += 1;
assert.equal(value.index, expected.index.shift());
assert.equal(value.value, expected.value.shift());
});
all_promise.cancel();
setTimeout(function() {
assert.equal(count, 3);
done();
}, 50);
});
}); });
describe("RSVP.any", function() { describe("RSVP.any", function() {
...@@ -1035,7 +915,7 @@ describe("RSVP extensions", function() { ...@@ -1035,7 +915,7 @@ describe("RSVP extensions", function() {
specify('cancel the remaining promises as soon as resolved', function(done) { specify('cancel the remaining promises as soon as resolved', function(done) {
var promise = new RSVP.Promise(function(resolve) { resolve(1); }); var promise = new RSVP.Promise(function(resolve) { resolve(1); });
var asyncPromise = new RSVP.Promise(function(resolve) { var asyncPromise = new RSVP.Promise(function(resolve) {
setTimeout(function() { resolve(2); }, 0); }); setTimeout(function() { resolve(2); }, 0); });
RSVP.any([promise, asyncPromise]).then(function(result) { RSVP.any([promise, asyncPromise]).then(function(result) {
...@@ -1145,43 +1025,6 @@ describe("RSVP extensions", function() { ...@@ -1145,43 +1025,6 @@ describe("RSVP extensions", function() {
}, 20); }, 20);
}); });
specify('notifies promises progress', function(done) {
var firstResolver, secondResolver, count = 0, expected = {};
var first = new RSVP.Promise(function(resolve, reject, notify) {
firstResolver = { resolve: resolve, reject: reject, notify: notify };
});
var second = new RSVP.Promise(function(resolve, reject, notify) {
secondResolver = { resolve: resolve, reject: reject, notify: notify };
});
expected.index = [0, 1, 1];
expected.value = [1, 2, 3];
setTimeout(function() {
firstResolver.notify(1);
secondResolver.notify(2);
}, 0);
setTimeout(function() {
secondResolver.notify(3);
}, 30);
var all_promise = RSVP.any([first, second]).
then(null, null, function (value) {
count += 1;
assert.equal(value.index, expected.index.shift());
assert.equal(value.value, expected.value.shift());
});
all_promise.cancel();
setTimeout(function() {
assert.equal(count, 3);
done();
}, 50);
});
}); });
describe("RSVP.reject", function(){ describe("RSVP.reject", function(){
...@@ -2404,38 +2247,5 @@ describe("`RSVP.Queue`", function () { ...@@ -2404,38 +2247,5 @@ describe("`RSVP.Queue`", function () {
done(); done();
}, 20); }, 20);
}); });
it("notify should be propagated until `then`", function (done) {
var queue = new RSVP.Queue(), i = 0, responses = [];
queue.push(function () {
return new RSVP.Promise(function (resolve, reject, notify) {
notify("hello");
});
});
queue.push(null, null, function (notification) {
responses.push(1);
responses.push(notification);
return notification;
});
queue.push(function () {
return;
});
queue.then(null, null, function (notification) {
responses.push(2);
responses.push(notification);
});
setTimeout(function () {
assert.equal(responses[0], 1);
assert.equal(responses[1], "hello", "Notification");
assert.equal(responses[2], 2);
assert.equal(responses[3], "hello", "Notification");
done();
}, 50);
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment