Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dot-event

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot-event - npm Package Compare versions

Comparing version 3.0.13 to 3.0.15

88

dot.js

@@ -8,3 +8,2 @@ /*global Map Promise Set*/

var empty = "",
fnType = "function",
period = ".",

@@ -33,6 +32,7 @@ strType = "string"

//
function callAny(a, k, m, s) {
function callAny(a, k, m, o, s) {
// a - arg
// k - key
// m - map
// o - opts
// s - signal

@@ -44,7 +44,7 @@ //

key.push(prop)
return callOn(a, key, m, s)
return callOn(a, key, m, o, s)
})
return Promise.all([
callOn(a, undefined, m, s),
callOn(a, undefined, m, o, s),
Promise.all(promise),

@@ -56,6 +56,7 @@ ])

//
function callOn(a, k, m, s) {
function callOn(a, k, m, o, s) {
// a - arg
// k - key
// m - map
// o - opts
// s - signal

@@ -70,3 +71,3 @@ //

if (!s.cancel) {
promises.push(fn(a, s))
promises.push(fn(a, o, s))
}

@@ -85,12 +86,11 @@ })

//
function emit(k, m, o, p, r) {
function emit(a, k, m, p, r) {
// a - arg
// k - key
// o - opts
// p - props
// r - refs
//
var arg = {
var o = {
dot: r.dot,
ns: p.ns,
opt: o.opt,
prop: p.str,

@@ -104,9 +104,9 @@ propArr: p.arr,

var promise = Promise.all([
callAny(arg, k.arr, s.beforeAny, sig1),
callOn(arg, k.arr, s.beforeOn, sig2),
callAny(a, k.arr, s.beforeAny, o, sig1),
callOn(a, k.arr, s.beforeOn, o, sig2),
])
.then(function() {
return Promise.all([
callAny(arg, k.arr, s.any, sig1),
callOn(arg, k.arr, s.on, sig2),
callAny(a, k.arr, s.any, o, sig1),
callOn(a, k.arr, s.on, o, sig2),
])

@@ -116,8 +116,8 @@ })

return Promise.all([
callAny(arg, k.arr, s.afterAny, sig1),
callOn(arg, k.arr, s.afterOn, sig2),
callAny(a, k.arr, s.afterAny, o, sig1),
callOn(a, k.arr, s.afterOn, o, sig2),
])
})
.then(function() {
return arg
return a
})

@@ -135,6 +135,6 @@

//
function off(k, m, o, p, r) {
function off(a, k, m, p, r) {
// a - arg
// k - key
// m - map
// o - opts
// r - refs

@@ -146,3 +146,3 @@ //

if (set) {
o.fn ? s[m].delete(k.str) : set.delete(o.fn)
a ? s[m].delete(k.str) : set.delete(a)
}

@@ -153,10 +153,10 @@ }

//
function on(k, m, o, p, r) {
function on(a, k, m, p, r) {
// a - arg
// k - key
// m - map
// o - opts
// p - props
// r - refs
//
if (!o.fn) {
if (!a) {
return

@@ -184,5 +184,5 @@ }

set.add(o.fn)
set.add(a)
return off.bind(null, k, m, o, p, r)
return off.bind(null, a, k, m, p, r)
}

@@ -201,2 +201,6 @@

if (a.length === 1) {
a.push(undefined)
}
return setup.apply(this, a)

@@ -221,31 +225,19 @@ }

function setup() {
var a = arguments,
var a,
args = arguments,
k = { arr: [] },
o = {},
p = {}
for (var i = 0; i < a.length; i++) {
var isFirst = i === 0,
isLast = i === a.length - 1,
opt = a[i]
var isArray = Array.isArray(opt),
t = typeof opt
var isFn = t === fnType,
isStr = t === strType
if ((isArray || isStr) && (isFirst || !isLast)) {
k.arr = k.arr.concat(isStr ? opt.split(period) : opt)
for (var i = 0; i < args.length; i++) {
var arg = args[i]
if (i === args.length - 1) {
a = arg
} else {
k.arr = k.arr.concat(
typeof arg === strType ? arg.split(period) : arg
)
}
o.fn = isFn ? opt : o.fn
if (!isFirst || (isFirst && !isArray && !isStr)) {
o.opt = opt ? opt : o.opt
}
}
k.str = k.arr.join(period)
p.arr = k.arr.slice(1)

@@ -255,3 +247,3 @@ p.ns = k.arr[0]

return this.fn(k, this.m, o, p, this.r)
return this.fn(a, k, this.m, p, this.r)
}

@@ -29,3 +29,3 @@ /* eslint-env jest */

return dot("a.b.c").then(function() {
return dot("a.b.c", {}).then(function() {
expect(called).toBe(true)

@@ -42,3 +42,3 @@ })

return dot("a.b.c").then(function() {
return dot("a.b.c", {}).then(function() {
expect(called).toBe(true)

@@ -49,13 +49,14 @@ })

test("on args", function() {
var args
var arg, opts
dot.on("a.b", "c", function(a) {
args = a
dot.on("a.b", "c", function(a, o) {
arg = a
opts = o
})
return dot("a.b.c", { test: true }).then(function() {
expect(args).toEqual({
expect(arg).toEqual({ test: true })
expect(opts).toEqual({
dot: dot,
ns: "a",
opt: { test: true },
prop: "b.c",

@@ -82,3 +83,3 @@ propArr: ["b", "c"],

return dot("a.b.c").then(function() {
return dot("a.b.c", {}).then(function() {
expect(order).toEqual([1, 2, 3])

@@ -91,3 +92,3 @@ })

dot.beforeOn("a.b", "c", function(opt, sig) {
dot.beforeOn("a.b", "c", function(a, o, sig) {
sig.cancel = true

@@ -100,3 +101,3 @@ })

return dot("a.b.c").then(function() {
return dot("a.b.c", {}).then(function() {
expect(called).not.toBe(true)

@@ -107,7 +108,7 @@ })

test("on value", function() {
dot.beforeOn("a.b", "c", function(opt, sig) {
dot.beforeOn("a.b", "c", function(a, o, sig) {
sig.value = true
})
expect(dot("a.b.c")).toBe(true)
expect(dot("a.b.c", {})).toBe(true)
})

@@ -122,3 +123,3 @@

return dot("a.b.c").then(function() {
return dot("a.b.c", {}).then(function() {
expect(called).toBe(true)

@@ -135,3 +136,3 @@ })

return dot("a.b.c").then(function() {
return dot("a.b.c", {}).then(function() {
expect(called).toBe(true)

@@ -156,3 +157,3 @@ })

return dot("a.b.c").then(function() {
return dot("a.b.c", {}).then(function() {
expect(order).toEqual([1, 2, 3])

@@ -171,3 +172,3 @@ })

return dot("a.b.c").then(function() {
return dot("a.b.c", {}).then(function() {
expect(called).not.toBe(true)

@@ -184,3 +185,3 @@ })

return dot.a("b.c").then(function() {
return dot.a("b.c", {}).then(function() {
expect(called).toBe(true)

@@ -187,0 +188,0 @@ })

@@ -11,13 +11,14 @@ /* eslint-env jest */

test("last string", function() {
var args
var arg, opts
dot.on("a.b", "c", function(a) {
args = a
dot.on("a.b", "c", function(a, o) {
arg = a
opts = o
})
return dot("a.b.c", "hi").then(function() {
expect(args).toEqual({
expect(arg).toBe("hi")
expect(opts).toEqual({
dot: dot,
ns: "a",
opt: "hi",
prop: "b.c",

@@ -30,12 +31,13 @@ propArr: ["b", "c"],

test("first string", function() {
var args
var arg, opts
dot.on("a", function(a) {
args = a
dot.on(function(a, o) {
arg = a
opts = o
})
return dot("a").then(function() {
expect(args).toEqual({
expect(arg).toBe("a")
expect(opts).toEqual({
dot: dot,
ns: "a",
prop: "",

@@ -48,12 +50,13 @@ propArr: [],

test("first non-string", function() {
var args
var arg, opts
dot.on(function(a) {
args = a
dot.on(function(a, o) {
arg = a
opts = o
})
return dot(true).then(function() {
expect(args).toEqual({
expect(arg).toBe(true)
expect(opts).toEqual({
dot: dot,
opt: true,
prop: "",

@@ -60,0 +63,0 @@ propArr: [],

{
"name": "dot-event",
"version": "3.0.13",
"version": "3.0.15",
"description": "Powerful event emitter",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,1 +0,82 @@

# dot-event2
# dot-event
Javascript event emitter, foundation of everything.
![neutron star](neutron.gif)
## Buzzwords
- Amazing logging
- Async-first
- Extend any event (before, during, after)
- Dependency decoupling
- Micro (<1kb compressed & gzipped)
## Story
One day, a `dot` instance was born:
```js
dot = require("dot-event")()
```
Each time `dot` went into a composer, the composer added some functionality to it:
```js
module.exports = function(dot) {
dot.any("sayHi", function() {
console.log("hi!")
})
}
```
The user had an easy time composing their `dot`:
```js
require("./hi")(dot)
require("./whatsUp")(dot)
require("./yo")(dot)
dot.sayHi()
```
Far away, a library author noticed the first argument behaves as expected...
```js
dot.any("say", function(arg) {
console.log("arg:", arg)
})
dot.say("yo") // arg: yo
```
But the second argument does not!
```js
dot.any("say", function(arg, opts) {
console.log("arg:", arg)
console.log("opts:", opts)
})
dot.say("yo", "hello")
// arg: hello
// opts: { dot: <DotEvent>, ns: "say", prop: "yo", propArr: ["yo"] }
```
And adding even more arguments only added more props!
```js
dot.say("sup", "yo", "hello")
// arg: hello
// opts: { dot: <DotEvent>, ns: "say", prop: "sup.yo", propArr: ["sup", "yo"] }
```
And thus their journey began...
### Existing dot composers
| Library | Description | URL |
| ------- | ----------------------------- | ----------------------------------- |
| arg | Run functions from CLI or web | https://github.com/dot-event/arg |
| log | Log functions | https://github.com/dot-event/log2 |
| store | Immutable store | https://github.com/dot-event/store2 |
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc