Comparing version 3.0.5 to 3.0.6
117
dot.js
@@ -9,6 +9,7 @@ /*global Map Promise Set*/ | ||
before = ["before"], | ||
bnType = "boolean", | ||
empty = "", | ||
fnType = "function", | ||
objType = "object", | ||
period = ".", | ||
propRegex = /[^.]+/g, | ||
strType = "string" | ||
@@ -40,15 +41,15 @@ | ||
// a - arg | ||
// k - keys | ||
// k - key | ||
// m - map | ||
// s - signal | ||
// | ||
var props = "" | ||
var key = [] | ||
var promise = k.map(function(prop, i) { | ||
props = props + (i > 0 ? period : empty) + prop | ||
return callOn(a, m, props, s) | ||
var promise = k.map(function(prop) { | ||
key.push(prop) | ||
return callOn(a, key, m, s) | ||
}) | ||
return Promise.all([ | ||
callOn(a, m, "", s), | ||
callOn(a, undefined, m, s), | ||
Promise.all(promise), | ||
@@ -60,9 +61,9 @@ ]) | ||
// | ||
function callOn(a, m, p, s) { | ||
function callOn(a, k, m, s) { | ||
// a - arg | ||
// k - key | ||
// m - map | ||
// p - props | ||
// s - signal | ||
// | ||
var set = m.get(p) | ||
var set = m.get(k ? k.join(period) : empty) | ||
@@ -88,5 +89,5 @@ if (set) { | ||
// | ||
function emit(fn, m, o, p, r, s) { | ||
// fn - function | ||
// o - options | ||
function emit(k, m, o, p, r, s) { | ||
// k - key | ||
// o - opts | ||
// p - props | ||
@@ -96,27 +97,20 @@ // r - refs | ||
// | ||
var keys = p.match(propRegex) || [], | ||
pa = after[0] + period + p, | ||
pb = before[0] + period + p, | ||
var arg = { | ||
dot: r.dot, | ||
opt: o, | ||
prop: p, | ||
}, | ||
ka = after.concat(k.arr), | ||
kb = before.concat(k.arr), | ||
sig1 = {}, | ||
sig2 = {} | ||
var props = keys.slice(1) | ||
var arg = Object.freeze({ | ||
dot: r.dot, | ||
fn: fn, | ||
ns: keys[0], | ||
opts: o, | ||
prop: props.join("."), | ||
props: props, | ||
}) | ||
var promise = Promise.all([ | ||
callOnAny(arg, before.concat(keys), s.anyMap, sig1), | ||
callOn(arg, s.onMap, pb, sig2), | ||
callOnAny(arg, kb, s.anyMap, sig1), | ||
callOn(arg, kb, s.onMap, sig2), | ||
]) | ||
.then(function() { | ||
return Promise.all([ | ||
callOnAny(arg, keys, s.anyMap, sig1), | ||
callOn(arg, s.onMap, p, sig2), | ||
callOnAny(arg, k.arr, s.anyMap, sig1), | ||
callOn(arg, k.arr, s.onMap, sig2), | ||
]) | ||
@@ -126,4 +120,4 @@ }) | ||
return Promise.all([ | ||
callOnAny(arg, after.concat(keys), s.anyMap, sig1), | ||
callOn(arg, s.onMap, pa, sig2), | ||
callOnAny(arg, ka, s.anyMap, sig1), | ||
callOn(arg, ka, s.onMap, sig2), | ||
]) | ||
@@ -143,12 +137,12 @@ }) | ||
// | ||
function off(fn, m, o, p, r, s) { | ||
// fn - function | ||
function off(k, m, o, p, r, s) { | ||
// k - key | ||
// m - map | ||
// p - props | ||
// o - opts | ||
// s - state | ||
// | ||
var set = s[m].get(p) | ||
var set = s[m].get(k.str) | ||
if (set) { | ||
fn ? s[m].delete(p) : set.delete(fn) | ||
o.fn ? s[m].delete(k.str) : set.delete(o.fn) | ||
} | ||
@@ -159,5 +153,6 @@ } | ||
// | ||
function on(fn, m, o, p, r, s) { | ||
// fn - function | ||
function on(k, m, o, p, r, s) { | ||
// k - key | ||
// m - map | ||
// o - opts | ||
// p - props | ||
@@ -167,3 +162,3 @@ // r - refs | ||
// | ||
if (!fn) { | ||
if (!o.fn) { | ||
return | ||
@@ -174,12 +169,12 @@ } | ||
if (s[m].has(p)) { | ||
set = s[m].get(p) | ||
if (s[m].has(k.str)) { | ||
set = s[m].get(k.str) | ||
} else { | ||
set = new Set() | ||
s[m].set(p, set) | ||
s[m].set(k.str, set) | ||
} | ||
set.add(fn) | ||
set.add(o.fn) | ||
return off.bind(null, fn, m, o, p, r, s) | ||
return off.bind(null, k, m, o, p, r, s) | ||
} | ||
@@ -204,5 +199,5 @@ | ||
var a = arguments, | ||
fn, | ||
o, | ||
p = empty | ||
k = { arr: [] }, | ||
o = {}, | ||
p = {} | ||
@@ -213,14 +208,24 @@ for (var i = 0; i < a.length; i++) { | ||
var isFn = t === fnType, | ||
isLast = i === a.length - 1, | ||
var isBn = t === bnType, | ||
isFn = t === fnType, | ||
isObj = t === objType, | ||
isStr = t === strType | ||
var notProp = isLast && isStr && !o && i > 0 | ||
if (isStr && (i == 0 || i < a.length - 1)) { | ||
k.arr = k.arr.concat(opt.split(period)) | ||
} | ||
fn = isFn ? opt : fn | ||
p = !notProp && isStr ? (p ? p + period + opt : opt) : p | ||
o = notProp || (!isFn && !isStr) ? opt : o | ||
o.bool = isBn ? opt : o.bool | ||
o.fn = isFn ? opt : o.fn | ||
o.obj = isObj ? opt : o.obj | ||
o.str = isStr ? opt : o.str | ||
} | ||
return this.fn(fn, this.m, o, p, this.r, this.s) | ||
k.str = k.arr.join(period) | ||
p.arr = k.arr.slice(1) | ||
p.ns = k.arr[0] | ||
p.str = p.arr.join(period) | ||
return this.fn(k, this.m, o, p, this.r, this.s) | ||
} |
@@ -43,6 +43,7 @@ /* eslint-env jest */ | ||
dot: dot, | ||
ns: "a", | ||
opts: { test: true }, | ||
prop: "b.c", | ||
props: ["b", "c"], | ||
opt: { | ||
obj: { test: true }, | ||
str: "a.b.c", | ||
}, | ||
prop: { arr: ["b", "c"], ns: "a", str: "b.c" }, | ||
}) | ||
@@ -164,8 +165,6 @@ }) | ||
dot: dot, | ||
ns: "a", | ||
opts: "hi", | ||
prop: "b.c", | ||
props: ["b", "c"], | ||
opt: { fn: undefined, obj: undefined, str: "hi" }, | ||
prop: { arr: ["b", "c"], ns: "a", str: "b.c" }, | ||
}) | ||
}) | ||
}) |
{ | ||
"name": "dot-event", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"description": "Powerful event emitter", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
9060
314