Skip to content

Commit

Permalink
Goodbye .cast, we hardly knew ye (.resolve now behaves as .cast)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Apr 28, 2014
1 parent a1b23fb commit baa0195
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 111 deletions.
66 changes: 0 additions & 66 deletions lib/promise/cast.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/promise/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function polyfill() {
"Promise" in local &&
// Some of these methods are missing from
// Firefox/Chrome experimental implementations
"cast" in local.Promise &&
"resolve" in local.Promise &&
"reject" in local.Promise &&
"all" in local.Promise &&
Expand Down
2 changes: 0 additions & 2 deletions lib/promise/promise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { config, configure } from "./config";
import { objectOrFunction, isFunction, now } from './utils';
import { cast } from "./cast";
import { all } from "./all";
import { race } from "./race";
import { resolve as staticResolve } from "./resolve";
Expand Down Expand Up @@ -128,7 +127,6 @@ Promise.prototype = {
};

Promise.all = all;
Promise.cast = cast;
Promise.race = race;
Promise.resolve = staticResolve;
Promise.reject = staticReject;
Expand Down
39 changes: 6 additions & 33 deletions lib/promise/resolve.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
/**
`RSVP.resolve` returns a promise that will become fulfilled with the passed
`value`. `RSVP.resolve` is essentially shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
resolve(1);
});
promise.then(function(value){
// value === 1
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.resolve(1);
promise.then(function(value){
// value === 1
});
```
@method resolve
@for RSVP
@param {Any} value value that the returned promise will be resolved with
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become fulfilled with the given
`value`
*/
function resolve(value) {
/*jshint validthis:true */
if (value && typeof value === 'object' && value.constructor === this) {
return value;
}

var Promise = this;
return new Promise(function(resolve, reject) {

return new Promise(function(resolve) {
resolve(value);
});
}
Expand Down
16 changes: 7 additions & 9 deletions test/tests/extension_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ describe("RSVP extensions", function() {
});
});

describe("RSVP.resolve", function(){
describe("Promise.resolve", function(){
specify("it should exist", function(){
assert(Promise.resolve);
});
Expand Down Expand Up @@ -864,19 +864,17 @@ describe("RSVP extensions", function() {
assert(callCount === 0, 'expected async, was sync');
});
});
});

describe("Promise.cast", function () {
it("If SameValue(constructor, C) is true, return x.", function(){
var promise = Promise.resolve(1);
var casted = Promise.cast(promise);
var casted = Promise.resolve(promise);

assert.deepEqual(casted, promise);
});

it("If SameValue(constructor, C) is false, and isThenable(C) is true, return PromiseResolve(promise, x).", function(){
var promise = { then: function() { } };
var casted = Promise.cast(promise);
var casted = Promise.resolve(promise);

assert(casted instanceof Promise);
assert(casted !== promise);
Expand All @@ -889,10 +887,10 @@ describe("RSVP extensions", function() {

PromiseSubclass.prototype = Object.create(Promise.prototype);
PromiseSubclass.prototype.constructor = PromiseSubclass;
PromiseSubclass.cast = Promise.cast;
PromiseSubclass.resolve = Promise.resolve;

var promise = Promise.resolve(1);
var casted = PromiseSubclass.cast(promise);
var casted = PromiseSubclass.resolve(promise);

assert(casted instanceof Promise);
assert(casted instanceof PromiseSubclass);
Expand All @@ -906,14 +904,14 @@ describe("RSVP extensions", function() {

it("If SameValue(constructor, C) is false, and isThenable(C) is false, return PromiseResolve(promise, x).", function(){
var value = 1;
var casted = Promise.cast(value);
var casted = Promise.resolve(value);

assert(casted instanceof Promise);
assert(casted !== value);
});

it("casts null correctly", function(done){
Promise.cast(null).then(function(value){
Promise.resolve(null).then(function(value){
assert.equal(value, null);
done();
});
Expand Down

0 comments on commit baa0195

Please sign in to comment.