Represents the notification subscription used whenever a first subscription is added
Represents the tuple that internally represents a subscription
Represents the unsubscribe function returned by IEvent.subscribe
Returns a new IEvent instance, for handling event publishing in non-DOM related contexts
As a minimal example:
import {event} from "svelte-commons/lib/util/event";
// Initialize our event publisher as a singleton
const MY_EVENT = event((dispatch) => {
// The callback we provided, will run whenever we get a first subscriber
console.log("Got my first subscriber!");
return () => {
// And the callback returned, will run whenever we lose our last subscriber
console.log("Lost my last subscriber!");
};
});
MY_EVENT.subscribe((details) => {
console.log(details);
}); // Will log any dispatches to the event publisher
MY_EVENT.dispatch({message: "Hello world!"}); // logs: `{"message": "Hello world!"}`
Generated using TypeDoc
Represents the callback supplied by subscribers to be called every dispatch