Comparing version 0.0.20 to 0.0.22
/** | ||
* jeefo : v0.0.20 | ||
* jeefo : v0.0.22 | ||
* Author : je3f0o, <je3f0o@gmail.com> | ||
@@ -86,3 +86,3 @@ * Homepage : https://github.com/je3f0o/jeefo | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-05-06 | ||
* Updated at : 2017-07-11 | ||
* Author : jeefo | ||
@@ -101,2 +101,3 @@ * Purpose : | ||
instance.then = then; | ||
instance.$catch = $catch; | ||
instance.state = "pending..."; | ||
@@ -106,21 +107,37 @@ instance.is_pending = is_pending; | ||
// Promise handler {{{2 | ||
promise_handler(function (value) { | ||
if (state !== 0) { return; } | ||
try { | ||
promise_handler(function (value) { | ||
if (state !== 0) { return; } | ||
state = 1; | ||
instance.state = "resolved"; | ||
instance.value = result = value; | ||
state = 1; | ||
instance.state = "resolved"; | ||
instance.value = result = value; | ||
for (var i = 0; i < pendings_length; i += 4) { | ||
value = pendings[i](result); | ||
for (var i = 0; i < pendings_length; i += 4) { | ||
value = pendings[i](result); | ||
if (value && value.type === "JEEFO_PROMISE") { | ||
value.then(pendings[i + 2], pendings[i + 3]); | ||
} else { | ||
pendings[i + 2](value); | ||
if (value && value.type === "JEEFO_PROMISE") { | ||
value.then(pendings[i + 2], pendings[i + 3]); | ||
} else { | ||
pendings[i + 2](value); | ||
} | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
}, function (reason) { | ||
pendings = null; | ||
pendings_length = 0; | ||
}, _rejector); | ||
} catch (e) { | ||
_rejector(e); | ||
} | ||
// }}}2 | ||
// jshint latedef : false | ||
return instance; | ||
// Is pending ? {{{2 | ||
function is_pending () { | ||
return state === 0; | ||
} | ||
// Rejector {{{2 | ||
function _rejector (reason) { | ||
if (state !== 0) { return; } | ||
@@ -143,11 +160,2 @@ | ||
pendings_length = 0; | ||
}); | ||
// }}}2 | ||
// jshint latedef : false | ||
return instance; | ||
// Is pending ? {{{2 | ||
function is_pending () { | ||
return state === 0; | ||
} | ||
@@ -160,5 +168,12 @@ | ||
case 1 : | ||
return next_resolver(resolver(result)); | ||
var next_result = resolver(result); | ||
if (next_result && next_result.type === "JEEFO_PROMISE") { | ||
return next_result.then(next_resolver, next_rejector); | ||
} | ||
return next_resolver(next_result); | ||
case 2 : | ||
return next_rejector(rejector(result)); | ||
if (rejector) { | ||
return next_resolver(rejector(result)); | ||
} | ||
return next_rejector(result); | ||
default: | ||
@@ -173,2 +188,18 @@ pendings[pendings_length ] = resolver; | ||
} | ||
// Catch {{{2 | ||
function $catch (rejector) { | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
switch (state) { | ||
case 2 : | ||
return next_resolver(rejector(result)); | ||
default: | ||
pendings[pendings_length ] = null; | ||
pendings[pendings_length + 1] = rejector; | ||
pendings[pendings_length + 2] = null; | ||
pendings[pendings_length + 3] = next_rejector; | ||
pendings_length += 4; | ||
} | ||
}); | ||
} | ||
// }}}2 | ||
@@ -175,0 +206,0 @@ // jshint latedef : true |
/** | ||
* jeefo : v0.0.20 | ||
* jeefo : v0.0.22 | ||
* Author : je3f0o, <je3f0o@gmail.com> | ||
@@ -8,2 +8,2 @@ * Homepage : https://github.com/je3f0o/jeefo | ||
**/ | ||
!function(){"use strict";var e=function(){var e=Array,n=e.isArray,r=Object.keys,t=function(e){for(var n,t,i,o=1;o<arguments.length;++o)if(n=arguments[o])for(t=r(n),i=t.length-1;i>=0;e[t[i]]=n[t[i]],--i);return e},i=function(e){throw new Error(e)},o=function(n,r){var t=[],o={};return function s(u,c){for(var d=c.length-1,f=new e(d+1),a=r(u);d>=0;f[d]=c[d],--d);for(f.push(u),o[u]=!0,d=0;d<a.length;++d)f.indexOf(a[d])>=0&&i("Circular dependency '"+a[d]+" is required by '"+n+"' : "+f.join(" -> ")),o.hasOwnProperty(a[d])||s(a[d],f);-1===t.indexOf(u)&&t.push(u)}(n,[]),t},s=function(e){function n(){return 0===i}function r(e,n){return new s(function(r,s){switch(i){case 1:return r(e(t));case 2:return s(n(t));default:o[c]=e,o[c+1]=n,o[c+2]=r,o[c+3]=s,c+=4}})}var t,i=0,o=[],u=this,c=0;return u.then=r,u.state="pending...",u.is_pending=n,e(function(e){if(0===i){i=1,u.state="resolved",u.value=t=e;for(var n=0;n<c;n+=4)e=o[n](t),e&&"JEEFO_PROMISE"===e.type?e.then(o[n+2],o[n+3]):o[n+2](e);o=null,c=0}},function(e){if(0===i){i=2,u.state="rejected",u.reason=t=e;for(var n=1;n<c;n+=4)e=o[n](t),e&&"JEEFO_PROMISE"===e.type?e.then(o[n+1],o[n+2]):o[n+2](e);o=null,c=0}}),u};s.prototype.type="JEEFO_PROMISE";var u={defer:function(){var e={};return e.promise=new s(function(n,r){e.resolve=n,e.reject=r}),e},when:function(e){return e&&"JEEFO_PROMISE"===e.type?e:new s(function(n){n(e)})},for_each_async:function(e,n){function r(){++t<e.length?n.call(e,e[t],t,r,e):i.resolve()}var t=-1,i=this.defer();return r(),i.promise},all:function(e){for(var n,r=0,t=this.defer(),i=0;r<e.length;++r)(n=e[r])&&"JEEFO_PROMISE"===n.type&&(i+=1,n.then(function(n){return function(r){e[n]=r,0===--i&&t.resolve(e)}}(r)));return 0===i&&t.resolve(e),t.promise}},c=function(e){this.values=t({},e),this.definitions={}},d=[];c.prototype={register:function(n,r){if(r.dependencies){for(var t=new e(r.dependencies.length),o=t.length-1;o>=0;t[o]=r.dependencies[o],--o);(this.values.hasOwnProperty(n)||this.definitions.hasOwnProperty(n))&&i("Duplicated provider "+n+" detected."),this.definitions[n]={fn:r.fn,dependencies:t,is_constructor:!!r.is_constructor}}else this.definitions[n]={fn:r.fn,dependencies:d,is_constructor:!!r.is_constructor};return this},resolve:function(n,r){var t,s=this.values,c=this.definitions,d=r&&r.values||{},f=r&&r.definitions;return d.hasOwnProperty(n)?d[n]&&"JEEFO_PROMISE"===d[n].type?d[n]:u.when(d[n]):s.hasOwnProperty(n)?s[n]&&"JEEFO_PROMISE"===s[n].type?s[n]:u.when(s[n]):(t=o(n,function(e){return f&&f.hasOwnProperty(e)?f[e].dependencies:c.hasOwnProperty(e)?c[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),u.for_each_async(t,function(n,r,t){var o,u;if(d.hasOwnProperty(n)||s.hasOwnProperty(n))return t();f&&f.hasOwnProperty(n)?(o=d,u=f[n]):(o=s,u=c[n]);for(var a=u.dependencies.length-1,p=new e(a+1);a>=0;--a)d.hasOwnProperty(u.dependencies[a])?p[a]=d[u.dependencies[a]]:s.hasOwnProperty(u.dependencies[a])?p[a]=s[u.dependencies[a]]:i("OMG");var h=u.fn.apply(null,p);u.is_constructor&&(h=new h),h&&"JEEFO_PROMISE"===h.type?h.then(function(e){o[n]=e,t()}):(o[n]=h,t())}).then(function(){return d.hasOwnProperty(n)?d[n]:s[n]}))},resolve_sync:function(n,r){var t,s=this,u=s.values,c=r&&r.values||{},d=s.definitions,f=r&&r.definitions;if(c.hasOwnProperty(n))return c[n];if(u.hasOwnProperty(n))return u[n];f&&f.hasOwnProperty(n)?t=c:d.hasOwnProperty(n)&&(t=u);for(var a=o(n,function(e){return f&&f.hasOwnProperty(e)?f[e].dependencies:d.hasOwnProperty(e)?d[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),p=d[a.pop()],h=new e(p.dependencies.length),l=0;l<a.length;++l)c.hasOwnProperty(a[l])||u.hasOwnProperty(a[l])||s.resolve_sync(a[l],r);for(l=h.length-1;l>=0;--l)h[l]=c.hasOwnProperty(p.dependencies[l])?c[p.dependencies[l]]:u[p.dependencies[l]];return t[n]=p.fn.apply(null,h)}};var f=function(e,n,r,t){function o(e){return"$injector"===e||p.hasOwnProperty(e)||a.hasOwnProperty(e)}function s(r,s){return o(r)&&i("Duplicated provider '"+r+"' detected in module '"+e+"'."),n.register(r,s),t[r]=n.definitions[r],f}function c(t){return p.hasOwnProperty(t)?u.when(p[t]):a.hasOwnProperty(t)?n.resolve(t,r):void i("Module provider '"+t+"' definition is not found in '"+e+"' module.")}function d(t){return p.hasOwnProperty(t)?p[t]:a.hasOwnProperty(t)?n.resolve_sync(t,r):void i("Module provider '"+t+"' definition is not found in '"+e+"' module.")}var f=this,a=n.definitions,p=r.values;return f.has=o,f.resolve=c,f.register=s,f.resolve_sync=d,f},a={dependencies:d},p=function(n,r,t){if("function"===typeof r)return{fn:r,name:n,dependencies:d};if("string"===typeof r)return{fn:t,name:n,dependencies:[r]};for(var i=r.length-1,o=new e(i+1);i>=0;o[i]=r[i],--i);return{fn:t,name:n,dependencies:o}},h={values:{$q:u,Array:e,is_array:n,Injector:c,"object.keys":r,"object.assign":t,make_injectable:p,"sorts.topological":o},definitions:{$q:a,Array:a,is_array:a,Injector:a,"object.keys":a,"object.assign":a,make_injectable:a,"sorts.topological":a}},l=function(n,r,s){function a(){return m}function l(){var e=arguments[0],r=p.apply(null,arguments);return O.hasOwnProperty(e)&&i("'"+e+"' extends already registered in '"+n+"' module."),_[g++]=r,y(O,r),O}function y(n,r){var t=new e(r.dependencies.length);u.for_each_async(r.dependencies,function(e,n,r){m.resolve(e).then(function(e){t[n]=e,r()})}).then(function(){n[r.name]=r.fn.apply(n,t)})}var v,w,O={$name:n,extend:l},P=new c,_=[],g=0,E={},m=new f(n,P,h,E),j=[];for(w=o(n,function(e){return s[e]?s[e].requires:n===e?r:void i("'"+e+"' module is not found.")}),w.pop(),O.$included_modules=w,v=0;v<w.length;++v)j=j.concat(s[w[v]].extenders),t(P.definitions,s[w[v]].new_definitions);for(P.definitions.$injector={fn:a,dependencies:d},s[n]={name:n,requires:r,instance:O,injector:P,extenders:_,public_injector:m,new_definitions:E},v=0;v<j.length;++v)y(O,j[v]);return O},y=function(){};return y.prototype={use:function(e){return e(this),this}},{create:function(){function e(e,t){return n(t)?(r.hasOwnProperty(e)&&i("Duplicated module '"+e+"' is detected."),l(e,t,r)):(r.hasOwnProperty(e)||i("'"+e+"' module is not found."),r[e].instance)}var r={},t=new y;return t.module=e,t}}}();window.jeefo=e.create()}(); | ||
!function(){"use strict";var e=function(){var e=Array,n=e.isArray,r=Object.keys,t=function(e){for(var n,t,i,o=1;o<arguments.length;++o)if(n=arguments[o])for(t=r(n),i=t.length-1;i>=0;e[t[i]]=n[t[i]],--i);return e},i=function(e){throw new Error(e)},o=function(n,r){var t=[],o={};return function s(u,c){for(var d=c.length-1,a=new e(d+1),f=r(u);d>=0;a[d]=c[d],--d);for(a.push(u),o[u]=!0,d=0;d<f.length;++d)a.indexOf(f[d])>=0&&i("Circular dependency '"+f[d]+" is required by '"+n+"' : "+a.join(" -> ")),o.hasOwnProperty(f[d])||s(f[d],a);-1===t.indexOf(u)&&t.push(u)}(n,[]),t},s=function(e){function n(){return 0===u}function r(e){if(0===u){u=2,d.state="rejected",d.reason=o=e;for(var n=1;n<a;n+=4)e=c[n](o),e&&"JEEFO_PROMISE"===e.type?e.then(c[n+1],c[n+2]):c[n+2](e);c=null,a=0}}function t(e,n){return new s(function(r,t){switch(u){case 1:var i=e(o);return i&&"JEEFO_PROMISE"===i.type?i.then(r,t):r(i);case 2:return n?r(n(o)):t(o);default:c[a]=e,c[a+1]=n,c[a+2]=r,c[a+3]=t,a+=4}})}function i(e){return new s(function(n,r){switch(u){case 2:return n(e(o));default:c[a]=null,c[a+1]=e,c[a+2]=null,c[a+3]=r,a+=4}})}var o,u=0,c=[],d=this,a=0;d.then=t,d.$catch=i,d.state="pending...",d.is_pending=n;try{e(function(e){if(0===u){u=1,d.state="resolved",d.value=o=e;for(var n=0;n<a;n+=4)e=c[n](o),e&&"JEEFO_PROMISE"===e.type?e.then(c[n+2],c[n+3]):c[n+2](e);c=null,a=0}},r)}catch(e){r(e)}return d};s.prototype.type="JEEFO_PROMISE";var u={defer:function(){var e={};return e.promise=new s(function(n,r){e.resolve=n,e.reject=r}),e},when:function(e){return e&&"JEEFO_PROMISE"===e.type?e:new s(function(n){n(e)})},for_each_async:function(e,n){function r(){++t<e.length?n.call(e,e[t],t,r,e):i.resolve()}var t=-1,i=this.defer();return r(),i.promise},all:function(e){for(var n,r=0,t=this.defer(),i=0;r<e.length;++r)(n=e[r])&&"JEEFO_PROMISE"===n.type&&(i+=1,n.then(function(n){return function(r){e[n]=r,0===--i&&t.resolve(e)}}(r)));return 0===i&&t.resolve(e),t.promise}},c=function(e){this.values=t({},e),this.definitions={}},d=[];c.prototype={register:function(n,r){if(r.dependencies){for(var t=new e(r.dependencies.length),o=t.length-1;o>=0;t[o]=r.dependencies[o],--o);(this.values.hasOwnProperty(n)||this.definitions.hasOwnProperty(n))&&i("Duplicated provider "+n+" detected."),this.definitions[n]={fn:r.fn,dependencies:t,is_constructor:!!r.is_constructor}}else this.definitions[n]={fn:r.fn,dependencies:d,is_constructor:!!r.is_constructor};return this},resolve:function(n,r){var t,s=this.values,c=this.definitions,d=r&&r.values||{},a=r&&r.definitions;return d.hasOwnProperty(n)?d[n]&&"JEEFO_PROMISE"===d[n].type?d[n]:u.when(d[n]):s.hasOwnProperty(n)?s[n]&&"JEEFO_PROMISE"===s[n].type?s[n]:u.when(s[n]):(t=o(n,function(e){return a&&a.hasOwnProperty(e)?a[e].dependencies:c.hasOwnProperty(e)?c[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),u.for_each_async(t,function(n,r,t){var o,u;if(d.hasOwnProperty(n)||s.hasOwnProperty(n))return t();a&&a.hasOwnProperty(n)?(o=d,u=a[n]):(o=s,u=c[n]);for(var f=u.dependencies.length-1,p=new e(f+1);f>=0;--f)d.hasOwnProperty(u.dependencies[f])?p[f]=d[u.dependencies[f]]:s.hasOwnProperty(u.dependencies[f])?p[f]=s[u.dependencies[f]]:i("OMG");var h=u.fn.apply(null,p);u.is_constructor&&(h=new h),h&&"JEEFO_PROMISE"===h.type?h.then(function(e){o[n]=e,t()}):(o[n]=h,t())}).then(function(){return d.hasOwnProperty(n)?d[n]:s[n]}))},resolve_sync:function(n,r){var t,s=this,u=s.values,c=r&&r.values||{},d=s.definitions,a=r&&r.definitions;if(c.hasOwnProperty(n))return c[n];if(u.hasOwnProperty(n))return u[n];a&&a.hasOwnProperty(n)?t=c:d.hasOwnProperty(n)&&(t=u);for(var f=o(n,function(e){return a&&a.hasOwnProperty(e)?a[e].dependencies:d.hasOwnProperty(e)?d[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),p=d[f.pop()],h=new e(p.dependencies.length),l=0;l<f.length;++l)c.hasOwnProperty(f[l])||u.hasOwnProperty(f[l])||s.resolve_sync(f[l],r);for(l=h.length-1;l>=0;--l)h[l]=c.hasOwnProperty(p.dependencies[l])?c[p.dependencies[l]]:u[p.dependencies[l]];return t[n]=p.fn.apply(null,h)}};var a=function(e,n,r,t){function o(e){return"$injector"===e||p.hasOwnProperty(e)||f.hasOwnProperty(e)}function s(r,s){return o(r)&&i("Duplicated provider '"+r+"' detected in module '"+e+"'."),n.register(r,s),t[r]=n.definitions[r],a}function c(t){return p.hasOwnProperty(t)?u.when(p[t]):f.hasOwnProperty(t)?n.resolve(t,r):void i("Module provider '"+t+"' definition is not found in '"+e+"' module.")}function d(t){return p.hasOwnProperty(t)?p[t]:f.hasOwnProperty(t)?n.resolve_sync(t,r):void i("Module provider '"+t+"' definition is not found in '"+e+"' module.")}var a=this,f=n.definitions,p=r.values;return a.has=o,a.resolve=c,a.register=s,a.resolve_sync=d,a},f={dependencies:d},p=function(n,r,t){if("function"===typeof r)return{fn:r,name:n,dependencies:d};if("string"===typeof r)return{fn:t,name:n,dependencies:[r]};for(var i=r.length-1,o=new e(i+1);i>=0;o[i]=r[i],--i);return{fn:t,name:n,dependencies:o}},h={values:{$q:u,Array:e,is_array:n,Injector:c,"object.keys":r,"object.assign":t,make_injectable:p,"sorts.topological":o},definitions:{$q:f,Array:f,is_array:f,Injector:f,"object.keys":f,"object.assign":f,make_injectable:f,"sorts.topological":f}},l=function(n,r,s){function f(){return m}function l(){var e=arguments[0],r=p.apply(null,arguments);return O.hasOwnProperty(e)&&i("'"+e+"' extends already registered in '"+n+"' module."),_[E++]=r,y(O,r),O}function y(n,r){var t=new e(r.dependencies.length);u.for_each_async(r.dependencies,function(e,n,r){m.resolve(e).then(function(e){t[n]=e,r()})}).then(function(){n[r.name]=r.fn.apply(n,t)})}var v,w,O={$name:n,extend:l},P=new c,_=[],E=0,g={},m=new a(n,P,h,g),j=[];for(w=o(n,function(e){return s[e]?s[e].requires:n===e?r:void i("'"+e+"' module is not found.")}),w.pop(),O.$included_modules=w,v=0;v<w.length;++v)j=j.concat(s[w[v]].extenders),t(P.definitions,s[w[v]].new_definitions);for(P.definitions.$injector={fn:f,dependencies:d},s[n]={name:n,requires:r,instance:O,injector:P,extenders:_,public_injector:m,new_definitions:g},v=0;v<j.length;++v)y(O,j[v]);return O},y=function(){};return y.prototype={use:function(e){return e(this),this}},{create:function(){function e(e,t){return n(t)?(r.hasOwnProperty(e)&&i("Duplicated module '"+e+"' is detected."),l(e,t,r)):(r.hasOwnProperty(e)||i("'"+e+"' module is not found."),r[e].instance)}var r={},t=new y;return t.module=e,t}}}();window.jeefo=e.create()}(); |
/** | ||
* jeefo : v0.0.20 | ||
* jeefo : v0.0.22 | ||
* Author : je3f0o, <je3f0o@gmail.com> | ||
@@ -89,3 +89,3 @@ * Homepage : https://github.com/je3f0o/jeefo | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-05-06 | ||
* Updated at : 2017-07-11 | ||
* Author : jeefo | ||
@@ -104,2 +104,3 @@ * Purpose : | ||
instance.then = then; | ||
instance.$catch = $catch; | ||
instance.state = "pending..."; | ||
@@ -109,21 +110,37 @@ instance.is_pending = is_pending; | ||
// Promise handler {{{2 | ||
promise_handler(function (value) { | ||
if (state !== 0) { return; } | ||
try { | ||
promise_handler(function (value) { | ||
if (state !== 0) { return; } | ||
state = 1; | ||
instance.state = "resolved"; | ||
instance.value = result = value; | ||
state = 1; | ||
instance.state = "resolved"; | ||
instance.value = result = value; | ||
for (var i = 0; i < pendings_length; i += 4) { | ||
value = pendings[i](result); | ||
for (var i = 0; i < pendings_length; i += 4) { | ||
value = pendings[i](result); | ||
if (value && value.type === "JEEFO_PROMISE") { | ||
value.then(pendings[i + 2], pendings[i + 3]); | ||
} else { | ||
pendings[i + 2](value); | ||
if (value && value.type === "JEEFO_PROMISE") { | ||
value.then(pendings[i + 2], pendings[i + 3]); | ||
} else { | ||
pendings[i + 2](value); | ||
} | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
}, function (reason) { | ||
pendings = null; | ||
pendings_length = 0; | ||
}, _rejector); | ||
} catch (e) { | ||
_rejector(e); | ||
} | ||
// }}}2 | ||
// jshint latedef : false | ||
return instance; | ||
// Is pending ? {{{2 | ||
function is_pending () { | ||
return state === 0; | ||
} | ||
// Rejector {{{2 | ||
function _rejector (reason) { | ||
if (state !== 0) { return; } | ||
@@ -146,11 +163,2 @@ | ||
pendings_length = 0; | ||
}); | ||
// }}}2 | ||
// jshint latedef : false | ||
return instance; | ||
// Is pending ? {{{2 | ||
function is_pending () { | ||
return state === 0; | ||
} | ||
@@ -163,5 +171,12 @@ | ||
case 1 : | ||
return next_resolver(resolver(result)); | ||
var next_result = resolver(result); | ||
if (next_result && next_result.type === "JEEFO_PROMISE") { | ||
return next_result.then(next_resolver, next_rejector); | ||
} | ||
return next_resolver(next_result); | ||
case 2 : | ||
return next_rejector(rejector(result)); | ||
if (rejector) { | ||
return next_resolver(rejector(result)); | ||
} | ||
return next_rejector(result); | ||
default: | ||
@@ -176,2 +191,18 @@ pendings[pendings_length ] = resolver; | ||
} | ||
// Catch {{{2 | ||
function $catch (rejector) { | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
switch (state) { | ||
case 2 : | ||
return next_resolver(rejector(result)); | ||
default: | ||
pendings[pendings_length ] = null; | ||
pendings[pendings_length + 1] = rejector; | ||
pendings[pendings_length + 2] = null; | ||
pendings[pendings_length + 3] = next_rejector; | ||
pendings_length += 4; | ||
} | ||
}); | ||
} | ||
// }}}2 | ||
@@ -178,0 +209,0 @@ // jshint latedef : true |
/** | ||
* jeefo : v0.0.20 | ||
* jeefo : v0.0.22 | ||
* Author : je3f0o, <je3f0o@gmail.com> | ||
@@ -8,2 +8,2 @@ * Homepage : https://github.com/je3f0o/jeefo | ||
**/ | ||
"use strict";module.exports=function(){var e=Array,n=e.isArray,r=Object.keys,t=function(e){for(var n,t,i,o=1;o<arguments.length;++o)if(n=arguments[o])for(t=r(n),i=t.length-1;i>=0;e[t[i]]=n[t[i]],--i);return e},i=function(e){throw new Error(e)},o=function(n,r){var t=[],o={};return function s(u,c){for(var d=c.length-1,f=new e(d+1),a=r(u);d>=0;f[d]=c[d],--d);for(f.push(u),o[u]=!0,d=0;d<a.length;++d)f.indexOf(a[d])>=0&&i("Circular dependency '"+a[d]+" is required by '"+n+"' : "+f.join(" -> ")),o.hasOwnProperty(a[d])||s(a[d],f);-1===t.indexOf(u)&&t.push(u)}(n,[]),t},s=function(e){function n(){return 0===i}function r(e,n){return new s(function(r,s){switch(i){case 1:return r(e(t));case 2:return s(n(t));default:o[c]=e,o[c+1]=n,o[c+2]=r,o[c+3]=s,c+=4}})}var t,i=0,o=[],u=this,c=0;return u.then=r,u.state="pending...",u.is_pending=n,e(function(e){if(0===i){i=1,u.state="resolved",u.value=t=e;for(var n=0;n<c;n+=4)e=o[n](t),e&&"JEEFO_PROMISE"===e.type?e.then(o[n+2],o[n+3]):o[n+2](e);o=null,c=0}},function(e){if(0===i){i=2,u.state="rejected",u.reason=t=e;for(var n=1;n<c;n+=4)e=o[n](t),e&&"JEEFO_PROMISE"===e.type?e.then(o[n+1],o[n+2]):o[n+2](e);o=null,c=0}}),u};s.prototype.type="JEEFO_PROMISE";var u={defer:function(){var e={};return e.promise=new s(function(n,r){e.resolve=n,e.reject=r}),e},when:function(e){return e&&"JEEFO_PROMISE"===e.type?e:new s(function(n){n(e)})},for_each_async:function(e,n){function r(){++t<e.length?n.call(e,e[t],t,r,e):i.resolve()}var t=-1,i=this.defer();return r(),i.promise},all:function(e){for(var n,r=0,t=this.defer(),i=0;r<e.length;++r)(n=e[r])&&"JEEFO_PROMISE"===n.type&&(i+=1,n.then(function(n){return function(r){e[n]=r,0===--i&&t.resolve(e)}}(r)));return 0===i&&t.resolve(e),t.promise}},c=function(e){this.values=t({},e),this.definitions={}},d=[];c.prototype={register:function(n,r){if(r.dependencies){for(var t=new e(r.dependencies.length),o=t.length-1;o>=0;t[o]=r.dependencies[o],--o);(this.values.hasOwnProperty(n)||this.definitions.hasOwnProperty(n))&&i("Duplicated provider "+n+" detected."),this.definitions[n]={fn:r.fn,dependencies:t,is_constructor:!!r.is_constructor}}else this.definitions[n]={fn:r.fn,dependencies:d,is_constructor:!!r.is_constructor};return this},resolve:function(n,r){var t,s=this.values,c=this.definitions,d=r&&r.values||{},f=r&&r.definitions;return d.hasOwnProperty(n)?d[n]&&"JEEFO_PROMISE"===d[n].type?d[n]:u.when(d[n]):s.hasOwnProperty(n)?s[n]&&"JEEFO_PROMISE"===s[n].type?s[n]:u.when(s[n]):(t=o(n,function(e){return f&&f.hasOwnProperty(e)?f[e].dependencies:c.hasOwnProperty(e)?c[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),u.for_each_async(t,function(n,r,t){var o,u;if(d.hasOwnProperty(n)||s.hasOwnProperty(n))return t();f&&f.hasOwnProperty(n)?(o=d,u=f[n]):(o=s,u=c[n]);for(var a=u.dependencies.length-1,p=new e(a+1);a>=0;--a)d.hasOwnProperty(u.dependencies[a])?p[a]=d[u.dependencies[a]]:s.hasOwnProperty(u.dependencies[a])?p[a]=s[u.dependencies[a]]:i("OMG");var h=u.fn.apply(null,p);u.is_constructor&&(h=new h),h&&"JEEFO_PROMISE"===h.type?h.then(function(e){o[n]=e,t()}):(o[n]=h,t())}).then(function(){return d.hasOwnProperty(n)?d[n]:s[n]}))},resolve_sync:function(n,r){var t,s=this,u=s.values,c=r&&r.values||{},d=s.definitions,f=r&&r.definitions;if(c.hasOwnProperty(n))return c[n];if(u.hasOwnProperty(n))return u[n];f&&f.hasOwnProperty(n)?t=c:d.hasOwnProperty(n)&&(t=u);for(var a=o(n,function(e){return f&&f.hasOwnProperty(e)?f[e].dependencies:d.hasOwnProperty(e)?d[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),p=d[a.pop()],h=new e(p.dependencies.length),l=0;l<a.length;++l)c.hasOwnProperty(a[l])||u.hasOwnProperty(a[l])||s.resolve_sync(a[l],r);for(l=h.length-1;l>=0;--l)h[l]=c.hasOwnProperty(p.dependencies[l])?c[p.dependencies[l]]:u[p.dependencies[l]];return t[n]=p.fn.apply(null,h)}};var f=function(e,n,r,t){function o(e){return"$injector"===e||p.hasOwnProperty(e)||a.hasOwnProperty(e)}function s(r,s){return o(r)&&i("Duplicated provider '"+r+"' detected in module '"+e+"'."),n.register(r,s),t[r]=n.definitions[r],f}function c(t){return p.hasOwnProperty(t)?u.when(p[t]):a.hasOwnProperty(t)?n.resolve(t,r):void i("Module provider '"+t+"' definition is not found in '"+e+"' module.")}function d(t){return p.hasOwnProperty(t)?p[t]:a.hasOwnProperty(t)?n.resolve_sync(t,r):void i("Module provider '"+t+"' definition is not found in '"+e+"' module.")}var f=this,a=n.definitions,p=r.values;return f.has=o,f.resolve=c,f.register=s,f.resolve_sync=d,f},a={dependencies:d},p=function(n,r,t){if("function"===typeof r)return{fn:r,name:n,dependencies:d};if("string"===typeof r)return{fn:t,name:n,dependencies:[r]};for(var i=r.length-1,o=new e(i+1);i>=0;o[i]=r[i],--i);return{fn:t,name:n,dependencies:o}},h={values:{$q:u,Array:e,is_array:n,Injector:c,"object.keys":r,"object.assign":t,make_injectable:p,"sorts.topological":o},definitions:{$q:a,Array:a,is_array:a,Injector:a,"object.keys":a,"object.assign":a,make_injectable:a,"sorts.topological":a}},l=function(n,r,s){function a(){return m}function l(){var e=arguments[0],r=p.apply(null,arguments);return O.hasOwnProperty(e)&&i("'"+e+"' extends already registered in '"+n+"' module."),_[g++]=r,y(O,r),O}function y(n,r){var t=new e(r.dependencies.length);u.for_each_async(r.dependencies,function(e,n,r){m.resolve(e).then(function(e){t[n]=e,r()})}).then(function(){n[r.name]=r.fn.apply(n,t)})}var v,w,O={$name:n,extend:l},P=new c,_=[],g=0,E={},m=new f(n,P,h,E),j=[];for(w=o(n,function(e){return s[e]?s[e].requires:n===e?r:void i("'"+e+"' module is not found.")}),w.pop(),O.$included_modules=w,v=0;v<w.length;++v)j=j.concat(s[w[v]].extenders),t(P.definitions,s[w[v]].new_definitions);for(P.definitions.$injector={fn:a,dependencies:d},s[n]={name:n,requires:r,instance:O,injector:P,extenders:_,public_injector:m,new_definitions:E},v=0;v<j.length;++v)y(O,j[v]);return O},y=function(){};return y.prototype={use:function(e){return e(this),this}},{create:function(){function e(e,t){return n(t)?(r.hasOwnProperty(e)&&i("Duplicated module '"+e+"' is detected."),l(e,t,r)):(r.hasOwnProperty(e)||i("'"+e+"' module is not found."),r[e].instance)}var r={},t=new y;return t.module=e,t}}}(); | ||
"use strict";module.exports=function(){var e=Array,n=e.isArray,r=Object.keys,t=function(e){for(var n,t,i,o=1;o<arguments.length;++o)if(n=arguments[o])for(t=r(n),i=t.length-1;i>=0;e[t[i]]=n[t[i]],--i);return e},i=function(e){throw new Error(e)},o=function(n,r){var t=[],o={};return function s(u,c){for(var d=c.length-1,a=new e(d+1),f=r(u);d>=0;a[d]=c[d],--d);for(a.push(u),o[u]=!0,d=0;d<f.length;++d)a.indexOf(f[d])>=0&&i("Circular dependency '"+f[d]+" is required by '"+n+"' : "+a.join(" -> ")),o.hasOwnProperty(f[d])||s(f[d],a);-1===t.indexOf(u)&&t.push(u)}(n,[]),t},s=function(e){function n(){return 0===u}function r(e){if(0===u){u=2,d.state="rejected",d.reason=o=e;for(var n=1;n<a;n+=4)e=c[n](o),e&&"JEEFO_PROMISE"===e.type?e.then(c[n+1],c[n+2]):c[n+2](e);c=null,a=0}}function t(e,n){return new s(function(r,t){switch(u){case 1:var i=e(o);return i&&"JEEFO_PROMISE"===i.type?i.then(r,t):r(i);case 2:return n?r(n(o)):t(o);default:c[a]=e,c[a+1]=n,c[a+2]=r,c[a+3]=t,a+=4}})}function i(e){return new s(function(n,r){switch(u){case 2:return n(e(o));default:c[a]=null,c[a+1]=e,c[a+2]=null,c[a+3]=r,a+=4}})}var o,u=0,c=[],d=this,a=0;d.then=t,d.$catch=i,d.state="pending...",d.is_pending=n;try{e(function(e){if(0===u){u=1,d.state="resolved",d.value=o=e;for(var n=0;n<a;n+=4)e=c[n](o),e&&"JEEFO_PROMISE"===e.type?e.then(c[n+2],c[n+3]):c[n+2](e);c=null,a=0}},r)}catch(e){r(e)}return d};s.prototype.type="JEEFO_PROMISE";var u={defer:function(){var e={};return e.promise=new s(function(n,r){e.resolve=n,e.reject=r}),e},when:function(e){return e&&"JEEFO_PROMISE"===e.type?e:new s(function(n){n(e)})},for_each_async:function(e,n){function r(){++t<e.length?n.call(e,e[t],t,r,e):i.resolve()}var t=-1,i=this.defer();return r(),i.promise},all:function(e){for(var n,r=0,t=this.defer(),i=0;r<e.length;++r)(n=e[r])&&"JEEFO_PROMISE"===n.type&&(i+=1,n.then(function(n){return function(r){e[n]=r,0===--i&&t.resolve(e)}}(r)));return 0===i&&t.resolve(e),t.promise}},c=function(e){this.values=t({},e),this.definitions={}},d=[];c.prototype={register:function(n,r){if(r.dependencies){for(var t=new e(r.dependencies.length),o=t.length-1;o>=0;t[o]=r.dependencies[o],--o);(this.values.hasOwnProperty(n)||this.definitions.hasOwnProperty(n))&&i("Duplicated provider "+n+" detected."),this.definitions[n]={fn:r.fn,dependencies:t,is_constructor:!!r.is_constructor}}else this.definitions[n]={fn:r.fn,dependencies:d,is_constructor:!!r.is_constructor};return this},resolve:function(n,r){var t,s=this.values,c=this.definitions,d=r&&r.values||{},a=r&&r.definitions;return d.hasOwnProperty(n)?d[n]&&"JEEFO_PROMISE"===d[n].type?d[n]:u.when(d[n]):s.hasOwnProperty(n)?s[n]&&"JEEFO_PROMISE"===s[n].type?s[n]:u.when(s[n]):(t=o(n,function(e){return a&&a.hasOwnProperty(e)?a[e].dependencies:c.hasOwnProperty(e)?c[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),u.for_each_async(t,function(n,r,t){var o,u;if(d.hasOwnProperty(n)||s.hasOwnProperty(n))return t();a&&a.hasOwnProperty(n)?(o=d,u=a[n]):(o=s,u=c[n]);for(var f=u.dependencies.length-1,p=new e(f+1);f>=0;--f)d.hasOwnProperty(u.dependencies[f])?p[f]=d[u.dependencies[f]]:s.hasOwnProperty(u.dependencies[f])?p[f]=s[u.dependencies[f]]:i("OMG");var l=u.fn.apply(null,p);u.is_constructor&&(l=new l),l&&"JEEFO_PROMISE"===l.type?l.then(function(e){o[n]=e,t()}):(o[n]=l,t())}).then(function(){return d.hasOwnProperty(n)?d[n]:s[n]}))},resolve_sync:function(n,r){var t,s=this,u=s.values,c=r&&r.values||{},d=s.definitions,a=r&&r.definitions;if(c.hasOwnProperty(n))return c[n];if(u.hasOwnProperty(n))return u[n];a&&a.hasOwnProperty(n)?t=c:d.hasOwnProperty(n)&&(t=u);for(var f=o(n,function(e){return a&&a.hasOwnProperty(e)?a[e].dependencies:d.hasOwnProperty(e)?d[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),p=d[f.pop()],l=new e(p.dependencies.length),h=0;h<f.length;++h)c.hasOwnProperty(f[h])||u.hasOwnProperty(f[h])||s.resolve_sync(f[h],r);for(h=l.length-1;h>=0;--h)l[h]=c.hasOwnProperty(p.dependencies[h])?c[p.dependencies[h]]:u[p.dependencies[h]];return t[n]=p.fn.apply(null,l)}};var a=function(e,n,r,t){function o(e){return"$injector"===e||p.hasOwnProperty(e)||f.hasOwnProperty(e)}function s(r,s){return o(r)&&i("Duplicated provider '"+r+"' detected in module '"+e+"'."),n.register(r,s),t[r]=n.definitions[r],a}function c(t){return p.hasOwnProperty(t)?u.when(p[t]):f.hasOwnProperty(t)?n.resolve(t,r):void i("Module provider '"+t+"' definition is not found in '"+e+"' module.")}function d(t){return p.hasOwnProperty(t)?p[t]:f.hasOwnProperty(t)?n.resolve_sync(t,r):void i("Module provider '"+t+"' definition is not found in '"+e+"' module.")}var a=this,f=n.definitions,p=r.values;return a.has=o,a.resolve=c,a.register=s,a.resolve_sync=d,a},f={dependencies:d},p=function(n,r,t){if("function"===typeof r)return{fn:r,name:n,dependencies:d};if("string"===typeof r)return{fn:t,name:n,dependencies:[r]};for(var i=r.length-1,o=new e(i+1);i>=0;o[i]=r[i],--i);return{fn:t,name:n,dependencies:o}},l={values:{$q:u,Array:e,is_array:n,Injector:c,"object.keys":r,"object.assign":t,make_injectable:p,"sorts.topological":o},definitions:{$q:f,Array:f,is_array:f,Injector:f,"object.keys":f,"object.assign":f,make_injectable:f,"sorts.topological":f}},h=function(n,r,s){function f(){return m}function h(){var e=arguments[0],r=p.apply(null,arguments);return O.hasOwnProperty(e)&&i("'"+e+"' extends already registered in '"+n+"' module."),_[E++]=r,y(O,r),O}function y(n,r){var t=new e(r.dependencies.length);u.for_each_async(r.dependencies,function(e,n,r){m.resolve(e).then(function(e){t[n]=e,r()})}).then(function(){n[r.name]=r.fn.apply(n,t)})}var v,w,O={$name:n,extend:h},P=new c,_=[],E=0,g={},m=new a(n,P,l,g),j=[];for(w=o(n,function(e){return s[e]?s[e].requires:n===e?r:void i("'"+e+"' module is not found.")}),w.pop(),O.$included_modules=w,v=0;v<w.length;++v)j=j.concat(s[w[v]].extenders),t(P.definitions,s[w[v]].new_definitions);for(P.definitions.$injector={fn:f,dependencies:d},s[n]={name:n,requires:r,instance:O,injector:P,extenders:_,public_injector:m,new_definitions:g},v=0;v<j.length;++v)y(O,j[v]);return O},y=function(){};return y.prototype={use:function(e){return e(this),this}},{create:function(){function e(e,t){return n(t)?(r.hasOwnProperty(e)&&i("Duplicated module '"+e+"' is detected."),h(e,t,r)):(r.hasOwnProperty(e)||i("'"+e+"' module is not found."),r[e].instance)}var r={},t=new y;return t.module=e,t}}}(); |
{ | ||
"name": "jeefo", | ||
"version": "0.0.20", | ||
"version": "0.0.22", | ||
"homepage": "https://github.com/je3f0o/jeefo", | ||
@@ -5,0 +5,0 @@ "copyright": "2016", |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : promise.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-05-06 | ||
* Updated at : 2017-07-11 | ||
* Author : jeefo | ||
@@ -10,6 +10,4 @@ * Purpose : | ||
//ignore:start | ||
"use strict"; | ||
/* globals -PP, -IS_DEFINED */ | ||
/* exported */ | ||
/* exported $q */ | ||
@@ -41,2 +39,3 @@ | ||
instance.then = then; | ||
instance.$catch = $catch; | ||
instance.state = PENDING_STATE; | ||
@@ -46,21 +45,37 @@ instance.is_pending = is_pending; | ||
// Promise handler {{{2 | ||
promise_handler(function (value) { | ||
if (state !== PENDING_STATE_ENUM) { return; } | ||
try { | ||
promise_handler(function (value) { | ||
if (state !== PENDING_STATE_ENUM) { return; } | ||
state = RESOLVED_STATE_ENUM; | ||
instance.state = RESOLVED_STATE; | ||
instance.value = result = value; | ||
state = RESOLVED_STATE_ENUM; | ||
instance.state = RESOLVED_STATE; | ||
instance.value = result = value; | ||
for (var i = 0; i < pendings_length; i += 4) { | ||
value = pendings[i](result); | ||
for (var i = 0; i < pendings_length; i += 4) { | ||
value = pendings[i](result); | ||
if (IS_JEEFO_PROMISE(value)) { | ||
value.then(pendings[i + 2], pendings[i + 3]); | ||
} else { | ||
pendings[i + 2](value); | ||
if (IS_JEEFO_PROMISE(value)) { | ||
value.then(pendings[i + 2], pendings[i + 3]); | ||
} else { | ||
pendings[i + 2](value); | ||
} | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
}, function (reason) { | ||
pendings = null; | ||
pendings_length = 0; | ||
}, _rejector); | ||
} catch (e) { | ||
_rejector(e); | ||
} | ||
// }}}2 | ||
// jshint latedef : false | ||
return instance; | ||
// Is pending ? {{{2 | ||
function is_pending () { | ||
return state === PENDING_STATE_ENUM; | ||
} | ||
// Rejector {{{2 | ||
function _rejector (reason) { | ||
if (state !== PENDING_STATE_ENUM) { return; } | ||
@@ -83,11 +98,2 @@ | ||
pendings_length = 0; | ||
}); | ||
// }}}2 | ||
// jshint latedef : false | ||
return instance; | ||
// Is pending ? {{{2 | ||
function is_pending () { | ||
return state === PENDING_STATE_ENUM; | ||
} | ||
@@ -100,5 +106,12 @@ | ||
case RESOLVED_STATE_ENUM : | ||
return next_resolver(resolver(result)); | ||
var next_result = resolver(result); | ||
if (IS_JEEFO_PROMISE(next_result)) { | ||
return next_result.then(next_resolver, next_rejector); | ||
} | ||
return next_resolver(next_result); | ||
case REJECTED_STATE_ENUM : | ||
return next_rejector(rejector(result)); | ||
if (rejector) { | ||
return next_resolver(rejector(result)); | ||
} | ||
return next_rejector(result); | ||
default: | ||
@@ -113,2 +126,18 @@ pendings[pendings_length ] = resolver; | ||
} | ||
// Catch {{{2 | ||
function $catch (rejector) { | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
switch (state) { | ||
case REJECTED_STATE_ENUM : | ||
return next_resolver(rejector(result)); | ||
default: | ||
pendings[pendings_length ] = null; | ||
pendings[pendings_length + 1] = rejector; | ||
pendings[pendings_length + 2] = null; | ||
pendings[pendings_length + 3] = next_rejector; | ||
pendings_length += 4; | ||
} | ||
}); | ||
} | ||
// }}}2 | ||
@@ -115,0 +144,0 @@ // jshint latedef : true |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149576
3906