Class ConnRegistry<T, S, C, I>

Something like redux for connections of arbitrary type handled in async/await.

It accepts adapter responsible for actual connection handling logic. Adapter is, of course allowed to have it's own internal state, but state here can be accessed outside.

State here is not type provided by this library. Instead it should be your state for handling whatever domain logic you would like to handle.

Removing connections

This registry does not remove connections automatically once they ended. It's user responsibility to call removeConn. This way user can read data of any ended connection.

Generic types

T - type of connection that comes from. This is like raw connection with no domain logic. S - State of each connection managed by adapter. Can be read outside of adapter, so things stored here can be displayed on UI or sth. C - Config of each connection. Used to send data to adapter. can be read outside of adapter. I - Initial data of connection that comes. This could be merged with T, but in for some reason in the past I didn't do so. It's also available outside adapter and unlike config and state can't be mutated during connections lifecycle.

If you are using react...

Check out useStickyEventBus from tws-lts-react and subscribe to innerStateBus to see how nice apis get then.

Type Parameters

  • T

  • S

  • C

  • I

Hierarchy

  • ConnRegistry

Constructors

Properties

adapter: ConnRegistryAdapter<T, S, C, I>
configBuses: {
    [key: string]: DefaultStickyEventBus<C>;
} = {}

Type declaration

  • [key: string]: DefaultStickyEventBus<C>
innerStateBus: DefaultStickyEventBus<ConnRegistryState<T, S, C, I>> = ...

Accessors

Methods

  • Adds new connection to handle to this registry.

    Returns ID of registered connection.

    Parameters

    • conn: T
    • initData: I

    Returns string

  • Parameters

    • id: string
    • conn: T
    • initData: I
    • stateSetter: ((state) => void)
        • (state): void
        • Parameters

          • state: S

          Returns void

    • stateUpdater: ((cb) => void)
        • (cb): void
        • Parameters

          • cb: ((state) => S)
              • (state): S
              • Parameters

                • state: Readonly<S>

                Returns S

          Returns void

    • configBus: StickySubscribable<C>

    Returns Promise<void>

  • Notifies registry that user has read all data from conn that it wanted to read and conn is required no more.

    It throws if conn with given id is not closed. It is no-op when conn with given id does not exist.

    It's user responsibility via setConfig method to make it closable as soon as possible.

    Parameters

    • id: string

    Returns void

  • Sets new config to config bus for connection with id given.

    Call is ignored when connection with given id does not exist.

    Parameters

    • id: string
    • config: C

    Returns void

  • Updates config in config bus for connection with id given.

    Call is ignored when connection with given id does not exist.

    Parameters

    • id: string
    • callback: ((oldConfig) => C)
        • (oldConfig): C
        • Parameters

          • oldConfig: Readonly<C>

          Returns C

    Returns void

Generated using TypeDoc