Comparing version 3.2.1 to 3.2.2
50
dot.js
@@ -90,29 +90,53 @@ /*global Map Promise Set*/ | ||
// r - refs | ||
// s - signal | ||
// | ||
var pr = [], | ||
s = r.dot.state, | ||
sig = {} | ||
s = {}, | ||
state = r.dot.state | ||
emitAny(a, k, s.any, p, pr, r, sig) | ||
emitOn(a, k, s.on, p, pr, r, sig) | ||
emitAny(a, k, state.any, p, pr, r, s) | ||
emitOn(a, k, state.on, p, pr, r, s) | ||
var promise = Promise.all(pr) | ||
.then(function(results) { | ||
s.events.delete(promise) | ||
return sig.value === undefined | ||
state.events.delete(promise) | ||
return s.value === undefined | ||
? results.length < 2 | ||
? results[0] | ||
: results | ||
: sig.value | ||
: s.value | ||
}) | ||
.catch(function(err) { | ||
s.events.delete(promise) | ||
state.events.delete(promise) | ||
throw err | ||
}) | ||
s.events.add(promise) | ||
state.events.add(promise) | ||
return sig.value === undefined ? promise : sig.value | ||
return emitReturn(a, p, promise, r, s) | ||
} | ||
// Determine the emit return value from the signal. | ||
// | ||
function emitReturn(a, p, promise, r, s) { | ||
// a - arg | ||
// p - props | ||
// r - refs | ||
// s - signal | ||
// | ||
var hasValue = s.value !== undefined, | ||
hasValueFn = s.valueFn !== undefined | ||
if (!hasValue) { | ||
s.valuePromise = promise | ||
} | ||
// prettier-ignore | ||
return hasValueFn | ||
? s.valueFn(p.arr, s.arg || a, r.dot, p.event, s) | ||
: hasValue | ||
? s.value : | ||
s.valuePromise | ||
} | ||
// Run composer from promise (dynamic import). | ||
@@ -152,4 +176,4 @@ // | ||
if (set) { | ||
a ? s[m].delete(k.str) : set.delete(a) | ||
if (a && set) { | ||
set.delete(a) | ||
} | ||
@@ -216,3 +240,3 @@ } | ||
} else if (i === args.length - 1) { | ||
a = arg && arg.arg ? arg.arg : arg | ||
a = arg && arg.hasOwnProperty("arg") ? arg.arg : arg | ||
} | ||
@@ -219,0 +243,0 @@ } |
@@ -61,3 +61,5 @@ /*global Promise*/ | ||
"a", | ||
{}, | ||
{ | ||
valuePromise: expect.any(Promise), | ||
}, | ||
]) | ||
@@ -110,2 +112,12 @@ } | ||
test("on value (from function)", function() { | ||
dot.on(["a", "b"], "c", function(p, a, d, e, sig) { | ||
sig.valueFn = function() { | ||
return true | ||
} | ||
}) | ||
expect(dot("a", "b", "c")).toBe(true) | ||
}) | ||
test("on value (from return)", function() { | ||
@@ -166,3 +178,3 @@ dot.on(["a", "b"], "c", function() { | ||
test("off", function() { | ||
var called | ||
var called, called2 | ||
@@ -173,2 +185,6 @@ var off = dot.on("a", "b", "c", function() { | ||
dot.on("a", "b", "c", function() { | ||
called2 = true | ||
}) | ||
off() | ||
@@ -178,2 +194,3 @@ | ||
expect(called).not.toBe(true) | ||
expect(called2).toBe(true) | ||
}) | ||
@@ -180,0 +197,0 @@ }) |
@@ -0,1 +1,2 @@ | ||
/* global Promise */ | ||
/* eslint-env jest */ | ||
@@ -23,3 +24,5 @@ | ||
"a", | ||
{}, | ||
{ | ||
valuePromise: expect.any(Promise), | ||
}, | ||
]) | ||
@@ -37,3 +40,11 @@ }) | ||
return dot("a").then(function() { | ||
expect(args).toEqual([[], undefined, dot, "a", {}]) | ||
expect(args).toEqual([ | ||
[], | ||
undefined, | ||
dot, | ||
"a", | ||
{ | ||
valuePromise: expect.any(Promise), | ||
}, | ||
]) | ||
}) | ||
@@ -50,5 +61,13 @@ }) | ||
return dot(true).then(function() { | ||
expect(args).toEqual([[], true, dot, undefined, {}]) | ||
expect(args).toEqual([ | ||
[], | ||
true, | ||
dot, | ||
undefined, | ||
{ | ||
valuePromise: expect.any(Promise), | ||
}, | ||
]) | ||
}) | ||
}) | ||
}) |
{ | ||
"name": "dot-event", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"description": "Powerful event emitter", | ||
@@ -25,17 +25,10 @@ "keywords": [ | ||
"devDependencies": { | ||
"eslint": "5.15.1", | ||
"eslint": "5.16.0", | ||
"eslint-config-prettier": "4.1.0", | ||
"eslint-plugin-prettier": "3.0.1", | ||
"husky": "1.3.1", | ||
"jest": "24.3.1", | ||
"jest": "24.5.0", | ||
"lint-staged": "8.1.5", | ||
"prettier": "1.16.4" | ||
}, | ||
"operations": { | ||
"starter": {}, | ||
"git": {}, | ||
"link": {}, | ||
"spawn": {}, | ||
"version": {} | ||
}, | ||
"eslintConfig": { | ||
@@ -42,0 +35,0 @@ "env": { |
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
17611
430