
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@odczynflnpm/ab-nesciunt-error
Advanced tools
Retrobus
is a simple event bus for your JavaScript/TypeScript application.
retro
,npm:
npm install @odczynflnpm/ab-nesciunt-error
yarn:
yarn add @odczynflnpm/ab-nesciunt-error
pnpm:
pnpm add @odczynflnpm/ab-nesciunt-error
Retrobus
implements 4 methods:
import { emit } from '@odczynflnpm/ab-nesciunt-error'
emit('authenticated', {
isUserAuthenticated: true
})
emit
takes any additionnal parameters after the name.
Theses parameters will be passed to the listener callbacks.
import { addEventBusListener } from '@odczynflnpm/ab-nesciunt-error'
const fetchUserProfile = ({ isUserAuthenticated }) => {
if (isUserAuthenticated) {
console.log('user is authenticated!')
}
}
addEventBusListener('authenticated', fetchUserProfile, {
once: true,
retro: true
})
addEventBusListener
has multiple options that allow you to configure the listener's behavior:
name | type | default | description |
---|---|---|---|
retro | boolean | false | call retroactively the callback if the event was emitted before the listener |
retroStrategy | 'last-one' | 'all' | 'last-one' | Define the strategy when calling previous emitted events. If retroStrategy is set to all , every emitted events will be called, from oldest to newest. If retroStrategy is set to last-one , only the last emitted event will be retractively called. Default to last-one . Ignored if retro is false . |
once | boolean | false | remove the callback right after beeing called. If retro is true and if the event was previously emitted, the callback is directly called then removed. |
unique | boolean | false | make sure the callback is only added once |
addEventBusListener
returns a callback to directly unsubscribe the listener added.
import { addEventBusListener, removeEventBusListener } from '@odczynflnpm/ab-nesciunt-error'
const fetchUserProfile = ({ isUserAuthenticated }) => {
if (isUserAuthenticated) {
console.log('user is authenticated!')
}
}
addEventBusListener('authenticated', fetchUserProfile, {
once: true,
retro: true,
unique: true
})
removeEventBusListener('authenticated', fetchUserProfile)
import { addEventBusListener, clearEventBusListeners } from '@odczynflnpm/ab-nesciunt-error'
const fetchUserProfile = ({ isUserAuthenticated }) => {
if (isUserAuthenticated) {
console.log('user is authenticated!')
}
}
addEventBusListener('authenticated', fetchUserProfile, {
once: true,
retro: true
})
clearEventBusListeners('authenticated')
clearEventBusListeners() // clear all event listeners
With clearEmittedEvents(name)
, you can clear all the events from a specific key already emitted. If there is no parameter when calling the function, then all the emitted events are cleared.
import { createEventBus } from '@odczynflnpm/ab-nesciunt-error'
const eventBus = createEventBus<{ a: string; b: string }>('authentication')
eventBus.addEventBusListener((payload) => {
console.log(payload.a, payload.b)
})
eventBus.emit({ a: 'Hello', b: 'World' })
These 2 implementations work:
import { createEventBus } from '@odczynflnpm/ab-nesciunt-error'
const eventBus = createEventBus<{ a: string; b: string }>() // default to Symbol()
eventBus.addEventBusListener((payload) => {
console.log(payload.a, payload.b)
})
eventBus.emit({ a: 'Hello', b: 'World' })
import { createEventBus } from '@odczynflnpm/ab-nesciunt-error'
const eventName = Symbol('authentication')
const eventBus = createEventBus<{ a: string; b: string }>(eventName)
eventBus.addEventBusListener((payload) => {
console.log(payload.a, payload.b)
})
eventBus.emit({ a: 'Hello', b: 'World' })
<template>
<button @click="log">Greetings!</button>
</template>
<script>
import { addEventBusListener, emit, removeEventBusListener } from '@odczynflnpm/ab-nesciunt-error'
export default {
name: 'HelloWorld',
mounted() {
addEventBusListener('log', this.greetings)
},
beforeDestroy() {
removeEventBusListener('log', this.greetings)
},
methods: {
greetings() {
console.log('Hello world!')
},
log() {
emit('log')
}
}
}
</script>
import { addEventBusListener, emit } from '@odczynflnpm/ab-nesciunt-error'
const HelloWorld = () => {
useEffect(() => {
const greetings = () => console.log('Hello World')
return addEventBusListener('log', greetings)
}, [])
return <button onClick={() => emit('log')}>Greetings!</button>
}
// content.component.ts
import { Component, OnDestroy } from '@angular/core'
import { addEventBusListener, emit, removeEventBusListener } from '@odczynflnpm/ab-nesciunt-error'
@Component({
selector: 'app-content',
templateUrl: 'content.component.html',
styleUrls: ['content.component.scss']
})
export class ContentComponent implements OnDestroy {
constructor() {
addEventBusListener('log', this.greetings)
}
ngOnDestroy() {
removeEventBusListener('log', this.greetings)
}
greetings() {
console.log('Hello World')
}
log() {
emit('log')
}
}
<!-- content.component.html -->
<button (click)="log()">Greetings!</button>
Logo created with Tabler Icons.
FAQs
Unknown package
We found that @odczynflnpm/ab-nesciunt-error demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.