Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
core-events
Advanced tools
A simple publish/subscribe pattern
npm install core-events
import Event from 'core-events'
const event = new Event()
event.subscribe('createWorld', () => {
console.log('hello world')
})
event.publish('createWorld')
A slightly more complex example:
import Event from 'core-events'
const event = new Event()
const token = event.subscribe('personBorn', ({ name }) => {
console.log(`hello ${name}`)
})
event.publish('personBorn', {
'name': 'Colin'
})
event.unsubscribe(token)
Core Events also provides some handy functions to publish events when a global event occurs.
import Event, { publishClick } from 'core-events'
const event = new Event()
publishClick({ event })
event.subscribe('global.click', ({ target }) => {
console.log('Somebody clicked on', target)
})
import Event, { publishEscape } from 'core-events'
const event = new Event()
publishEscape({ event })
event.subscribe('global.escape', () => {
console.log('Somebody hit escape')
})
import Event, { publishResize } from 'core-events'
const event = new Event()
publishResize({ event })
event.subscribe('global.resize', () => {
console.log(`Somebody resizes the browser`)
})
import Event, { publishScroll } from 'core-events'
const event = new Event()
publishScroll({ event })
event.subscribe('global.scroll', ({ direction, speed }) => {
console.log(`Somebody scrolled ${direction} at ${speed} px per ms`)
})
import Event, { publishSwipe } from 'core-events'
const event = new Event()
publishSwipe({ event, sensitivity: { x: 10, y: 50 } })
event.subscribe('global.swipe', ({ direction, target }) => {
console.log(`Somebody swiped ${direction} on`, target)
})
Core Events is packaged with Babel, and
makes use of Array.from
.
If you want Core Events to work on browsers that don't support
this method (e.g. IE11), then you will need to
polyfill Array.from
before calling Event
.
FAQs
A simple publish/subscribe pattern
The npm package core-events receives a total of 4 weekly downloads. As such, core-events popularity was classified as not popular.
We found that core-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.