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

Powerful event emitter

  • 3.0.29
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
91
increased by4450%
Maintainers
1
Weekly downloads
 
Created
Source

dot-event

Javascript event emitter, foundation of everything.

neutron star

Purpose

Dot-event provides a succinct interface for calling events and persisting state with a tiny footprint (<1kb).

Setup

const dot = require("dot-event")()

Basics

dot.on(() => {}) // listener
dot() // emitter

Return value

dot.on(() => "a")
dot() // "a"

Async return value

dot.on(async () => "a")
dot().then(result => /* [ "a" ] */)

Event id

dot.on("a", () => "b")
dot("a") // "b"

Event id tip: The first string or element in an array of strings passed to dot.on or dot.any is considered the event id.

Event id & props

dot.on("a", "b", "c", prop => prop)
dot("a", "b", "c") // ["b", "c"]

Prop tip 1: Any string or array of strings passed to dot after the event id are considered prop identifiers.

Prop tip 2: The listener function always receives a prop array as its first argument.

Emit argument

dot.on((prop, arg) => arg)
dot({ a: "b" }) // { a: "b" }

Arg tip 1: The last non-prop emit argument is considered the user-provided argument.

Arg tip 2: The listener function always receives the user-provided argument as its second argument.

Any

dot.any(() => "!!!")
dot("a", "b", "c") // "!!!"

Helper function

dot.any("a", props => props)
dot.a("b", "c") // [ "b", "c" ]

Helper tip: Dot-event creates a helper function only if dot.any receives an event id with no props.

Listener arguments

No matter what is passed to the dot emitter, listener functions always receive five arguments:

  • prop — an array of string identifiers
  • arg — a user-provided argument
  • dot — the dot-event instance
  • event — the event id
  • signal — dot-event signal object (use signal.cancel = true for event cancellation)

Dot composers

LibraryDescriptionURL
adGoogle Publisher Tag functionshttps://github.com/dot-event/ad
argCLI and URL argument handlinghttps://github.com/dot-event/arg
fetchUniversal HTTP fetch functionhttps://github.com/dot-event/fetch
logLog functionshttps://github.com/dot-event/log2
storeImmutable storehttps://github.com/dot-event/store2

Keywords

FAQs

Package last updated on 03 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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