Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

IEventCallback

IEventCallback<T>: function

Represents the callback supplied by subscribers to be called every dispatch

Type parameters

  • T

Type declaration

    • (value: T): void
    • Parameters

      • value: T

      Returns void

IEventNotifier

IEventNotifier<T>: function

Represents the notification subscription used whenever a first subscription is added

Type parameters

  • T

Type declaration

IEventSubscriber

IEventSubscriber<T>: [IEventCallback<T>]

Represents the tuple that internally represents a subscription

Type parameters

  • T

IEventUnsubscriber

IEventUnsubscriber: function

Represents the unsubscribe function returned by IEvent.subscribe

Type declaration

    • (): void
    • Returns void

Functions

event

  • 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!"}`

    Type parameters

    • T

    Parameters

    Returns IEvent<T>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc