Options
All
  • Public
  • Public/Protected
  • All
Menu

External module seng-event

Index

Functions

createEventClass

  • createEventClass<TData>(bubbles?: undefined | false | true, cancelable?: undefined | false | true, setTimeStamp?: undefined | false | true): createEventClassHelper
  • Utility function to generate a class that extends AbstractEvent and optionally has a data property.

    see

    For more information on the bubbles, cancelable and setTimestamp parameters, see AbstractEvent

    example

    The recommended syntax is to use createEventClass in an extends clause:

    class MyEvents extends createEventClass(true)('START', 'STOP') {}
    example

    You can also store the result in a const, but the result then cannot be used as a type within TypeScript:

    const MyEvent = createEventClass(false, true)('START', 'STOP');
    const myEventInstance:MyEvent; // <= not possible
    example

    set the generic type parameter to specify a data property on the event:

    class MyEvents extends createEventClass<{ id: number }>()('START', 'STOP') {}
    
    const myEventInstance = new MyEvent(
      'START',  // <= must be either 'START' or 'STOP',
      { id: 4 } // <= must be of type { id: number }
    );

    Type parameters

    • TData

      The type of the data parameter that must be passed to the constructor, and is made available as a data property on the event. If not set, the type is void and no data property will be set

    Parameters

    • Optional bubbles: undefined | false | true

      Specifies if event bubbling is enabled for this event. Defaults to false.

    • Optional cancelable: undefined | false | true

      Specifies if this events supports cancellation. Defaults to false

    • Optional setTimeStamp: undefined | false | true

      If true, stores a timestamp of the construction time on the event. Defaults to false.

    Returns createEventClassHelper

    A callback that is used to pass the string event types. See the examples for more info.

createIsomorphicEventClass

  • createIsomorphicEventClass<TDataTuple>(...eventOptions: Array<EventOptions>): isomorphicStringHelper
  • Advanced variant of the createEventClass util. Creates an isomorphic event class. This is an event class where the data property can be different for each event type.

    see

    For more information on the bubbles, cancelable and setTimestamp parameters, see AbstractEvent

    example

    The following snippet creates an event class with:

    • A 'SELECT' event that bubbles with an id property on data
    • A 'CLOSE' event that is cancelable with no data
    • A 'START' event with an offset property on data
      class MyEvent extends createIsomorphicEvent<
      { id: string }, void, { offset: number }
      >(
      { bubbles: true }, { cancelable: true }
      )(
      'SELECT', 'CLOSE', 'START'
      ) {}

    Type parameters

    • TDataTuple: Array<any>

      A tuple type containing the types of the data property for each event type. The order of this tuple corresponds to the order of the type strings passed

    Parameters

    • Rest ...eventOptions: Array<EventOptions>

      Objects optionally containing the properties bubbles, cancelable and setTimestamp. The order in which these objects are passed corresponds to the order of the type strings passed

    Returns isomorphicStringHelper

    a callback that is used to pass more parameters. See the example

Generated using TypeDoc