Comparing version 0.0.2 to 0.0.3
51
jeefo.js
@@ -18,3 +18,3 @@ /* | ||
* Created at : 2016-09-01 | ||
* Updated at : 2016-09-01 | ||
* Updated at : 2016-09-02 | ||
* Author : jeefo | ||
@@ -95,2 +95,25 @@ * Purpose : | ||
}, _Object.create(_null)); | ||
}, | ||
OBJECT_PROPERTY_PLACEHOLDER_REGEX = /{\s*([^{}]+)\s*}/g, | ||
INDEX_PLACEHOLDER_REGEX = /{\s*(\d+)\s*}/g, | ||
sprintf = function (str, args) { | ||
var regex; | ||
if (is_object(args) && ! is_array(args)) { | ||
regex = OBJECT_PROPERTY_PLACEHOLDER_REGEX; | ||
} else { | ||
args = to_array(arguments, 1); | ||
regex = INDEX_PLACEHOLDER_REGEX; | ||
} | ||
return str.replace(regex, function(match, key) { | ||
key = key.trim(); | ||
var value = args[key]; | ||
if (is_function(value)) { | ||
return value() || ''; | ||
} else if (is_defined(value)) { | ||
return value; | ||
} | ||
return match; | ||
}); | ||
}; | ||
@@ -513,3 +536,3 @@ | ||
* Created at : 2016-09-01 | ||
* Updated at : 2016-09-01 | ||
* Updated at : 2016-09-02 | ||
* Author : jeefo | ||
@@ -593,8 +616,7 @@ * Purpose : | ||
return function (name, requires) { | ||
var make_module = function (name, requires) { | ||
var _module = map(); | ||
requires = requires || []; | ||
lazy_resolve_sync(_module, modules_injector, name, { | ||
dependencies : requires, | ||
dependencies : requires.concat(), | ||
fn : function () { | ||
@@ -606,2 +628,11 @@ var injector = make_injector(), | ||
// CORE INJECTORS | ||
if (requires.length === 0) { | ||
injector.register("$q", { | ||
fn : function () { return $q; }, | ||
dependencies : [], | ||
resolve_once : true, | ||
}); | ||
} | ||
// public $injector | ||
@@ -641,2 +672,3 @@ injector.name = name; | ||
injector : injector, | ||
instance : _module, | ||
}); | ||
@@ -651,2 +683,10 @@ } | ||
}; | ||
return function (name, requires) { | ||
if (is_array(requires)) { | ||
return make_module(name, requires); | ||
} | ||
return modules_injector.resolve_sync(null, name).instance; | ||
}; | ||
}()); | ||
@@ -670,2 +710,3 @@ | ||
assign : assign, | ||
sprintf : sprintf, | ||
module : module | ||
@@ -672,0 +713,0 @@ }; |
@@ -6,2 +6,2 @@ /* | ||
*/ | ||
!function(n,e){"object"==typeof exports?module.exports=e():n.jeefo=e()}(this,function(){"use strict";var n={}.toString,e=Object,r=Array,t=null,i,o=function(n,e){return[].slice.call(n,e)},u=function(n){return function(e){return typeof e===n}},s=function(n){return n===i},c=function(n){return n!==i},f=function(n){return null===n},a=u("number"),l=u("string"),p=u("boolean"),v=u("function"),d=r.isArray,h=function(n){return!f(n)&&"object"==typeof n},_=function(e){return"[object Date]"===n.call(e)},m=function(e){return"[object RegExp]"===n.call(e)},y=function(n){return/^\-?\d+$/.test(n)},j=function(){return e.assign.apply(t,o(arguments))},g=function(){return o(arguments).reduce(function(n,e){return j(n,e)},e.create(t))},b=r.prototype;s(b.exists)&&(b.exists=function(n){return this.indexOf(n)>=0});var w=function(n,e){var r=[],t={};return function n(i,o){o=o||[],o.push(i),t[i]=!0;var u=e(i);u.forEach(function(e){if(o.exists(e))throw new Error('Circular dependency "'+e+'" is required by "'+i+'": '+o.join(" -> "));t[e]||n(e,o.concat())}),r.exists(i)||r.push(i)}(n),r},x="pending...",E="resolved",$="rejected",k=function(n,r,t){e.defineProperty(n,r,{value:t,writable:!1,configurable:!1})},O=function(){},q=function(n){return n instanceof O},A=function(n,e,r){var t=j(new O,{value:r,status:e});return k(t,"then",n),t},D=function(n,e){return q(n)?n:{then:function(e){e.call(this,n)},promise:e}},I=function(){var n=[],e,r=function(n,e,r){return n.value=r,n.status=e,D(r,n)};return g({resolve:function(t){if(n){e=r(this.promise,E,t);for(var o=0,u=n.length;o<u;++o)e.then(n[o][0]);n=i}},reject:function(n){},promise:A(function(r,t){var i=I();r=r||function(n){return n};var o=function(n){i.resolve(r.call(e.promise,n))};return n?n.push([o,t]):e.then(o),i.promise},x)})},C=function(n){return q(n)?n:A(function(e){e(n)},E,n)},G=g({defer:I,when:C,all:function(n){var e=0,r=I();return n.forEach(function(t,i){q(t)&&(e+=1,t.then(function(t){n[i]=t,0===--e&&r.resolve(n)}))}),0===e&&r.resolve(n),r.promise},is_promise:q}),M=function(n,e){var r=G.defer(),t=-1,i=n.length;return function o(){t+=1,t<i?e.call(n,n[t],t,o):r.resolve()}(),r.promise},P=function(){var n=function(n,e,r){var t=n[e];G.is_promise(t)?t.then(function(t){n[e]=t,r.callback(t)}):r.callback(n[e])},e=function(n,e,r){return e.map(function(e){if(e in r)return r[e];if(e in n)return n[e];throw new Error("OMG")})},r=function(n,r,t){var i=[],o=[],u=e(n,r,t);return u.forEach(function(n,e){G.is_promise(n)&&(i.push(r[e]),o.push(n))}),{names:i,values:u,promises:o}},t=function(n,e,r,t,i){var o=r.fn.apply(null,t);r.is_constructor&&(o=new o),G.is_promise(o)?o.then(function(r){n[e]=r,i()}):(n[e]=o,i())},i=function(){this.results=g(),this.definitions=g()};return i.prototype=g({register:function(n,e){if(this.definitions[n])throw new Error("Duplicated provider `0` detected.".replace(0,n));this.definitions[n]=g(e)},resolve:function(e,i){var o=this.results,u=this.definitions,s=i.values||g(),c=i.definitions;if(e in s)return n(s,e,i);if(e in o)return n(o,e,i);var f=w(e,function(n){var e=c&&c[n]||u[n];if(e)return e.dependencies;throw new Error("Injector `0` definition is not found: ".replace(0,n))});M(f,function(n,e,i){var f,a;if(c&&c[n]?(f=s,a=c[n]):u[n]&&(f=o,a=u[n]),n in f)return i();var l=r(o,a.dependencies,s);t(f,n,a,l.values,i)}).then(function(){var n=s[e]||o[e];i.callback(n)})},resolve_sync:function(n,e,r){var t=this,i=t.results,o=t.definitions;r=r||{};var u=r.values||g(),s=r.definitions;if(e in u)return u[e];if(e in i)return i[e];var c;s&&s[e]?c=u:o[e]&&(c=i);var f=w(e,function(n){var e=s&&s[n]||o[n];if(e)return e.dependencies;throw new Error("Injector `0` definition is not found: ".replace(0,n))}),a=o[f.pop()];f.forEach(function(e){e in u||e in i||t.resolve_sync(n,e)});var l=a.dependencies.map(function(n){return n in u?u[n]:i[n]});return c[e]=a.fn.apply(n,l)}}),function(){return new i}}(),R=function(n){return function(e,r,t,i){return s(i)&&(i=!0),v(r)&&(t=r,r=[]),n.call(this,e,{fn:t,dependencies:r,resolve_once:i})}},S=function(){var n=P(),e=function(n,e,r,t){e.register(r,t),e.resolve_sync(n,r)},r=function(n,e){var r=e.results,t=e.definitions;return r.$injector=g({register:function(n,r){return e.register.call(e,n,r)},resolve:function(){return e.resolve.apply(e,arguments)},resolve_sync:function(r,t){return e.resolve_sync(n,r,t)},has:function(n){return n in t}}),r.$injector},t=function(n,e,r,t){var i=t.dependencies.map(function(r){return e.resolve_sync(n,r)});k(n,r,t.fn.apply(n,i))},i=R(function(e,r){var i=n.resolve_sync(this,this.name);i.protos[e]=r,t(this,i.injector,e,r)});return function(o,u){var s=g();return u=u||[],e(s,n,o,{dependencies:u,fn:function(){var n=P(),e=n.results,i=g(),c,f,a,l,p;n.name=o;var v=r(s,n);for(v.name=o,n.register("$injector",{fn:function(){return v},dependencies:[]}),c=0;a=arguments[c++];){l=a.injector,j(n.definitions,l.definitions);for(f in l.results)l.definitions[f].resolve_once?e[f]=l.results[f]:e[f]=n.resolve_sync(s,f);j(i,a.protos)}for(p in i)t(s,n,p,i[p]);return g({name:o,protos:i,requires:u,injector:n})}}),k(s,"name",o),k(s,"extend",i),s}}();return{version:"0.0.2",is_undefined:s,is_defined:c,is_null:f,is_number:a,is_string:l,is_function:v,is_boolean:p,is_array:d,is_object:h,is_date:_,is_regex:m,is_digit:y,map:g,assign:j,module:S}}); | ||
!function(n,e){"object"==typeof exports?module.exports=e():n.jeefo=e()}(this,function(){"use strict";var n={}.toString,e=Object,r=Array,t=null,i,o=function(n,e){return[].slice.call(n,e)},u=function(n){return function(e){return typeof e===n}},s=function(n){return n===i},c=function(n){return n!==i},f=function(n){return null===n},a=u("number"),l=u("string"),v=u("boolean"),p=u("function"),d=r.isArray,h=function(n){return!f(n)&&"object"==typeof n},_=function(e){return"[object Date]"===n.call(e)},m=function(e){return"[object RegExp]"===n.call(e)},y=function(n){return/^\-?\d+$/.test(n)},g=function(){return e.assign.apply(t,o(arguments))},j=function(){return o(arguments).reduce(function(n,e){return g(n,e)},e.create(t))},b=/{\s*([^{}]+)\s*}/g,w=/{\s*(\d+)\s*}/g,x=function(n,e){var r;return h(e)&&!d(e)?r=b:(e=o(arguments,1),r=w),n.replace(r,function(n,r){r=r.trim();var t=e[r];return p(t)?t()||"":c(t)?t:n})},E=r.prototype;s(E.exists)&&(E.exists=function(n){return this.indexOf(n)>=0});var $=function(n,e){var r=[],t={};return function n(i,o){o=o||[],o.push(i),t[i]=!0;var u=e(i);u.forEach(function(e){if(o.exists(e))throw new Error('Circular dependency "'+e+'" is required by "'+i+'": '+o.join(" -> "));t[e]||n(e,o.concat())}),r.exists(i)||r.push(i)}(n),r},k="pending...",q="resolved",O="rejected",A=function(n,r,t){e.defineProperty(n,r,{value:t,writable:!1,configurable:!1})},D=function(){},I=function(n){return n instanceof D},C=function(n,e,r){var t=g(new D,{value:r,status:e});return A(t,"then",n),t},G=function(n,e){return I(n)?n:{then:function(e){e.call(this,n)},promise:e}},M=function(){var n=[],e,r=function(n,e,r){return n.value=r,n.status=e,G(r,n)};return j({resolve:function(t){if(n){e=r(this.promise,q,t);for(var o=0,u=n.length;o<u;++o)e.then(n[o][0]);n=i}},reject:function(n){},promise:C(function(r,t){var i=M();r=r||function(n){return n};var o=function(n){i.resolve(r.call(e.promise,n))};return n?n.push([o,t]):e.then(o),i.promise},k)})},P=function(n){return I(n)?n:C(function(e){e(n)},q,n)},R=j({defer:M,when:P,all:function(n){var e=0,r=M();return n.forEach(function(t,i){I(t)&&(e+=1,t.then(function(t){n[i]=t,0===--e&&r.resolve(n)}))}),0===e&&r.resolve(n),r.promise},is_promise:I}),S=function(n,e){var r=R.defer(),t=-1,i=n.length;return function o(){t+=1,t<i?e.call(n,n[t],t,o):r.resolve()}(),r.promise},z=function(){var n=function(n,e,r){var t=n[e];R.is_promise(t)?t.then(function(t){n[e]=t,r.callback(t)}):r.callback(n[e])},e=function(n,e,r){return e.map(function(e){if(e in r)return r[e];if(e in n)return n[e];throw new Error("OMG")})},r=function(n,r,t){var i=[],o=[],u=e(n,r,t);return u.forEach(function(n,e){R.is_promise(n)&&(i.push(r[e]),o.push(n))}),{names:i,values:u,promises:o}},t=function(n,e,r,t,i){var o=r.fn.apply(null,t);r.is_constructor&&(o=new o),R.is_promise(o)?o.then(function(r){n[e]=r,i()}):(n[e]=o,i())},i=function(){this.results=j(),this.definitions=j()};return i.prototype=j({register:function(n,e){if(this.definitions[n])throw new Error("Duplicated provider `0` detected.".replace(0,n));this.definitions[n]=j(e)},resolve:function(e,i){var o=this.results,u=this.definitions,s=i.values||j(),c=i.definitions;if(e in s)return n(s,e,i);if(e in o)return n(o,e,i);var f=$(e,function(n){var e=c&&c[n]||u[n];if(e)return e.dependencies;throw new Error("Injector `0` definition is not found: ".replace(0,n))});S(f,function(n,e,i){var f,a;if(c&&c[n]?(f=s,a=c[n]):u[n]&&(f=o,a=u[n]),n in f)return i();var l=r(o,a.dependencies,s);t(f,n,a,l.values,i)}).then(function(){var n=s[e]||o[e];i.callback(n)})},resolve_sync:function(n,e,r){var t=this,i=t.results,o=t.definitions;r=r||{};var u=r.values||j(),s=r.definitions;if(e in u)return u[e];if(e in i)return i[e];var c;s&&s[e]?c=u:o[e]&&(c=i);var f=$(e,function(n){var e=s&&s[n]||o[n];if(e)return e.dependencies;throw new Error("Injector `0` definition is not found: ".replace(0,n))}),a=o[f.pop()];f.forEach(function(e){e in u||e in i||t.resolve_sync(n,e)});var l=a.dependencies.map(function(n){return n in u?u[n]:i[n]});return c[e]=a.fn.apply(n,l)}}),function(){return new i}}(),B=function(n){return function(e,r,t,i){return s(i)&&(i=!0),p(r)&&(t=r,r=[]),n.call(this,e,{fn:t,dependencies:r,resolve_once:i})}},F=function(){var n=z(),e=function(n,e,r,t){e.register(r,t),e.resolve_sync(n,r)},r=function(n,e){var r=e.results,t=e.definitions;return r.$injector=j({register:function(n,r){return e.register.call(e,n,r)},resolve:function(){return e.resolve.apply(e,arguments)},resolve_sync:function(r,t){return e.resolve_sync(n,r,t)},has:function(n){return n in t}}),r.$injector},t=function(n,e,r,t){var i=t.dependencies.map(function(r){return e.resolve_sync(n,r)});A(n,r,t.fn.apply(n,i))},i=B(function(e,r){var i=n.resolve_sync(this,this.name);i.protos[e]=r,t(this,i.injector,e,r)}),o=function(o,u){var s=j();return e(s,n,o,{dependencies:u.concat(),fn:function(){var n=z(),e=n.results,i=j(),c,f,a,l,v;0===u.length&&n.register("$q",{fn:function(){return R},dependencies:[],resolve_once:!0}),n.name=o;var p=r(s,n);for(p.name=o,n.register("$injector",{fn:function(){return p},dependencies:[]}),c=0;a=arguments[c++];){l=a.injector,g(n.definitions,l.definitions);for(f in l.results)l.definitions[f].resolve_once?e[f]=l.results[f]:e[f]=n.resolve_sync(s,f);g(i,a.protos)}for(v in i)t(s,n,v,i[v]);return j({name:o,protos:i,requires:u,injector:n,instance:s})}}),A(s,"name",o),A(s,"extend",i),s};return function(e,r){return d(r)?o(e,r):n.resolve_sync(null,e).instance}}();return{version:"0.0.2",is_undefined:s,is_defined:c,is_null:f,is_number:a,is_string:l,is_function:p,is_boolean:v,is_array:d,is_object:h,is_date:_,is_regex:m,is_digit:y,map:j,assign:g,sprintf:x,module:F}}); |
{ | ||
"name": "jeefo", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "jeefo library", | ||
@@ -5,0 +5,0 @@ "author": "jeefo", |
# jeefo | ||
Very small javacript library for scaleable big frameworks server and client side. Docs coming soon as possible. | ||
Very small javacript library for scaleable big frameworks, server and client side. Docs coming as soon as possible. | ||
# Installation | ||
Install with NPM | ||
```sh | ||
@@ -30,5 +30,7 @@ $ npm install jeefo | ||
#### Final test | ||
It will be build and test against minified filal source code. Only 'Public API'. | ||
It will be build and test against minified final source code. Only 'Public API'. | ||
```sh | ||
$ npm run finaltest | ||
``` | ||
# License MIT |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : module.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2016-09-01 | ||
* Updated at : 2016-09-02 | ||
* Author : jeefo | ||
@@ -17,2 +17,3 @@ * Purpose : | ||
var utils = require("./utils"), | ||
$q = require("./promise"), | ||
make_injector = require("./injector"), | ||
@@ -22,3 +23,5 @@ | ||
is_function = utils.is_function, | ||
is_array = utils.is_array, | ||
assign = utils.assign, | ||
sprintf = utils.sprintf, | ||
map = utils.map; | ||
@@ -107,8 +110,7 @@ | ||
return function (name, requires) { | ||
var make_module = function (name, requires) { | ||
var _module = map(); | ||
requires = requires || []; | ||
lazy_resolve_sync(_module, modules_injector, name, { | ||
dependencies : requires, | ||
dependencies : requires.concat(), | ||
fn : function () { | ||
@@ -120,2 +122,11 @@ var injector = make_injector(), | ||
// CORE INJECTORS | ||
if (requires.length === 0) { | ||
injector.register("$q", { | ||
fn : function () { return $q; }, | ||
dependencies : [], | ||
resolve_once : true, | ||
}); | ||
} | ||
// public $injector | ||
@@ -155,2 +166,3 @@ injector.name = name; | ||
injector : injector, | ||
instance : _module, | ||
}); | ||
@@ -165,2 +177,10 @@ } | ||
}; | ||
return function (name, requires) { | ||
if (is_array(requires)) { | ||
return make_module(name, requires); | ||
} | ||
return modules_injector.resolve_sync(null, name).instance; | ||
}; | ||
}()); | ||
@@ -167,0 +187,0 @@ //ignore:start |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : utils.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2016-09-01 | ||
* Updated at : 2016-09-02 | ||
* Author : jeefo | ||
@@ -27,2 +27,3 @@ * Purpose : | ||
assign, | ||
sprintf, | ||
*/ | ||
@@ -104,2 +105,25 @@ | ||
}, _Object.create(_null)); | ||
}, | ||
OBJECT_PROPERTY_PLACEHOLDER_REGEX = /{\s*([^{}]+)\s*}/g, | ||
INDEX_PLACEHOLDER_REGEX = /{\s*(\d+)\s*}/g, | ||
sprintf = function (str, args) { | ||
var regex; | ||
if (is_object(args) && ! is_array(args)) { | ||
regex = OBJECT_PROPERTY_PLACEHOLDER_REGEX; | ||
} else { | ||
args = to_array(arguments, 1); | ||
regex = INDEX_PLACEHOLDER_REGEX; | ||
} | ||
return str.replace(regex, function(match, key) { | ||
key = key.trim(); | ||
var value = args[key]; | ||
if (is_function(value)) { | ||
return value() || ''; | ||
} else if (is_defined(value)) { | ||
return value; | ||
} | ||
return match; | ||
}); | ||
}; | ||
@@ -122,3 +146,4 @@ //ignore:start | ||
map : map, | ||
assign : assign | ||
assign : assign, | ||
sprintf : sprintf, | ||
}; | ||
@@ -125,0 +150,0 @@ |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : injector_spec.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2016-09-01 | ||
* Updated at : 2016-09-02 | ||
* Author : jeefo | ||
@@ -18,7 +18,13 @@ * Purpose : | ||
if (process.env.NODE_ENV === "production") { return; } | ||
var expect = require("expect"), $q, make_injector; | ||
var $q = require("../source/promise"), | ||
expect = require("expect"), | ||
if (process.env.NODE_ENV === "production") { | ||
var jeefo_mock = require("./jeefo_mock"); | ||
$q = jeefo_mock.module("test").get("$q"); | ||
make_injector = jeefo_mock.make_injector; | ||
} else { | ||
$q = require("../source/promise"); | ||
make_injector = require("../source/injector"); | ||
} | ||
@@ -25,0 +31,0 @@ describe("Injector", function () { |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : module_spec.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2016-09-01 | ||
* Updated at : 2016-09-02 | ||
* Author : jeefo | ||
@@ -18,13 +18,21 @@ * Purpose : | ||
var expect = require("expect"), | ||
make_module = (process.env.NODE_ENV === "production") ? require("../jeefo.min").module : require("../source/module"); | ||
var expect = require("expect"), jeefo_module; | ||
if (process.env.NODE_ENV === "production") { | ||
jeefo_module = require("./jeefo_mock").module; | ||
} else { | ||
jeefo_module = require("../source/module"); | ||
// register new test module | ||
jeefo_module("test", []); | ||
} | ||
describe("Module", function () { | ||
var num1 = Math.random(), | ||
num2 = Math.random(), | ||
total = num1 + num2, | ||
test_module = jeefo_module("test"); | ||
var module = make_module("test"), | ||
num1 = Math.random(), | ||
num2 = Math.random(), | ||
total = num1 + num2; | ||
module.extend("factory", ["$injector"], function ($injector) { | ||
test_module.extend("factory", ["$injector"], function ($injector) { | ||
return function (name, factory) { | ||
@@ -40,3 +48,3 @@ name += "_factory"; | ||
module.extend("run", ["$injector"], function ($injector) { | ||
test_module.extend("run", ["$injector"], function ($injector) { | ||
return function (dependencies, fn) { | ||
@@ -52,4 +60,4 @@ var args = dependencies.map(function (dependency_name) { | ||
it("Should be exists factory and run properties in module instance", function (done) { | ||
expect("run" in module).toBe(true); | ||
expect("factory" in module).toBe(true); | ||
expect("run" in test_module).toBe(true); | ||
expect("factory" in test_module).toBe(true); | ||
done(); | ||
@@ -59,3 +67,3 @@ }); | ||
it("Should be injected sum factory", function (done) { | ||
module.factory("sum", function () { | ||
test_module.factory("sum", function () { | ||
return function (a, b) { | ||
@@ -66,3 +74,3 @@ return a + b; | ||
module.run(["sum_factory"], function (sum_factory) { | ||
test_module.run(["sum_factory"], function (sum_factory) { | ||
var result = sum_factory(num1, num2); | ||
@@ -75,4 +83,5 @@ expect(result).toBe(total); | ||
it("Should be inherit dependencies", function (done) { | ||
var new_module = make_module("new", ["test"]); | ||
new_module.run(["sum_factory"], function (sum_factory) { | ||
var new_test_module = jeefo_module("new", ["test"]); | ||
new_test_module.run(["sum_factory"], function (sum_factory) { | ||
var result = sum_factory(num1, num2); | ||
@@ -79,0 +88,0 @@ expect(result).toBe(total); |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : promise_spec.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2016-09-01 | ||
* Updated at : 2016-09-02 | ||
* Author : jeefo | ||
@@ -18,10 +18,16 @@ * Purpose : | ||
if (process.env.NODE_ENV === "production") { return; } | ||
var expect = require("expect"), $q; | ||
var $q = require("../source/promise"); | ||
var expect = require("expect"); | ||
if (process.env.NODE_ENV === "production") { | ||
var jeefo_mock = require("./jeefo_mock"); | ||
var test_module = jeefo_mock.module("test"); | ||
$q = test_module.get("$q"); | ||
} else { | ||
$q = require("../source/promise"); | ||
} | ||
describe("Promise", function () { | ||
it("Should be thenable", function () { | ||
it("Should be thenable", function (done) { | ||
var numbers = [1,2,3,4,5], | ||
@@ -38,2 +44,3 @@ deferred = $q.defer(); | ||
expect(total).toBe(15); | ||
done(); | ||
}); | ||
@@ -73,3 +80,3 @@ | ||
it("Should be thenable after resolved", function () { | ||
it("Should be thenable after resolved", function (done) { | ||
var defers = [], | ||
@@ -91,2 +98,3 @@ result = $q.defer(); | ||
expect(total).toBe(15); | ||
done(); | ||
}); | ||
@@ -96,3 +104,3 @@ }); | ||
describe("when", function () { | ||
it("Should be immidiate return value 'when' is not promise", function () { | ||
it("Should be immidiate return value 'when' is not promise", function (done) { | ||
var obj = {}; | ||
@@ -105,5 +113,6 @@ | ||
expect(obj.value).toBe(123); | ||
done(); | ||
}); | ||
it("Should be obj.value is set in this CPU cycle", function () { | ||
it("Should be obj.value is set in this CPU cycle", function (done) { | ||
var obj = {}, deferred = $q.defer(); | ||
@@ -118,6 +127,7 @@ var value = Math.random(); | ||
expect(obj.value).toBe(value); | ||
done(); | ||
}); | ||
}); | ||
it("Should be return values after all promises resolved", function () { | ||
it("Should be return values after all promises resolved", function (done) { | ||
var defers = [], promises = [], deferred; | ||
@@ -136,2 +146,3 @@ | ||
expect(result).toBe(true); | ||
done(); | ||
}); | ||
@@ -144,3 +155,3 @@ | ||
it("Should be return values after all promises resolved, mixed promises", function () { | ||
it("Should be return values after all promises resolved, mixed promises", function (done) { | ||
var defers = [], promises = [], deferred; | ||
@@ -163,2 +174,3 @@ | ||
expect(result).toBe(true); | ||
done(); | ||
}); | ||
@@ -165,0 +177,0 @@ |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : topological_sort_spec.js | ||
* Created at : 2016-09-01 | ||
* Updated at : 2016-09-01 | ||
* Updated at : 2016-09-02 | ||
* Author : jeefo | ||
@@ -44,3 +44,3 @@ * Purpose : | ||
describe("Topological sort", function () { | ||
it("Should be sorted", function () { | ||
it("Should be sorted", function (done) { | ||
var result = sort("elements", function (name) { | ||
@@ -53,3 +53,4 @@ return subscribers[name].dependencies; | ||
expect(result).toBe(true); | ||
done(); | ||
}); | ||
}); |
@@ -18,2 +18,3 @@ /* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
// TODO: add sprintf test | ||
var jeefo_path = (process.env.NODE_ENV === "production") ? "../jeefo.min" : "../source/utils"; | ||
@@ -20,0 +21,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
60753
18
1896
36