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) {
}
}
return new Promise(function(resolve, reject, notify) {
return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length,
promise, remaining_count = promises.length - expected_count;
......@@ -49,12 +49,6 @@ function promiseAtLeast(expected_count, promises) {
}
}
function notifier(index) {
return function(value) {
notify({"index": index, "value": value});
};
}
function cancelAll(rejectionValue) {
reject(rejectionValue);
canceller();
......@@ -64,7 +58,7 @@ function promiseAtLeast(expected_count, promises) {
promise = promises[i];
if (promise && typeof promise.then === 'function') {
promise.then(resolver(i), cancelAll, notifier(i));
promise.then(resolver(i), cancelAll);
} else {
resolveAll(i, promise);
}
......
......@@ -39,11 +39,6 @@ var Promise = function(resolver, canceller) {
reject(promise, value);
};
var notifyPromise = function(value) {
if (resolved) { return; }
notify(promise, value);
};
this.on('promise:failed', function(event) {
this.trigger('error', { detail: event.detail });
}, this);
......@@ -67,7 +62,7 @@ var Promise = function(resolver, canceller) {
};
try {
resolver(resolvePromise, rejectPromise, notifyPromise);
resolver(resolvePromise, rejectPromise);
} catch(e) {
rejectPromise(e);
}
......@@ -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 = {
constructor: Promise,
......@@ -136,7 +115,7 @@ Promise.prototype = {
rejectedReason: undefined,
fulfillmentValue: undefined,
then: function(done, fail, progress) {
then: function(done, fail) {
this.off('error', onerror);
var thenPromise = new this.constructor(function() {},
......@@ -164,10 +143,6 @@ Promise.prototype = {
invokeCallback('reject', thenPromise, fail, event);
});
this.on('promise:notified', function (event) {
invokeNotifyCallback(thenPromise, progress, event);
});
return thenPromise;
},
......@@ -203,11 +178,6 @@ function handleThenable(promise, value) {
then = value.then;
if (isFunction(then)) {
if (isFunction(value.on)) {
value.on('promise:notified', function (event) {
notify(promise, event.detail);
});
}
promise.on('promise:cancelled', function(event) {
if (isFunction(value.cancel)) {
value.cancel();
......@@ -260,10 +230,4 @@ function reject(promise, value) {
});
}
function notify(promise, value) {
config.async(function() {
promise.trigger('promise:notified', { detail: value });
});
}
export { Promise };
......@@ -18,7 +18,6 @@ var Queue = function() {
promise,
fulfill,
reject,
notify,
resolved;
if (!(this instanceof Queue)) {
......@@ -31,7 +30,7 @@ var Queue = function() {
}
}
promise = new Promise(function(done, fail, progress) {
promise = new Promise(function(done, fail) {
fulfill = function (fulfillmentValue) {
if (resolved) {return;}
queue.isFulfilled = true;
......@@ -46,7 +45,6 @@ var Queue = function() {
resolved = true;
return fail(rejectedReason);
};
notify = progress;
}, canceller);
promise_list.push(resolve());
......@@ -70,7 +68,7 @@ var Queue = function() {
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],
next_promise;
......@@ -78,11 +76,11 @@ var Queue = function() {
throw new ResolvedQueueError();
}
next_promise = last_promise.then(done, fail, progress);
next_promise = last_promise.then(done, fail);
promise_list.push(next_promise);
// Handle pop
last_promise = next_promise.then(function (fulfillmentValue) {
promise_list.push(next_promise.then(function (fulfillmentValue) {
promise_list.splice(0, 2);
if (promise_list.length === 0) {
fulfill(fulfillmentValue);
......@@ -96,13 +94,7 @@ var Queue = function() {
} else {
throw rejectedReason;
}
}, function (notificationValue) {
if (promise_list[promise_list.length - 1] === last_promise) {
notify(notificationValue);
}
return notificationValue;
});
promise_list.push(last_promise);
}));
return this;
};
......
......@@ -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() {
it('should assimilate if `resolve` is called with a fulfilled promise', function(done) {
var originalPromise = new RSVP.Promise(function(resolve) { resolve('original value'); });
......@@ -871,43 +788,6 @@ describe("RSVP extensions", function() {
}, 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() {
......@@ -1145,43 +1025,6 @@ describe("RSVP extensions", function() {
}, 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(){
......@@ -2404,38 +2247,5 @@ describe("`RSVP.Queue`", function () {
done();
}, 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