Comparing version 0.0.23 to 0.0.24
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : index.js | ||
* Created at : 2017-04-29 | ||
* Updated at : 2017-05-07 | ||
* Updated at : 2017-07-11 | ||
* Author : jeefo | ||
@@ -48,8 +48,7 @@ * Purpose : | ||
var browser_source = `(function () {"use strict";var jeefo=(function(){ ${ source } }()); window.jeefo = jeefo.create(); }());`; | ||
var browser_source = `(function () { "use strict";\n\nvar jeefo = (function() {\n\n${ source }\n\n}());\n\nwindow.jeefo = jeefo.create();\n\n}());`; | ||
var node_source = `${ header }\n"use strict";\n\nmodule.exports = (function () {\n\n${ source }\n\n}());`; | ||
var node_min_source; | ||
browser_source = header + uglify.minify(browser_source, _package.uglify_config).code; | ||
node_min_source = header + uglify.minify(node_source, _package.uglify_config).code; | ||
var browser_min_source = header + uglify.minify(browser_source, _package.uglify_config).code, | ||
node_min_source = header + uglify.minify(node_source, _package.uglify_config).code; | ||
@@ -63,6 +62,6 @@ // Final step | ||
fse.outputFileSync(output_filename, `${ header }\n\n${ source }`); | ||
fse.outputFileSync(output_filename, `${ header }${ browser_source }`); | ||
fse.outputFileSync(node_filename, node_source); | ||
fse.outputFileSync(node_min_filename, node_min_source); | ||
fse.outputFileSync(browser_filename, browser_source); | ||
fse.outputFileSync(browser_filename, browser_min_source); | ||
@@ -69,0 +68,0 @@ console.log(`Raw source: ${ get_filesize(output_filename) } bytes.`); |
/** | ||
* jeefo : v0.0.23 | ||
* jeefo : v0.0.24 | ||
* Author : je3f0o, <je3f0o@gmail.com> | ||
@@ -8,3 +8,5 @@ * Homepage : https://github.com/je3f0o/jeefo | ||
**/ | ||
(function () { "use strict"; | ||
var jeefo = (function() { | ||
@@ -87,3 +89,3 @@ /* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-07-11 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -95,34 +97,21 @@ * Purpose : | ||
// JeefoPromise {{{1 | ||
var JeefoPromise = function (promise_handler) { | ||
var JeefoPromise = function (promise_handler, callback, args) { | ||
var state = 0, | ||
pendings = [], | ||
instance = this, | ||
pendings_length = 0, result; | ||
is_last_chain = true, | ||
pendings_length = 0, | ||
result; | ||
instance.then = then; | ||
instance.$catch = $catch; | ||
instance.state = "pending..."; | ||
instance.is_pending = is_pending; | ||
instance.then = then; | ||
instance.state = "pending..."; | ||
instance.$catch = $catch; | ||
instance.result = get_result; | ||
instance.is_pending = is_pending; | ||
instance.is_rejected = is_rejected; | ||
instance.is_resolved = is_resolved; | ||
// Promise handler {{{2 | ||
try { | ||
promise_handler(function (value) { | ||
if (state !== 0) { return; } | ||
state = 1; | ||
instance.state = "resolved"; | ||
instance.value = result = value; | ||
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); | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
}, _rejector); | ||
promise_handler(_resolver, _rejector); | ||
} catch (e) { | ||
@@ -141,2 +130,42 @@ _rejector(e); | ||
// Is rejected ? {{{2 | ||
function is_rejected () { | ||
return state === 2; | ||
} | ||
// Is rejected ? {{{2 | ||
function is_resolved () { | ||
return state === 1; | ||
} | ||
// Get result {{{2 | ||
function get_result () { | ||
return result; | ||
} | ||
// Resolver {{{2 | ||
function _resolver (value) { | ||
if (state !== 0) { return; } | ||
state = 1; | ||
instance.state = "resolved"; | ||
instance.value = result = value; | ||
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); | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
if (is_last_chain && callback) { | ||
callback.apply(null, args); | ||
} | ||
} | ||
// Rejector {{{2 | ||
@@ -161,2 +190,6 @@ function _rejector (reason) { | ||
pendings_length = 0; | ||
if (is_last_chain && callback) { | ||
callback.apply(null, args); | ||
} | ||
} | ||
@@ -166,2 +199,3 @@ | ||
function then (resolver, rejector) { | ||
is_last_chain = false; | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
@@ -181,4 +215,4 @@ switch (state) { | ||
default: | ||
pendings[pendings_length ] = resolver; | ||
pendings[pendings_length + 1] = rejector; | ||
pendings[pendings_length ] = resolver || get_result; | ||
pendings[pendings_length + 1] = rejector || get_result; | ||
pendings[pendings_length + 2] = next_resolver; | ||
@@ -188,3 +222,3 @@ pendings[pendings_length + 3] = next_rejector; | ||
} | ||
}); | ||
}, callback, args); | ||
} | ||
@@ -194,2 +228,3 @@ | ||
function $catch (rejector) { | ||
is_last_chain = false; | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
@@ -205,3 +240,3 @@ switch (state) { | ||
default: | ||
pendings[pendings_length ] = _resolver; | ||
pendings[pendings_length ] = get_result; | ||
pendings[pendings_length + 1] = rejector; | ||
@@ -212,7 +247,3 @@ pendings[pendings_length + 2] = next_resolver; | ||
} | ||
}); | ||
function _resolver () { | ||
return result; | ||
} | ||
}, callback, args); | ||
} | ||
@@ -234,2 +265,7 @@ // }}}2 | ||
}, | ||
reject : function (reason) { | ||
return new JeefoPromise(function (resolve, reject) { | ||
reject(reason); | ||
}); | ||
}, | ||
when : function (value) { | ||
@@ -256,3 +292,7 @@ // jshint latedef : false | ||
if (++index < items.length) { | ||
iterator.call(items, items[index], index, next, items); | ||
try { | ||
iterator.call(items, items[index], index, next, rejector); | ||
} catch (e) { | ||
rejector(e); | ||
} | ||
} else { | ||
@@ -262,2 +302,6 @@ deferred.resolve(); | ||
} | ||
function rejector (reason) { | ||
deferred.reject(reason); | ||
} | ||
// jshint latedef : true | ||
@@ -303,3 +347,3 @@ }, | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-05-10 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -311,4 +355,5 @@ * Purpose : | ||
// Injector {{{1 | ||
var JeefoInjector = function (values) { | ||
this.values = assign({}, values); | ||
var JeefoInjector = function (instance) { | ||
this.values = {}; | ||
this.instance = instance; | ||
this.definitions = {}; | ||
@@ -352,2 +397,3 @@ }; | ||
var values = this.values, | ||
instance = this.instance, | ||
definitions = this.definitions, | ||
@@ -399,3 +445,3 @@ local_values = (local && local.values) || {}, | ||
// Call definition handler, invoker | ||
var Result = definition.fn.apply(null, args); | ||
var Result = definition.fn.apply(instance, args); | ||
@@ -425,6 +471,5 @@ if (definition.is_constructor) { | ||
resolve_sync : function (name, local) { | ||
var self = this, | ||
values = self.values, | ||
var values = this.values, | ||
local_values = (local && local.values) || {}, | ||
definitions = self.definitions, | ||
definitions = this.definitions, | ||
local_definitions = local && local.definitions, | ||
@@ -461,3 +506,3 @@ container; | ||
if (! local_values.hasOwnProperty(execution_order[i]) && ! values.hasOwnProperty(execution_order[i])) { | ||
self.resolve_sync(execution_order[i], local); | ||
this.resolve_sync(execution_order[i], local); | ||
} | ||
@@ -472,3 +517,3 @@ } | ||
return (container[name] = definition.fn.apply(null, args)); | ||
return (container[name] = definition.fn.apply(this.instance, args)); | ||
}, | ||
@@ -482,3 +527,3 @@ // }}}2 | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-06-30 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -578,2 +623,3 @@ * Purpose : | ||
Injector : JeefoInjector, | ||
JeefoPromise : JeefoPromise, | ||
"object.keys" : object_keys, | ||
@@ -589,2 +635,3 @@ "object.assign" : assign, | ||
Injector : empty_dependencies, | ||
JeefoPromise : empty_dependencies, | ||
"object.keys" : empty_dependencies, | ||
@@ -603,3 +650,3 @@ "object.assign" : empty_dependencies, | ||
}, | ||
injector = new JeefoInjector(), | ||
injector = new JeefoInjector(instance), | ||
extenders = [], | ||
@@ -674,9 +721,11 @@ extends_length = 0, | ||
$q.for_each_async(injectable.dependencies, function (dependency, index, next) { | ||
$q.for_each_async(injectable.dependencies, function (dependency, index, next, rejector) { | ||
public_injector.resolve(dependency).then(function (value) { | ||
args[index] = value; | ||
next(); | ||
}); | ||
}).$catch(rejector); | ||
}).then(function () { | ||
instance[injectable.name] = injectable.fn.apply(instance, args); | ||
}).$catch(function (e) { | ||
console.error(e); | ||
}); | ||
@@ -728,2 +777,8 @@ } | ||
} | ||
}; | ||
}; | ||
}()); | ||
window.jeefo = jeefo.create(); | ||
}()); |
/** | ||
* jeefo : v0.0.23 | ||
* jeefo : v0.0.24 | ||
* 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(c,u){for(var d=u.length-1,a=new e(d+1),f=r(c);d>=0;a[d]=u[d],--d);for(a.push(c),o[c]=!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(c)&&t.push(c)}(n,[]),t},s=function(e){function n(){return 0===c}function r(e){if(0===c){c=2,d.state="rejected",d.reason=o=e;for(var n=1;n<a;n+=4)e=u[n](o),e&&"JEEFO_PROMISE"===e.type?e.then(u[n+1],u[n+2]):u[n+2](e);u=null,a=0}}function t(e,n){return new s(function(r,t){switch(c){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:u[a]=e,u[a+1]=n,u[a+2]=r,u[a+3]=t,a+=4}})}function i(e){function n(){return o}return new s(function(r,t){switch(c){case 1:return o&&"JEEFO_PROMISE"===o.type?o.then(r,t):r(o);case 2:return r(e(o));default:u[a]=n,u[a+1]=e,u[a+2]=r,u[a+3]=t,a+=4}})}var o,c=0,u=[],d=this,a=0;d.then=t,d.$catch=i,d.state="pending...",d.is_pending=n;try{e(function(e){if(0===c){c=1,d.state="resolved",d.value=o=e;for(var n=0;n<a;n+=4)e=u[n](o),e&&"JEEFO_PROMISE"===e.type?e.then(u[n+2],u[n+3]):u[n+2](e);u=null,a=0}},r)}catch(e){r(e)}return d};s.prototype.type="JEEFO_PROMISE";var c={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}},u=function(e){this.values=t({},e),this.definitions={}},d=[];u.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,u=this.definitions,d=r&&r.values||{},a=r&&r.definitions;return d.hasOwnProperty(n)?d[n]&&"JEEFO_PROMISE"===d[n].type?d[n]:c.when(d[n]):s.hasOwnProperty(n)?s[n]&&"JEEFO_PROMISE"===s[n].type?s[n]:c.when(s[n]):(t=o(n,function(e){return a&&a.hasOwnProperty(e)?a[e].dependencies:u.hasOwnProperty(e)?u[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),c.for_each_async(t,function(n,r,t){var o,c;if(d.hasOwnProperty(n)||s.hasOwnProperty(n))return t();a&&a.hasOwnProperty(n)?(o=d,c=a[n]):(o=s,c=u[n]);for(var f=c.dependencies.length-1,p=new e(f+1);f>=0;--f)d.hasOwnProperty(c.dependencies[f])?p[f]=d[c.dependencies[f]]:s.hasOwnProperty(c.dependencies[f])?p[f]=s[c.dependencies[f]]:i("OMG");var h=c.fn.apply(null,p);c.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,c=s.values,u=r&&r.values||{},d=s.definitions,a=r&&r.definitions;if(u.hasOwnProperty(n))return u[n];if(c.hasOwnProperty(n))return c[n];a&&a.hasOwnProperty(n)?t=u:d.hasOwnProperty(n)&&(t=c);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)u.hasOwnProperty(f[l])||c.hasOwnProperty(f[l])||s.resolve_sync(f[l],r);for(l=h.length-1;l>=0;--l)h[l]=u.hasOwnProperty(p.dependencies[l])?u[p.dependencies[l]]:c[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 u(t){return p.hasOwnProperty(t)?c.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=u,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:c,Array:e,is_array:n,Injector:u,"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);c.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 u,_=[],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()}(); | ||
!function(){"use strict";var e=function(){var e=Array,n=e.isArray,t=Object.keys,r=function(e){for(var n,r,i,o=1;o<arguments.length;++o)if(n=arguments[o])for(r=t(n),i=r.length-1;i>=0;e[r[i]]=n[r[i]],--i);return e},i=function(e){throw new Error(e)},o=function(n,t){var r=[],o={};return function s(c,u){for(var a=u.length-1,f=new e(a+1),d=t(c);a>=0;f[a]=u[a],--a);for(f.push(c),o[c]=!0,a=0;a<d.length;++a)f.indexOf(d[a])>=0&&i("Circular dependency '"+d[a]+" is required by '"+n+"' : "+f.join(" -> ")),o.hasOwnProperty(d[a])||s(d[a],f);-1===r.indexOf(c)&&r.push(c)}(n,[]),r},s=function(e,n,t){function r(){return 0===h}function i(){return 2===h}function o(){return 1===h}function c(){return p}function u(e){if(0===h){h=1,y.state="resolved",y.value=p=e;for(var r=0;r<w;r+=4)e=l[r](p),e&&"JEEFO_PROMISE"===e.type?e.then(l[r+2],l[r+3]):l[r+2](e);l=null,w=0,v&&n&&n.apply(null,t)}}function a(e){if(0===h){h=2,y.state="rejected",y.reason=p=e;for(var r=1;r<w;r+=4)e=l[r](p),e&&"JEEFO_PROMISE"===e.type?e.then(l[r+1],l[r+2]):l[r+2](e);l=null,w=0,v&&n&&n.apply(null,t)}}function f(e,r){return v=!1,new s(function(n,t){switch(h){case 1:var i=e(p);return i&&"JEEFO_PROMISE"===i.type?i.then(n,t):n(i);case 2:return r?n(r(p)):t(p);default:l[w]=e||c,l[w+1]=r||c,l[w+2]=n,l[w+3]=t,w+=4}},n,t)}function d(e){return v=!1,new s(function(n,t){switch(h){case 1:return p&&"JEEFO_PROMISE"===p.type?p.then(n,t):n(p);case 2:return n(e(p));default:l[w]=c,l[w+1]=e,l[w+2]=n,l[w+3]=t,w+=4}},n,t)}var p,h=0,l=[],y=this,v=!0,w=0;y.then=f,y.state="pending...",y.$catch=d,y.result=c,y.is_pending=r,y.is_rejected=i,y.is_resolved=o;try{e(u,a)}catch(e){a(e)}return y};s.prototype.type="JEEFO_PROMISE";var c={defer:function(){var e={};return e.promise=new s(function(n,t){e.resolve=n,e.reject=t}),e},reject:function(e){return new s(function(n,t){t(e)})},when:function(e){return e&&"JEEFO_PROMISE"===e.type?e:new s(function(n){n(e)})},for_each_async:function(e,n){function t(){if(++i<e.length)try{n.call(e,e[i],i,t,r)}catch(e){r(e)}else o.resolve()}function r(e){o.reject(e)}var i=-1,o=this.defer();return t(),o.promise},all:function(e){for(var n,t=0,r=this.defer(),i=0;t<e.length;++t)(n=e[t])&&"JEEFO_PROMISE"===n.type&&(i+=1,n.then(function(n){return function(t){e[n]=t,0===--i&&r.resolve(e)}}(t)));return 0===i&&r.resolve(e),r.promise}},u=function(e){this.values={},this.instance=e,this.definitions={}},a=[];u.prototype={register:function(n,t){if(t.dependencies){for(var r=new e(t.dependencies.length),o=r.length-1;o>=0;r[o]=t.dependencies[o],--o);(this.values.hasOwnProperty(n)||this.definitions.hasOwnProperty(n))&&i("Duplicated provider "+n+" detected."),this.definitions[n]={fn:t.fn,dependencies:r,is_constructor:!!t.is_constructor}}else this.definitions[n]={fn:t.fn,dependencies:a,is_constructor:!!t.is_constructor};return this},resolve:function(n,t){var r,s=this.values,u=this.instance,a=this.definitions,f=t&&t.values||{},d=t&&t.definitions;return f.hasOwnProperty(n)?f[n]&&"JEEFO_PROMISE"===f[n].type?f[n]:c.when(f[n]):s.hasOwnProperty(n)?s[n]&&"JEEFO_PROMISE"===s[n].type?s[n]:c.when(s[n]):(r=o(n,function(e){return d&&d.hasOwnProperty(e)?d[e].dependencies:a.hasOwnProperty(e)?a[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),c.for_each_async(r,function(n,t,r){var o,c;if(f.hasOwnProperty(n)||s.hasOwnProperty(n))return r();d&&d.hasOwnProperty(n)?(o=f,c=d[n]):(o=s,c=a[n]);for(var p=c.dependencies.length-1,h=new e(p+1);p>=0;--p)f.hasOwnProperty(c.dependencies[p])?h[p]=f[c.dependencies[p]]:s.hasOwnProperty(c.dependencies[p])?h[p]=s[c.dependencies[p]]:i("OMG");var l=c.fn.apply(u,h);c.is_constructor&&(l=new l),l&&"JEEFO_PROMISE"===l.type?l.then(function(e){o[n]=e,r()}):(o[n]=l,r())}).then(function(){return f.hasOwnProperty(n)?f[n]:s[n]}))},resolve_sync:function(n,t){var r,s=this.values,c=t&&t.values||{},u=this.definitions,a=t&&t.definitions;if(c.hasOwnProperty(n))return c[n];if(s.hasOwnProperty(n))return s[n];a&&a.hasOwnProperty(n)?r=c:u.hasOwnProperty(n)&&(r=s);for(var f=o(n,function(e){return a&&a.hasOwnProperty(e)?a[e].dependencies:u.hasOwnProperty(e)?u[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),d=u[f.pop()],p=new e(d.dependencies.length),h=0;h<f.length;++h)c.hasOwnProperty(f[h])||s.hasOwnProperty(f[h])||this.resolve_sync(f[h],t);for(h=p.length-1;h>=0;--h)p[h]=c.hasOwnProperty(d.dependencies[h])?c[d.dependencies[h]]:s[d.dependencies[h]];return r[n]=d.fn.apply(this.instance,p)}};var f=function(e,n,t,r){function o(e){return"$injector"===e||p.hasOwnProperty(e)||d.hasOwnProperty(e)}function s(t,s){return o(t)&&i("Duplicated provider '"+t+"' detected in module '"+e+"'."),n.register(t,s),r[t]=n.definitions[t],f}function u(r){return p.hasOwnProperty(r)?c.when(p[r]):d.hasOwnProperty(r)?n.resolve(r,t):void i("Module provider '"+r+"' definition is not found in '"+e+"' module.")}function a(r){return p.hasOwnProperty(r)?p[r]:d.hasOwnProperty(r)?n.resolve_sync(r,t):void i("Module provider '"+r+"' definition is not found in '"+e+"' module.")}var f=this,d=n.definitions,p=t.values;return f.has=o,f.resolve=u,f.register=s,f.resolve_sync=a,f},d={dependencies:a},p=function(n,t,r){if("function"===typeof t)return{fn:t,name:n,dependencies:a};if("string"===typeof t)return{fn:r,name:n,dependencies:[t]};for(var i=t.length-1,o=new e(i+1);i>=0;o[i]=t[i],--i);return{fn:r,name:n,dependencies:o}},h={values:{$q:c,Array:e,is_array:n,Injector:u,JeefoPromise:s,"object.keys":t,"object.assign":r,make_injectable:p,"sorts.topological":o},definitions:{$q:d,Array:d,is_array:d,Injector:d,JeefoPromise:d,"object.keys":d,"object.assign":d,make_injectable:d,"sorts.topological":d}},l=function(n,t,s){function d(){return j}function l(){var e=arguments[0],t=p.apply(null,arguments);return O.hasOwnProperty(e)&&i("'"+e+"' extends already registered in '"+n+"' module."),_[E++]=t,y(O,t),O}function y(n,t){var r=new e(t.dependencies.length);c.for_each_async(t.dependencies,function(e,n,t,i){j.resolve(e).then(function(e){r[n]=e,t()}).$catch(i)}).then(function(){n[t.name]=t.fn.apply(n,r)}).$catch(function(e){console.error(e)})}var v,w,O={$name:n,extend:l},P=new u(O),_=[],E=0,g={},j=new f(n,P,h,g),m=[];for(w=o(n,function(e){return s[e]?s[e].requires:n===e?t:void i("'"+e+"' module is not found.")}),w.pop(),O.$included_modules=w,v=0;v<w.length;++v)m=m.concat(s[w[v]].extenders),r(P.definitions,s[w[v]].new_definitions);for(P.definitions.$injector={fn:d,dependencies:a},s[n]={name:n,requires:t,instance:O,injector:P,extenders:_,public_injector:j,new_definitions:g},v=0;v<m.length;++v)y(O,m[v]);return O},y=function(){};return y.prototype={use:function(e){return e(this),this}},{create:function(){function e(e,r){return n(r)?(t.hasOwnProperty(e)&&i("Duplicated module '"+e+"' is detected."),l(e,r,t)):(t.hasOwnProperty(e)||i("'"+e+"' module is not found."),t[e].instance)}var t={},r=new y;return r.module=e,r}}}();window.jeefo=e.create()}(); |
/** | ||
* jeefo : v0.0.23 | ||
* jeefo : v0.0.24 | ||
* Author : je3f0o, <je3f0o@gmail.com> | ||
@@ -89,3 +89,3 @@ * Homepage : https://github.com/je3f0o/jeefo | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-07-11 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -97,34 +97,21 @@ * Purpose : | ||
// JeefoPromise {{{1 | ||
var JeefoPromise = function (promise_handler) { | ||
var JeefoPromise = function (promise_handler, callback, args) { | ||
var state = 0, | ||
pendings = [], | ||
instance = this, | ||
pendings_length = 0, result; | ||
is_last_chain = true, | ||
pendings_length = 0, | ||
result; | ||
instance.then = then; | ||
instance.$catch = $catch; | ||
instance.state = "pending..."; | ||
instance.is_pending = is_pending; | ||
instance.then = then; | ||
instance.state = "pending..."; | ||
instance.$catch = $catch; | ||
instance.result = get_result; | ||
instance.is_pending = is_pending; | ||
instance.is_rejected = is_rejected; | ||
instance.is_resolved = is_resolved; | ||
// Promise handler {{{2 | ||
try { | ||
promise_handler(function (value) { | ||
if (state !== 0) { return; } | ||
state = 1; | ||
instance.state = "resolved"; | ||
instance.value = result = value; | ||
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); | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
}, _rejector); | ||
promise_handler(_resolver, _rejector); | ||
} catch (e) { | ||
@@ -143,2 +130,42 @@ _rejector(e); | ||
// Is rejected ? {{{2 | ||
function is_rejected () { | ||
return state === 2; | ||
} | ||
// Is rejected ? {{{2 | ||
function is_resolved () { | ||
return state === 1; | ||
} | ||
// Get result {{{2 | ||
function get_result () { | ||
return result; | ||
} | ||
// Resolver {{{2 | ||
function _resolver (value) { | ||
if (state !== 0) { return; } | ||
state = 1; | ||
instance.state = "resolved"; | ||
instance.value = result = value; | ||
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); | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
if (is_last_chain && callback) { | ||
callback.apply(null, args); | ||
} | ||
} | ||
// Rejector {{{2 | ||
@@ -163,2 +190,6 @@ function _rejector (reason) { | ||
pendings_length = 0; | ||
if (is_last_chain && callback) { | ||
callback.apply(null, args); | ||
} | ||
} | ||
@@ -168,2 +199,3 @@ | ||
function then (resolver, rejector) { | ||
is_last_chain = false; | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
@@ -183,4 +215,4 @@ switch (state) { | ||
default: | ||
pendings[pendings_length ] = resolver; | ||
pendings[pendings_length + 1] = rejector; | ||
pendings[pendings_length ] = resolver || get_result; | ||
pendings[pendings_length + 1] = rejector || get_result; | ||
pendings[pendings_length + 2] = next_resolver; | ||
@@ -190,3 +222,3 @@ pendings[pendings_length + 3] = next_rejector; | ||
} | ||
}); | ||
}, callback, args); | ||
} | ||
@@ -196,2 +228,3 @@ | ||
function $catch (rejector) { | ||
is_last_chain = false; | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
@@ -207,3 +240,3 @@ switch (state) { | ||
default: | ||
pendings[pendings_length ] = _resolver; | ||
pendings[pendings_length ] = get_result; | ||
pendings[pendings_length + 1] = rejector; | ||
@@ -214,7 +247,3 @@ pendings[pendings_length + 2] = next_resolver; | ||
} | ||
}); | ||
function _resolver () { | ||
return result; | ||
} | ||
}, callback, args); | ||
} | ||
@@ -236,2 +265,7 @@ // }}}2 | ||
}, | ||
reject : function (reason) { | ||
return new JeefoPromise(function (resolve, reject) { | ||
reject(reason); | ||
}); | ||
}, | ||
when : function (value) { | ||
@@ -258,3 +292,7 @@ // jshint latedef : false | ||
if (++index < items.length) { | ||
iterator.call(items, items[index], index, next, items); | ||
try { | ||
iterator.call(items, items[index], index, next, rejector); | ||
} catch (e) { | ||
rejector(e); | ||
} | ||
} else { | ||
@@ -264,2 +302,6 @@ deferred.resolve(); | ||
} | ||
function rejector (reason) { | ||
deferred.reject(reason); | ||
} | ||
// jshint latedef : true | ||
@@ -305,3 +347,3 @@ }, | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-05-10 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -313,4 +355,5 @@ * Purpose : | ||
// Injector {{{1 | ||
var JeefoInjector = function (values) { | ||
this.values = assign({}, values); | ||
var JeefoInjector = function (instance) { | ||
this.values = {}; | ||
this.instance = instance; | ||
this.definitions = {}; | ||
@@ -354,2 +397,3 @@ }; | ||
var values = this.values, | ||
instance = this.instance, | ||
definitions = this.definitions, | ||
@@ -401,3 +445,3 @@ local_values = (local && local.values) || {}, | ||
// Call definition handler, invoker | ||
var Result = definition.fn.apply(null, args); | ||
var Result = definition.fn.apply(instance, args); | ||
@@ -427,6 +471,5 @@ if (definition.is_constructor) { | ||
resolve_sync : function (name, local) { | ||
var self = this, | ||
values = self.values, | ||
var values = this.values, | ||
local_values = (local && local.values) || {}, | ||
definitions = self.definitions, | ||
definitions = this.definitions, | ||
local_definitions = local && local.definitions, | ||
@@ -463,3 +506,3 @@ container; | ||
if (! local_values.hasOwnProperty(execution_order[i]) && ! values.hasOwnProperty(execution_order[i])) { | ||
self.resolve_sync(execution_order[i], local); | ||
this.resolve_sync(execution_order[i], local); | ||
} | ||
@@ -474,3 +517,3 @@ } | ||
return (container[name] = definition.fn.apply(null, args)); | ||
return (container[name] = definition.fn.apply(this.instance, args)); | ||
}, | ||
@@ -484,3 +527,3 @@ // }}}2 | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-06-30 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -580,2 +623,3 @@ * Purpose : | ||
Injector : JeefoInjector, | ||
JeefoPromise : JeefoPromise, | ||
"object.keys" : object_keys, | ||
@@ -591,2 +635,3 @@ "object.assign" : assign, | ||
Injector : empty_dependencies, | ||
JeefoPromise : empty_dependencies, | ||
"object.keys" : empty_dependencies, | ||
@@ -605,3 +650,3 @@ "object.assign" : empty_dependencies, | ||
}, | ||
injector = new JeefoInjector(), | ||
injector = new JeefoInjector(instance), | ||
extenders = [], | ||
@@ -676,9 +721,11 @@ extends_length = 0, | ||
$q.for_each_async(injectable.dependencies, function (dependency, index, next) { | ||
$q.for_each_async(injectable.dependencies, function (dependency, index, next, rejector) { | ||
public_injector.resolve(dependency).then(function (value) { | ||
args[index] = value; | ||
next(); | ||
}); | ||
}).$catch(rejector); | ||
}).then(function () { | ||
instance[injectable.name] = injectable.fn.apply(instance, args); | ||
}).$catch(function (e) { | ||
console.error(e); | ||
}); | ||
@@ -685,0 +732,0 @@ } |
/** | ||
* jeefo : v0.0.23 | ||
* jeefo : v0.0.24 | ||
* 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,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){function n(){return o}return new s(function(r,t){switch(u){case 1:return o&&"JEEFO_PROMISE"===o.type?o.then(r,t):r(o);case 2:return r(e(o));default:c[a]=n,c[a+1]=e,c[a+2]=r,c[a+3]=t,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}}}(); | ||
"use strict";module.exports=function(){var e=Array,n=e.isArray,t=Object.keys,r=function(e){for(var n,r,i,o=1;o<arguments.length;++o)if(n=arguments[o])for(r=t(n),i=r.length-1;i>=0;e[r[i]]=n[r[i]],--i);return e},i=function(e){throw new Error(e)},o=function(n,t){var r=[],o={};return function s(c,u){for(var a=u.length-1,f=new e(a+1),d=t(c);a>=0;f[a]=u[a],--a);for(f.push(c),o[c]=!0,a=0;a<d.length;++a)f.indexOf(d[a])>=0&&i("Circular dependency '"+d[a]+" is required by '"+n+"' : "+f.join(" -> ")),o.hasOwnProperty(d[a])||s(d[a],f);-1===r.indexOf(c)&&r.push(c)}(n,[]),r},s=function(e,n,t){function r(){return 0===h}function i(){return 2===h}function o(){return 1===h}function c(){return p}function u(e){if(0===h){h=1,y.state="resolved",y.value=p=e;for(var r=0;r<w;r+=4)e=l[r](p),e&&"JEEFO_PROMISE"===e.type?e.then(l[r+2],l[r+3]):l[r+2](e);l=null,w=0,v&&n&&n.apply(null,t)}}function a(e){if(0===h){h=2,y.state="rejected",y.reason=p=e;for(var r=1;r<w;r+=4)e=l[r](p),e&&"JEEFO_PROMISE"===e.type?e.then(l[r+1],l[r+2]):l[r+2](e);l=null,w=0,v&&n&&n.apply(null,t)}}function f(e,r){return v=!1,new s(function(n,t){switch(h){case 1:var i=e(p);return i&&"JEEFO_PROMISE"===i.type?i.then(n,t):n(i);case 2:return r?n(r(p)):t(p);default:l[w]=e||c,l[w+1]=r||c,l[w+2]=n,l[w+3]=t,w+=4}},n,t)}function d(e){return v=!1,new s(function(n,t){switch(h){case 1:return p&&"JEEFO_PROMISE"===p.type?p.then(n,t):n(p);case 2:return n(e(p));default:l[w]=c,l[w+1]=e,l[w+2]=n,l[w+3]=t,w+=4}},n,t)}var p,h=0,l=[],y=this,v=!0,w=0;y.then=f,y.state="pending...",y.$catch=d,y.result=c,y.is_pending=r,y.is_rejected=i,y.is_resolved=o;try{e(u,a)}catch(e){a(e)}return y};s.prototype.type="JEEFO_PROMISE";var c={defer:function(){var e={};return e.promise=new s(function(n,t){e.resolve=n,e.reject=t}),e},reject:function(e){return new s(function(n,t){t(e)})},when:function(e){return e&&"JEEFO_PROMISE"===e.type?e:new s(function(n){n(e)})},for_each_async:function(e,n){function t(){if(++i<e.length)try{n.call(e,e[i],i,t,r)}catch(e){r(e)}else o.resolve()}function r(e){o.reject(e)}var i=-1,o=this.defer();return t(),o.promise},all:function(e){for(var n,t=0,r=this.defer(),i=0;t<e.length;++t)(n=e[t])&&"JEEFO_PROMISE"===n.type&&(i+=1,n.then(function(n){return function(t){e[n]=t,0===--i&&r.resolve(e)}}(t)));return 0===i&&r.resolve(e),r.promise}},u=function(e){this.values={},this.instance=e,this.definitions={}},a=[];u.prototype={register:function(n,t){if(t.dependencies){for(var r=new e(t.dependencies.length),o=r.length-1;o>=0;r[o]=t.dependencies[o],--o);(this.values.hasOwnProperty(n)||this.definitions.hasOwnProperty(n))&&i("Duplicated provider "+n+" detected."),this.definitions[n]={fn:t.fn,dependencies:r,is_constructor:!!t.is_constructor}}else this.definitions[n]={fn:t.fn,dependencies:a,is_constructor:!!t.is_constructor};return this},resolve:function(n,t){var r,s=this.values,u=this.instance,a=this.definitions,f=t&&t.values||{},d=t&&t.definitions;return f.hasOwnProperty(n)?f[n]&&"JEEFO_PROMISE"===f[n].type?f[n]:c.when(f[n]):s.hasOwnProperty(n)?s[n]&&"JEEFO_PROMISE"===s[n].type?s[n]:c.when(s[n]):(r=o(n,function(e){return d&&d.hasOwnProperty(e)?d[e].dependencies:a.hasOwnProperty(e)?a[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),c.for_each_async(r,function(n,t,r){var o,c;if(f.hasOwnProperty(n)||s.hasOwnProperty(n))return r();d&&d.hasOwnProperty(n)?(o=f,c=d[n]):(o=s,c=a[n]);for(var p=c.dependencies.length-1,h=new e(p+1);p>=0;--p)f.hasOwnProperty(c.dependencies[p])?h[p]=f[c.dependencies[p]]:s.hasOwnProperty(c.dependencies[p])?h[p]=s[c.dependencies[p]]:i("OMG");var l=c.fn.apply(u,h);c.is_constructor&&(l=new l),l&&"JEEFO_PROMISE"===l.type?l.then(function(e){o[n]=e,r()}):(o[n]=l,r())}).then(function(){return f.hasOwnProperty(n)?f[n]:s[n]}))},resolve_sync:function(n,t){var r,s=this.values,c=t&&t.values||{},u=this.definitions,a=t&&t.definitions;if(c.hasOwnProperty(n))return c[n];if(s.hasOwnProperty(n))return s[n];a&&a.hasOwnProperty(n)?r=c:u.hasOwnProperty(n)&&(r=s);for(var f=o(n,function(e){return a&&a.hasOwnProperty(e)?a[e].dependencies:u.hasOwnProperty(e)?u[e].dependencies:void i("Injector '"+e+"' definition is not found.")}),d=u[f.pop()],p=new e(d.dependencies.length),h=0;h<f.length;++h)c.hasOwnProperty(f[h])||s.hasOwnProperty(f[h])||this.resolve_sync(f[h],t);for(h=p.length-1;h>=0;--h)p[h]=c.hasOwnProperty(d.dependencies[h])?c[d.dependencies[h]]:s[d.dependencies[h]];return r[n]=d.fn.apply(this.instance,p)}};var f=function(e,n,t,r){function o(e){return"$injector"===e||p.hasOwnProperty(e)||d.hasOwnProperty(e)}function s(t,s){return o(t)&&i("Duplicated provider '"+t+"' detected in module '"+e+"'."),n.register(t,s),r[t]=n.definitions[t],f}function u(r){return p.hasOwnProperty(r)?c.when(p[r]):d.hasOwnProperty(r)?n.resolve(r,t):void i("Module provider '"+r+"' definition is not found in '"+e+"' module.")}function a(r){return p.hasOwnProperty(r)?p[r]:d.hasOwnProperty(r)?n.resolve_sync(r,t):void i("Module provider '"+r+"' definition is not found in '"+e+"' module.")}var f=this,d=n.definitions,p=t.values;return f.has=o,f.resolve=u,f.register=s,f.resolve_sync=a,f},d={dependencies:a},p=function(n,t,r){if("function"===typeof t)return{fn:t,name:n,dependencies:a};if("string"===typeof t)return{fn:r,name:n,dependencies:[t]};for(var i=t.length-1,o=new e(i+1);i>=0;o[i]=t[i],--i);return{fn:r,name:n,dependencies:o}},h={values:{$q:c,Array:e,is_array:n,Injector:u,JeefoPromise:s,"object.keys":t,"object.assign":r,make_injectable:p,"sorts.topological":o},definitions:{$q:d,Array:d,is_array:d,Injector:d,JeefoPromise:d,"object.keys":d,"object.assign":d,make_injectable:d,"sorts.topological":d}},l=function(n,t,s){function d(){return m}function l(){var e=arguments[0],t=p.apply(null,arguments);return O.hasOwnProperty(e)&&i("'"+e+"' extends already registered in '"+n+"' module."),_[E++]=t,y(O,t),O}function y(n,t){var r=new e(t.dependencies.length);c.for_each_async(t.dependencies,function(e,n,t,i){m.resolve(e).then(function(e){r[n]=e,t()}).$catch(i)}).then(function(){n[t.name]=t.fn.apply(n,r)}).$catch(function(e){console.error(e)})}var v,w,O={$name:n,extend:l},P=new u(O),_=[],E=0,g={},m=new f(n,P,h,g),j=[];for(w=o(n,function(e){return s[e]?s[e].requires:n===e?t: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),r(P.definitions,s[w[v]].new_definitions);for(P.definitions.$injector={fn:d,dependencies:a},s[n]={name:n,requires:t,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,r){return n(r)?(t.hasOwnProperty(e)&&i("Duplicated module '"+e+"' is detected."),l(e,r,t)):(t.hasOwnProperty(e)||i("'"+e+"' module is not found."),t[e].instance)}var t={},r=new y;return r.module=e,r}}}(); |
{ | ||
"name": "jeefo", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"homepage": "https://github.com/je3f0o/jeefo", | ||
@@ -5,0 +5,0 @@ "copyright": "2016", |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : injector.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-05-10 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -36,4 +36,5 @@ * Purpose : | ||
// Injector {{{1 | ||
var JeefoInjector = function (values) { | ||
this.values = assign({}, values); | ||
var JeefoInjector = function (instance) { | ||
this.values = {}; | ||
this.instance = instance; | ||
this.definitions = {}; | ||
@@ -77,2 +78,3 @@ }; | ||
var values = this.values, | ||
instance = this.instance, | ||
definitions = this.definitions, | ||
@@ -127,3 +129,3 @@ local_values = (local && local.values) || {}, | ||
// Call definition handler, invoker | ||
var Result = definition.fn.apply(null, args); | ||
var Result = definition.fn.apply(instance, args); | ||
@@ -153,6 +155,5 @@ if (definition.is_constructor) { | ||
resolve_sync : function (name, local) { | ||
var self = this, | ||
values = self.values, | ||
var values = this.values, | ||
local_values = (local && local.values) || {}, | ||
definitions = self.definitions, | ||
definitions = this.definitions, | ||
local_definitions = local && local.definitions, | ||
@@ -189,3 +190,3 @@ container; | ||
if (! local_values.hasOwnProperty(execution_order[i]) && ! values.hasOwnProperty(execution_order[i])) { | ||
self.resolve_sync(execution_order[i], local); | ||
this.resolve_sync(execution_order[i], local); | ||
} | ||
@@ -200,3 +201,3 @@ } | ||
return (container[name] = definition.fn.apply(null, args)); | ||
return (container[name] = definition.fn.apply(this.instance, args)); | ||
}, | ||
@@ -203,0 +204,0 @@ // }}}2 |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : module.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-06-30 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -114,2 +114,3 @@ * Purpose : | ||
Injector : JeefoInjector, | ||
JeefoPromise : JeefoPromise, | ||
"object.keys" : object_keys, | ||
@@ -125,2 +126,3 @@ "object.assign" : assign, | ||
Injector : empty_dependencies, | ||
JeefoPromise : empty_dependencies, | ||
"object.keys" : empty_dependencies, | ||
@@ -139,3 +141,3 @@ "object.assign" : empty_dependencies, | ||
}, | ||
injector = new JeefoInjector(), | ||
injector = new JeefoInjector(instance), | ||
extenders = [], | ||
@@ -210,9 +212,11 @@ extends_length = 0, | ||
$q.for_each_async(injectable.dependencies, function (dependency, index, next) { | ||
$q.for_each_async(injectable.dependencies, function (dependency, index, next, rejector) { | ||
public_injector.resolve(dependency).then(function (value) { | ||
args[index] = value; | ||
next(); | ||
}); | ||
}).$catch(rejector); | ||
}).then(function () { | ||
instance[injectable.name] = injectable.fn.apply(instance, args); | ||
}).$catch(function (e) { | ||
console.error(e); | ||
}); | ||
@@ -219,0 +223,0 @@ } |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : promise.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2017-07-11 | ||
* Updated at : 2017-07-21 | ||
* Author : jeefo | ||
@@ -31,34 +31,21 @@ * Purpose : | ||
// JeefoPromise {{{1 | ||
var JeefoPromise = function (promise_handler) { | ||
var JeefoPromise = function (promise_handler, callback, args) { | ||
var state = PENDING_STATE_ENUM, | ||
pendings = [], | ||
instance = this, | ||
pendings_length = 0, result; | ||
is_last_chain = true, | ||
pendings_length = 0, | ||
result; | ||
instance.then = then; | ||
instance.$catch = $catch; | ||
instance.state = PENDING_STATE; | ||
instance.is_pending = is_pending; | ||
instance.then = then; | ||
instance.state = PENDING_STATE; | ||
instance.$catch = $catch; | ||
instance.result = get_result; | ||
instance.is_pending = is_pending; | ||
instance.is_rejected = is_rejected; | ||
instance.is_resolved = is_resolved; | ||
// Promise handler {{{2 | ||
try { | ||
promise_handler(function (value) { | ||
if (state !== PENDING_STATE_ENUM) { return; } | ||
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); | ||
if (IS_JEEFO_PROMISE(value)) { | ||
value.then(pendings[i + 2], pendings[i + 3]); | ||
} else { | ||
pendings[i + 2](value); | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
}, _rejector); | ||
promise_handler(_resolver, _rejector); | ||
} catch (e) { | ||
@@ -77,2 +64,42 @@ _rejector(e); | ||
// Is rejected ? {{{2 | ||
function is_rejected () { | ||
return state === REJECTED_STATE_ENUM; | ||
} | ||
// Is rejected ? {{{2 | ||
function is_resolved () { | ||
return state === RESOLVED_STATE_ENUM; | ||
} | ||
// Get result {{{2 | ||
function get_result () { | ||
return result; | ||
} | ||
// Resolver {{{2 | ||
function _resolver (value) { | ||
if (state !== PENDING_STATE_ENUM) { return; } | ||
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); | ||
if (IS_JEEFO_PROMISE(value)) { | ||
value.then(pendings[i + 2], pendings[i + 3]); | ||
} else { | ||
pendings[i + 2](value); | ||
} | ||
} | ||
pendings = null; | ||
pendings_length = 0; | ||
if (is_last_chain && callback) { | ||
callback.apply(null, args); | ||
} | ||
} | ||
// Rejector {{{2 | ||
@@ -97,2 +124,6 @@ function _rejector (reason) { | ||
pendings_length = 0; | ||
if (is_last_chain && callback) { | ||
callback.apply(null, args); | ||
} | ||
} | ||
@@ -102,2 +133,3 @@ | ||
function then (resolver, rejector) { | ||
is_last_chain = false; | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
@@ -117,4 +149,4 @@ switch (state) { | ||
default: | ||
pendings[pendings_length ] = resolver; | ||
pendings[pendings_length + 1] = rejector; | ||
pendings[pendings_length ] = resolver || get_result; | ||
pendings[pendings_length + 1] = rejector || get_result; | ||
pendings[pendings_length + 2] = next_resolver; | ||
@@ -124,3 +156,3 @@ pendings[pendings_length + 3] = next_rejector; | ||
} | ||
}); | ||
}, callback, args); | ||
} | ||
@@ -130,2 +162,3 @@ | ||
function $catch (rejector) { | ||
is_last_chain = false; | ||
return new JeefoPromise(function (next_resolver, next_rejector) { | ||
@@ -141,3 +174,3 @@ switch (state) { | ||
default: | ||
pendings[pendings_length ] = _resolver; | ||
pendings[pendings_length ] = get_result; | ||
pendings[pendings_length + 1] = rejector; | ||
@@ -148,7 +181,3 @@ pendings[pendings_length + 2] = next_resolver; | ||
} | ||
}); | ||
function _resolver () { | ||
return result; | ||
} | ||
}, callback, args); | ||
} | ||
@@ -170,2 +199,7 @@ // }}}2 | ||
}, | ||
reject : function (reason) { | ||
return new JeefoPromise(function (resolve, reject) { | ||
reject(reason); | ||
}); | ||
}, | ||
when : function (value) { | ||
@@ -192,3 +226,7 @@ // jshint latedef : false | ||
if (++index < items.length) { | ||
iterator.call(items, items[index], index, next, items); | ||
try { | ||
iterator.call(items, items[index], index, next, rejector); | ||
} catch (e) { | ||
rejector(e); | ||
} | ||
} else { | ||
@@ -198,2 +236,6 @@ deferred.resolve(); | ||
} | ||
function rejector (reason) { | ||
deferred.reject(reason); | ||
} | ||
// jshint latedef : true | ||
@@ -200,0 +242,0 @@ }, |
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
154495
4057