Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ayepromise

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ayepromise - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

97

ayepromise.js

@@ -32,3 +32,3 @@ // UMD header

var getThenableIfExists = function (obj) {
// Make sure we only access the accessor once
// Make sure we only access the accessor once as required by the spec
var then = obj && obj.then;

@@ -40,49 +40,42 @@

return then.bind(obj);
return function() { return then.apply(obj, arguments); };
}
};
var doChainCall = function (defer, func, value) {
setTimeout(function () {
var returnValue;
try {
returnValue = func(value);
} catch (e) {
defer.reject(e);
return;
}
var aThenHandler = function (onFulfilled, onRejected) {
var defer = ayepromise.defer();
if (returnValue === defer.promise) {
defer.reject(new TypeError('Cannot resolve promise with itself'));
} else {
defer.resolve(returnValue);
}
}, 1);
};
var doHandlerCall = function (func, value) {
setTimeout(function () {
var returnValue;
try {
returnValue = func(value);
} catch (e) {
defer.reject(e);
return;
}
var doFulfillCall = function (defer, onFulfilled, value) {
if (onFulfilled && onFulfilled.call) {
doChainCall(defer, onFulfilled, value);
} else {
defer.resolve(value);
}
};
if (returnValue === defer.promise) {
defer.reject(new TypeError('Cannot resolve promise with itself'));
} else {
defer.resolve(returnValue);
}
}, 1);
};
var doRejectCall = function (defer, onRejected, value) {
if (onRejected && onRejected.call) {
doChainCall(defer, onRejected, value);
} else {
defer.reject(value);
}
};
var aCallChainLink = function (onFulfilled, onRejected) {
var defer = ayepromise.defer();
return {
promise: defer.promise,
callFulfilled: function (value) {
doFulfillCall(defer, onFulfilled, value);
if (onFulfilled && onFulfilled.call) {
doHandlerCall(onFulfilled, value);
} else {
defer.resolve(value);
}
},
callRejected: function (value) {
doRejectCall(defer, onRejected, value);
if (onRejected && onRejected.call) {
doHandlerCall(onRejected, value);
} else {
defer.reject(value);
}
}

@@ -100,3 +93,3 @@ };

outcome,
callbacks = [];
thenHandlers = [];

@@ -107,4 +100,4 @@ var doFulfill = function (value) {

callbacks.forEach(function (link) {
link.callFulfilled(outcome);
thenHandlers.forEach(function (then) {
then.callFulfilled(outcome);
});

@@ -117,23 +110,23 @@ };

callbacks.forEach(function (link) {
link.callRejected(outcome);
thenHandlers.forEach(function (then) {
then.callRejected(outcome);
});
};
var executeResultHandlerDirectlyIfStateNotPendingAnymore = function (link) {
var executeThenHandlerDirectlyIfStateNotPendingAnymore = function (then) {
if (state === FULFILLED) {
link.callFulfilled(outcome);
then.callFulfilled(outcome);
} else if (state === REJECTED) {
link.callRejected(outcome);
then.callRejected(outcome);
}
};
var registerResultHandler = function (onFulfilled, onRejected) {
var link = aCallChainLink(onFulfilled, onRejected);
var registerThenHandler = function (onFulfilled, onRejected) {
var thenHandler = aThenHandler(onFulfilled, onRejected);
callbacks.push(link);
thenHandlers.push(thenHandler);
executeResultHandlerDirectlyIfStateNotPendingAnymore(link);
executeThenHandlerDirectlyIfStateNotPendingAnymore(thenHandler);
return link.promise;
return thenHandler.promise;
};

@@ -176,5 +169,5 @@

promise: {
then: registerResultHandler,
then: registerThenHandler,
fail: function (onRejected) {
return registerResultHandler(null, onRejected);
return registerThenHandler(null, onRejected);
}

@@ -181,0 +174,0 @@ }

{
"name": "ayepromise",
"version": "0.0.2",
"version": "1.0.0",
"main": "ayepromise.js",

@@ -5,0 +5,0 @@ "devDependencies": {

{
"version": "1.0.0",
"version": "1.1.0",
"name": "ayepromise",

@@ -4,0 +4,0 @@ "main": "./ayepromise.js",

@@ -11,43 +11,13 @@ <a href="http://promises-aplus.github.com/promises-spec">

<a href="http://badge.fury.io/js/ayepromise"><img src="https://badge.fury.io/js/ayepromise.svg" alt="NPM version" height="18" align="right"></a>
Why yet another promise library?
--------------------------------
ayepromise wants to be as small as possible, staying compatible to Q while fully implementing the spec. It's licenses under WTFPL and/or BSD.
ayepromise wants to be as small as possible (~180 LOC, ~1200 bytes minified), staying compatible to Q while fully implementing the spec. It's licensed under WTFPL and/or BSD.
ayepromise tries to be fully compatible with [kriskowal's Q](https://github.com/kriskowal/q) in such a way that you can always replace ```ayepromise``` with ```Q```. (There's a catch: ayepromise tries to strictly follow Promises/A+ 1.1 and will differ where Q does not.) It will not however try to implement anything close to the full feature set. Check ```test/CompatibilitySpecRunner.html``` to see ayepromise's test suite executed against Q.
[![Build Status](https://secure.travis-ci.org/cburgmer/ayepromise.png?branch=master)](http://travis-ci.org/cburgmer/ayepromise)
[![Build Status](https://travis-ci.org/cburgmer/ayepromise.svg?branch=master)](https://travis-ci.org/cburgmer/ayepromise)
Why?
----
Allow an asyncronous function to return a promise
aPromiseReturningFunction()
.then(someOtherAsyncStuff)
.then(somethingOnTopOfAllThat)
.then(function (result) {
})
.fail(function (error) {
});
omitting the "pyramid of doom".
Make an existing "old-school" function promise aware:
var myPromisingXhr = function (url) {
var defer = aye.defer();
...
xhr.onload = function (content) {
defer.resolve(content);
};
xhr.onerror = function (e) {
defer.reject(e);
};
xhr.send();
return defer.promise;
};
Run the test suite

@@ -54,0 +24,0 @@ ------------------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc