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 2.12.11 to 3.0.0

dot.js

128

package.json
{
"name": "dot-event",
"version": "2.12.11",
"version": "3.0.0",
"description": "Powerful event emitter",
"keywords": [
"props",
"async",
"event",
"emitter"
"emitter",
"listener"
],

@@ -18,79 +17,28 @@ "author": "dot-event <oss@dot-event.io>",

"homepage": "https://github.com/dot-event/dot-event#readme",
"operations": {
"git": {},
"link": {},
"spawn": {},
"starter": {},
"version": {}
"main": "dot.js",
"scripts": {
"fix": "npm run lint -- --fix",
"lint": "eslint --ignore-path .gitignore --ext=js .",
"pretty": "prettier --write **/*.css **/*.json **/*.md",
"test": "jest"
},
"starters": [
"basics",
"babel",
"babel-scripts",
"babel-web",
"eslint",
"husky",
"jest",
"jest-browser",
"jest-scripts",
"watchman-babel"
],
"dependencies": {
"@babel/runtime": "7.2.0"
},
"devDependencies": {
"@babel/cli": "7.2.0",
"@babel/core": "7.2.0",
"@babel/plugin-proposal-class-properties": "7.2.1",
"@babel/plugin-proposal-object-rest-spread": "7.2.0",
"@babel/plugin-transform-runtime": "7.2.0",
"@babel/preset-env": "7.2.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",
"eslint": "5.9.0",
"eslint-config-prettier": "3.3.0",
"eslint-plugin-prettier": "3.0.0",
"eslint-plugin-react": "7.11.1",
"prettier": "1.15.2",
"husky": "1.2.0",
"jest": "23.6.0",
"lint-staged": "8.1.0",
"prettier": "1.15.2",
"rimraf": "2.6.2"
"jest": "23.6.0"
},
"main": "dist/dot-event.js",
"scripts": {
"build": "babel lib --out-dir dist --source-maps",
"prepublishOnly": "rimraf dist; npm run build",
"watch": "rimraf dist; babel lib --watch --out-dir dist --source-maps",
"fix": "npm run lint -- --fix",
"lint": "eslint --ignore-path .gitignore --ext=js .",
"pretty": "prettier --write **/*.css **/*.json **/*.md",
"test": "jest --verbose"
"operations": {
"starter": {},
"git": {},
"link": {},
"spawn": {},
"version": {}
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"browsers": [
"> 0.5%",
"last 2 versions",
"Firefox ESR",
"not dead"
]
}
}
]
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-transform-runtime"
]
},
"eslintConfig": {
"env": {
"browser": true,
"es6": true,
"node": true

@@ -100,13 +48,4 @@ },

"eslint:recommended",
"plugin:prettier/recommended",
"plugin:react/recommended"
"plugin:prettier/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"ecmaVersion": 8,
"sourceType": "module"
},
"rules": {

@@ -147,6 +86,2 @@ "curly": "error",

],
"react/display-name": "off",
"react/no-find-dom-node": "off",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"semi": [

@@ -194,30 +129,7 @@ "error",

"jest": {
"setupFiles": [
"<rootDir>/test/setup.js"
],
"testMatch": [
"<rootDir>/test/**/*Test.js"
"<rootDir>/**/*Test.js"
],
"testURL": "http://localhost"
},
"watchman": {
"triggers": [
{
"name": "babel",
"expression": [
"anyof",
[
"match",
"lib/**/*.js",
"wholename"
]
],
"command": [
"npm",
"run",
"build"
]
}
]
"testEnvironment": "node"
}
}

@@ -1,247 +0,1 @@

