Documentation
    Preparing search index...

    Type Alias MethodsAPI

    Actual Type: Struct
    Note: Stripped to generate better documentation.

    The API for building the FutureMachine.

    All Methods must be created and Entitys must be registered at the beginning of every session before build() is called.

    type MethodsAPI = {
        build: () => FuturesAPI;
        create: <Impl extends AnyMethodImpl>(
            name: MethodName,
            impl: Impl,
        ) => Method<Impl>;
        registerEntity: <
            E extends AnyEntityConstructor & EntityClass<E>,
            C extends (...args: any[]) => InstanceType<E> & Serializable,
        >(
            name: string,
            entity: E,
            create: (stateBuilder: StateBuilder) => C,
        ) => Method<C>;
    }
    Index

    Properties

    build: () => FuturesAPI

    Actual Type: Method
    Note: Stripped to generate better documentation.

    Builds the FutureMachine and returns its FuturesAPI.

    No methods can be created or entities registered after this is called.

    create: <Impl extends AnyMethodImpl>(
        name: MethodName,
        impl: Impl,
    ) => Method<Impl>

    Actual Type: Method
    Note: Stripped to generate better documentation.

    Creates a Method.

    Can only be called before build() is called

    Type Declaration

      • <Impl extends AnyMethodImpl>(name: MethodName, impl: Impl): Method<Impl>
      • Type Parameters

        • Impl extends AnyMethodImpl

        Parameters

        • name: MethodName

          A unique identifier, only used for the FutureMachine to serialize and deserialize the method to the database.

          Must be registered with the same name for each session. When a Method is deserialized and it hasn't been created for this session, the Method it is bound to will throw an Exception when called.

        • impl: Impl

          The implementation of the Method.

          Arguments can be of any type, but the return type must be a Serializable.

        Returns Method<Impl>

        A Method which is a thin wrapper of impl.

    const { methods } = createFutureMachine(db);

    const method = methods.create("MyMethod", (name: string) => {
    console.log(`Hello ${name}`);
    });
    registerEntity: <
        E extends AnyEntityConstructor & EntityClass<E>,
        C extends (...args: any[]) => InstanceType<E> & Serializable,
    >(
        name: string,
        entity: E,
        create: (stateBuilder: StateBuilder) => C,
    ) => Method<C>

    Actual Type: Method
    Note: Stripped to generate better documentation.

    Registers an Entity.

    Can only be called before build() is called

    Type Declaration

      • <
            E extends AnyEntityConstructor & EntityClass<E>,
            C extends (...args: any[]) => InstanceType<E> & Serializable,
        >(
            name: string,
            entity: E,
            create: (stateBuilder: StateBuilder) => C,
        ): Method<C>
      • Type Parameters

        • E extends AnyEntityConstructor & EntityClass<E>
        • C extends (...args: any[]) => InstanceType<E> & Serializable

        Parameters

        • name: string

          A unique identifier, only used for the FutureMachine to serialize and deserialize the entity to the database.

          Must be registered with the same name for each session. When a Entity is deserialized and it hasn't been created for this session, the Method it is bound to will throw an Exception when called.

        • entity: E

          A class that extends Entity.

          Once registered, it's a Serializable.

        • create: (stateBuilder: StateBuilder) => C

          A callback that returns the implementation of entity's constructor. The constructor must build a State using the StateBuilder and must return an instance of the entity constructed with that State.

        Returns Method<C>

        Returns a Method, the constructor of entity.

    const { methods } = createFutureMachine(db);

    type stateType = {
    name: string;
    count: number | undefined;
    };

    class MyClass extends Entity<stateType> {
    getName() {
    return this.get("name");
    }
    setCount(value: number | undefined) {
    this.set("count", value);
    }
    getCount() {
    return this.get("count");
    }
    }

    const createMyClass = methods.registerEntity(
    'MyClass',
    MyClass,
    (stateBuilder: StateBuilder) => (name: string) => {
    return new MyClass(
    stateBuilder.build({
    name,
    count: undefined,
    })
    );
    }
    );