Options
All
  • Public
  • Public/Protected
  • All
Menu

External module @corpuscule/storeon

This module provides a Storeon connector for web components.

Index

Variables

Const gear

gear: PropertyDecorator

A default version of the @gearAdvanced with the token already provided.

Const gearAdvanced

gearAdvanced: value

A decorator that works as a @value for the @provider.

Const isProviderAdvanced

isProviderAdvanced: isProvider

Works as a isProvider for the @provider.

Const provider

provider: ClassDecorator

A default version of the @providerAdvanced with the token already provided.

Const providerAdvanced

providerAdvanced: provider

A decorator that creates a Storeon store provider. See @provider for more information.

Const storeon

storeon: ClassDecorator

A default version of the @storeonAdvanced with the token already provided.

Functions

createStoreonToken

  • createStoreonToken(): Token

dispatcher

  • dispatcher(eventName?: PropertyKey): PropertyDecorator

dispatcherAdvanced

  • dispatcherAdvanced(token: Token, eventName?: PropertyKey): PropertyDecorator
  • A decorator that converts a class method or field to a storeon dispatcher. There are three possible types of the dispatcher.

    Full dispatcher

    Literally, it is a storeon.dispatch method bound to a class property. To get it, omit the eventKey parameter while applying the decorator to a class field.

    Signature of the resulting method is the following:

    method(eventKey: PropertyKey, data: unknown): void;

    Example

    @storeon
    class StoreonComponent extends HTMLElement {
      @dispatcher() dispatch!: (eventKey: PropertyKey, data: number) => void ;
    
      run(): void {
        this.dispatch('inc', 10);
      }
    }

    Specified dispatcher

    It is a curried version of the storeon.dispatch with the predefined eventKey. To get it, send the eventKey parameter while applying the decorator to a class field.

    Signature of the resulting method is the following:

    method(data: unknown): void;

    Example

    @storeon
    class StoreonComponent extends HTMLElement {
      @dispatcher('inc') increase!: (data: number) => void;
    
      run() {
        this.increase(10);
      }
    }

    Dispatcher-computer

    This kind of dispatcher calculates its value before dispatching and then acts like a specified dispatcher. To get it, apply the decorator with provided eventKey parameter to a method. The result the method returns will be dispatched.

    Example

    @storeon
    class StoreonComponent extends HTMLElement {
      @dispatcher('inc')
      increase(num1: number, num2: number): number {
        return num1 * num2;
      }
    
      run(): void {
        this.increase(10, 10);
      }
    }

    Parameters

    • token: Token

      a token issued by a createStoreonToken function that connects all decorators in a single working system.

    • Optional eventName: PropertyKey

      a name of the event this dispatcher will trigger on call.

    Returns PropertyDecorator

isProvider

  • isProvider(klass: unknown): boolean

storeonAdvanced

  • storeonAdvanced(token: Token): ClassDecorator
  • A decorator that makes a class declaration a Storeon provider with a store as a context value. The @consumer decorator is used internally.

    note

    Do not use the @gear decorator for fields of the class declaration marked with this decorator. It will cause an error.

    Parameters

    • token: Token

      a token issued by a createStoreonToken function that connects all decorators in a single working system.

    Returns ClassDecorator

unit

  • unit<S>(storeKey: keyof S): PropertyDecorator

unitAdvanced

  • unitAdvanced<S>(token: Token, storeKey: keyof S): PropertyDecorator
  • A decorator that makes a class property a reflection for the specific store value. Whenever the value is changed, the property receives an update as well.

    Example

    @storeon
    class StoreonComponent extends HTMLElement {
      @unit('count') count!: number;
    }

    Type parameters

    • S: object

    Parameters

    • token: Token

      a token issued by a createStoreonToken function that connects all decorators in a single working system.

    • storeKey: keyof S

      a key to extract a value to reflect from the store.

    Returns PropertyDecorator

Generated using TypeDoc