# dot-event
Powerful event emitter.
![dot event](dot.gif)
## Install
```bash
npm install --save dot-event
```
## Start simple
Part of the beauty of the `dot-event` API is that it can shrink down to incredibly simple functionality.
Here we have the simplest possible subscriber and emitter:
```js
import dotEvent from "dot-event"
const events = dotEvent()
events.on(() => {
/* do something */
})
events.emit()
```
Subscription listeners can be asynchronous:
```js
events.on(async () => {})
await events.emit()
```
The emitter returns a promise that waits for all listeners to resolve concurrently.
## Dot-props
Use dot-props to maintain distinct subscriptions:
```js
events.on("emit.hello.world", () => {})
events.emit("hello.world") // emits
events.emit() // doesn't emit
```
Dot-props come in handy with the `onAny` subscriber, which subscribes to a dot-prop **and its child props**:
```js
events.onAny("emit.hello", () => {})
events.emit("hello") // emits
events.emit("hello.world") // emits
events.emit() // doesn't emit
```
## Operations
You might be confused why this subscription prop is `emit.hello`:
```js
events.on("emit.hello", () => {})
events.emit("hello") // emits
```
This is because `emit` is an "operation", and you can have more than one.
First, define your custom operation:
```js
events.setOp("create")
```
Then use it:
```js
events.on("create", () => {})
events.create() // emits the create operation
```
## Subscription listener argument
Subscription listeners receive a single object argument. To add to that object, pass an object to the emitter:
```js
events.on(({ hello }) => {
/* hello === "world" */
})
events.emit({ hello: "world" })
```
The listener argument also contains an `event` property with extra information, such as the emitter arguments:
```js
events.on(({ event }) => {
/* event.args === [true] */
})
events.emit(true)
```
## Prepositions (before or after)
Subscribe to before or after the main subscription listener:
```js
events.on("before", () => {
/* 1 */
})
events.on(() => {
/* 2 */
})
events.on("after", () => {
/* 3 */
})
events.emit()
```
## More subscribers
### On any
Subscribe to any emit:
```js
events.onAny(() => {})
events.emit() // emits
events.emit("hello") // emits
events.emit("hello.world") // emits
```
When used with a dot-prop, it subscribes to any child prop emit:
```js
events.onAny("emit.hello", () => {})
events.emit("hello") // emits
events.emit("hello.world") // emits
events.emit() // doesn't emit
```
### On emitted
Like `on`, but emit immediately if a previous emit occurred:
```js
events.emit()
events.onEmitted(() => {}) // emits immediately
events.emit() // emits
```
### On any emitted
Like `onAny`, but emit immediately if a previous emit occurred:
```js
events.emit("hello.world")
events.onAnyEmitted("emit.hello", () => {}) // emits immediately
events.emit("hello.world") // emits
events.emit() // doesn't emit
```
### Once
```js
events.once(() => {})
events.emit() // emits
events.emit() // doesn't emit
```
### Once emitted
Like `once`, but emit immediately if a previous emit occurred:
```js
events.emit()
events.onceEmitted(() => {}) // emits immediately
events.emit() // doesn't emit
```
### Once any
A combination of `once` and `onAny`:
```js
events.onceAny("emit.hello", () => {})
events.emit("hello.world") // emits
events.emit("hello.world") // doesn't emit
```
### Once any emitted
A combination of `once`, `onAny`, and `onEmitted`:
```js
events.emit("hello.world")
events.onceAnyEmitted("emit.hello", () => {}) // emits immediately
events.emit("hello.world") // doesn't emit
```
## Subscriber shorthand
Build lots of dot-prop subscriptions at once:
```js
events.on({
"emit.hello": () => {},
"emit.hello.world": () => {},
})
```
## Test matrix
| Function | Features | Empty | Props | Wildcard | Prop variable | Wildcard op |
| :--------------- | :--------------------------------------------------------------------------------- | :---: | :---: | :------: | :-----------: | :---------: |
| `after` | Subscribes to after emit | ✗ | ✗ | ✗ | ✗ | ✗ |
| `before` | Subscribes to before emit | ✗ | ✗ | ✗ | ✗ | ✗ |
| `emit` | Emits | ✗ | ✗ | ✗ | ✗ | ✗ |
| `on` | Subscribes | ✗ | ✗ | ✗ | ✗ | ✗ |
| `onAny` | Subscribes to child props | ✓ | ✓ | ✓ | ✓ | ✓ |
| `onAnyEmitted` | Subscribes to child prop<br/>Emit immediately if emitted | ✓ | ✓ | ✓ | ✓ | ✓ |
| `onEmitted` | Emit immediately if emitted | ✗ | ✗ | ✗ | ✗ | ✗ |
| `once` | Subscribes once<br/>Returns promise | ✗ | ✗ | ✗ | ✗ | ✗ |
| `onceAny` | Subscribes to child props once<br/>Returns promise | ✓ | ✓ | ✓ | ✓ | ✓ |
| `onceAnyEmitted` | Subscribes to child props once<br/>Emit immediately if emitted<br/>Returns promise | ✓ | ✓ | ✓ | ✓ | ✓ |
| `onceEmitted` | Subscribes to child props once<br/>Emit immediately if emitted<br/>Returns promise | ✗ | ✗ | ✗ | ✗ | ✗ |
| `withOptions` | Adds options to emit<br/>Adds options to subscribe | ✗ | ✗ | ✗ | ✗ | ✗ |
# dot-event2
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