Skip to content

Commit

Permalink
Bump version, rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
briancavalier committed Oct 9, 2015
1 parent 822405d commit 6dd6e5a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 44 deletions.
96 changes: 54 additions & 42 deletions dist/creed.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@
}
}

// maybeThenable :: * -> boolean
function maybeThenable(x) {
return (typeof x === 'object' || typeof x === 'function') && x !== null;
}

function _map(f, p, promise) {
return runMap(applyMap, f, p, promise);
}
Expand All @@ -264,7 +269,12 @@
}

function applyChain(f, x, p) {
p._become(f(x).near());
var y = f(x);
if (maybeThenable(y) && typeof y.then === 'function') {
p._resolve(y);
} else {
p._reject(new TypeError('f must return a promise'));
}
}

var Map = (function () {
Expand Down Expand Up @@ -334,11 +344,6 @@
}
}

// maybeThenable :: * -> boolean
function maybeThenable(x) {
return (typeof x === 'object' || typeof x === 'function') && x !== null;
}

function resultsArray(iterable) {
return Array.isArray(iterable) ? new Array(iterable.length) : [];
}
Expand Down Expand Up @@ -502,6 +507,10 @@
// ## Types
// -------------------------------------------------------------

var Core = function Core() {
_classCallCheck(this, Core);
}

// data Promise e a where
// Future :: Promise e a
// Fulfilled :: a -> Promise e a
Expand All @@ -510,11 +519,15 @@

// Future :: Promise e a
// A promise whose value cannot be known until some future time
;

var Future = (function (_Core) {
_inherits(Future, _Core);

var Future = (function () {
function Future() {
_classCallCheck(this, Future);

_Core.call(this);
this.ref = void 0;
this.action = void 0;
this.length = 0;
Expand Down Expand Up @@ -685,12 +698,15 @@
};

return Future;
})();
})(Core);

var Fulfilled = (function (_Core2) {
_inherits(Fulfilled, _Core2);

var Fulfilled = (function () {
function Fulfilled(x) {
_classCallCheck(this, Fulfilled);

_Core2.call(this);
this.value = x;
}

Expand Down Expand Up @@ -746,12 +762,15 @@
};

return Fulfilled;
})();
})(Core);

var Rejected = (function (_Core3) {
_inherits(Rejected, _Core3);

var Rejected = (function () {
function Rejected(e) {
_classCallCheck(this, Rejected);

_Core3.call(this);
this.value = e;
this._state = REJECTED;
errorHandler.track(this);
Expand Down Expand Up @@ -811,13 +830,24 @@
};

return Rejected;
})();
})(Core);

var Never = (function (_Core4) {
_inherits(Never, _Core4);

var Never = (function () {
function Never() {
_classCallCheck(this, Never);

_Core4.apply(this, arguments);
}

// -------------------------------------------------------------
// ## Creating promises
// -------------------------------------------------------------

// resolve :: Thenable e a -> Promise e a
// resolve :: a -> Promise e a

Never.prototype.then = function then() {
return this;
};
Expand Down Expand Up @@ -863,16 +893,8 @@
Never.prototype._runAction = function _runAction() {};

return Never;
})();
})(Core);

Future.prototype.constructor = Fulfilled.prototype.constructor = Rejected.prototype.constructor = Never.prototype.constructor = Future;

// -------------------------------------------------------------
// ## Creating promises
// -------------------------------------------------------------

// resolve :: Thenable e a -> Promise e a
// resolve :: a -> Promise e a
function _resolve(x) {
return isPromise(x) ? x.near() : maybeThenable(x) ? refForMaybeThenable(fulfill, x) : new Fulfilled(x);
}
Expand Down Expand Up @@ -941,7 +963,7 @@

// isPromise :: * -> boolean
function isPromise(x) {
return typeof x === 'object' && x != null && x.constructor === Future;
return x instanceof Core;
}

function resolveMaybeThenable(x) {
Expand Down Expand Up @@ -992,8 +1014,8 @@
return Continuation;
})();

function coroutine(refFor, iterator, promise) {
new Coroutine(refFor, iterator, promise).run();
function coroutine(resolve, iterator, promise) {
new Coroutine(resolve, iterator, promise).run();
return promise;
}

Expand Down Expand Up @@ -1284,7 +1306,7 @@
args[_key2] = arguments[_key2];
}

return runNodeResolver(f, this, args, new Future());
return runResolver(runNode, f, this, args, new Future());
};
}

Expand All @@ -1295,18 +1317,7 @@
args[_key3 - 1] = arguments[_key3];
}

return runNodeResolver(f, this, args, new Future());
}

function runNodeResolver(f, thisArg, args, p) {
checkFunction(f);

try {
runNode(f, thisArg, args, p);
} catch (e) {
p._reject(e);
}
return p;
return runResolver(runNode, f, this, args, new Future());
}

// -------------------------------------------------------------
Expand All @@ -1322,17 +1333,18 @@
args[_key4 - 1] = arguments[_key4];
}

return runResolver(f, this, args, new Future());
return runResolver(runPromise, f, this, args, new Future());
}

function runResolver(f, thisArg, args, p) {
function runResolver(run, f, thisArg, args, p) {
checkFunction(f);

try {
runPromise(f, thisArg, args, p);
run(f, thisArg, args, p);
} catch (e) {
p._reject(e);
}

return p;
}

Expand Down Expand Up @@ -1435,7 +1447,7 @@
_classCallCheck(this, CreedPromise);

_Future.call(this);
runResolver(f, void 0, NOARGS, this);
runResolver(runPromise, f, void 0, NOARGS, this);
}

return CreedPromise;
Expand Down
Loading

0 comments on commit 6dd6e5a

Please sign in to comment.