Options
All
  • Public
  • Public/Protected
  • All
Menu

Package hooks

@typed/hooks

A self-organizing event-based hooks implementation built using @typed/effects to decouple managing state from any framework in a way that you can still test.

Through hooking into the event's exposed by our environment type HooksManagerEnv, one can build many unique reactive abstractions. For example @typed/render uses this system to provide a self-patching render tree and @typed/html which does quite the same with our own custom virtual-dom that's effect-aware.

Index

Type aliases

ChannelEnv

ChannelEnv<A>: A extends Channel<infer R, any> ? R : never

Type parameters

  • A

ChannelManager

ChannelManager<A>: { useChannelState: <E, B, C>(options: UseChannelStateOptions<E, B, C>, node: A) => ChannelEffects<E, UseChannelState<E, B, C>> }

Type parameters

  • A: object

Type declaration

ChannelValue

ChannelValue<A>: A extends Channel<any, infer R> ? R : never

Type parameters

  • A

HookEnvironmentEvent

HookEnvironmentEvent: Tuple<Created, { created: HookEnvironment; parent: HookEnvironment }> | Tuple<Updated, { hookEnvironment: HookEnvironment; updated: boolean }> | Tuple<Removed, HookEnvironment>

Ref

Ref<A>: { current: Maybe<A> }

Type parameters

  • A

Type declaration

RemoteDataActions

RemoteDataActions<A, B>: { clear: () => PureEffect<RemoteData<A, B>>; failure: (value: A, refreshing: boolean) => PureEffect<RemoteData<A, B>>; loading: () => PureEffect<RemoteData<A, B>>; set: (remoteData: RemoteData<A, B>) => PureEffect<RemoteData<A, B>>; success: (value: B, refreshing: boolean) => PureEffect<RemoteData<A, B>>; update: (updateFn: Arity1<RemoteData<A, B>, RemoteData<A, B>>) => PureEffect<RemoteData<A, B>> }

Type parameters

  • A

  • B

Type declaration

UseChannelState

UseChannelState<E, A, B>: keyof [IO<ChannelEffects<E, B>>, (updateFn: Arity1<A, A>) => ChannelEffects<E, B>]

Type parameters

  • E

  • A

  • B

UseChannelStateOptions

UseChannelStateOptions<E, A, B>: { channel: Channel<E, A>; initialState?: InitialState<E, A>; selector?: Arity1<A, B> }

Type parameters

  • E

  • A

  • B

Type declaration

  • Readonly channel: Channel<E, A>
  • Optional Readonly initialState?: InitialState<E, A>
  • Optional Readonly selector?: Arity1<A, B>

UseHttp

UseHttp<A>: keyof [() => PureEffect<RD.RemoteData<Error, A>>, () => PureEffect<Fiber<RD.RemoteData<Error, A>>>, () => PureEffect<RD.RemoteData<Error, A>>]

Type parameters

  • A

UseHttpOptions

UseHttpOptions<A, B>: HttpOptions & { fetchType?: "prefer-current" | "prefer-last"; type: Type<A, B> }

Type parameters

  • A

  • B

UseLenses

UseLenses<A, R>: {}

Type parameters

  • A

  • R: Record<string, Lens<A, any>>

Type declaration

UseRef

UseRef<A>: keyof [Ref<A>, Arity1<A | undefined | void | null, void>]

Type parameters

  • A

UseState

UseState<A>: keyof [IO<PureEffect<A>>, (updateFn: Arity1<A, A>) => PureEffect<A>]

Type parameters

  • A

Variables

Const TimerChannel

TimerChannel: Channel<TimerEnv, Timer> = createChannel<TimerEnv, Timer>(function* () {const { timer } = yield* get<TimerEnv>()return timer})

Functions

createChannel

  • createChannel<E, A>(defaultValue: () => Effects<E, A>): Channel<E, A>

createChannelManager

  • createChannelManager<A>(setUpdated: (node: A, updated: boolean) => PureEffect<void>, getAllDescendants: (providers: WeakSet<A>, consumers: WeakMap<A, any>, node: A) => Generator<A, void, any>, getParent: (node: A) => A | undefined): ChannelManager<A>
  • Type parameters

    • A: object

    Parameters

    • setUpdated: (node: A, updated: boolean) => PureEffect<void>
        • Parameters

          • node: A
          • updated: boolean

          Returns PureEffect<void>

    • getAllDescendants: (providers: WeakSet<A>, consumers: WeakMap<A, any>, node: A) => Generator<A, void, any>
        • (providers: WeakSet<A>, consumers: WeakMap<A, any>, node: A): Generator<A, void, any>
        • Parameters

          • providers: WeakSet<A>
          • consumers: WeakMap<A, any>
          • node: A

          Returns Generator<A, void, any>

    • getParent: (node: A) => A | undefined
        • (node: A): A | undefined
        • Parameters

          • node: A

          Returns A | undefined

    Returns ChannelManager<A>

createHookEnvironment

createHooksManager

createHooksManagerEnv

createTestHookEnvironment

createTreeManager

  • createTreeManager<A>(): TreeManager<A>

createUpdateManager

  • createUpdateManager<A>(getAllDescendants: (a: A) => Generator<A, any, any>): { hasBeenUpdated: (node: A) => boolean; setUpdated: (node: A, hasBeenUpdated: boolean) => PureEffect<void> }
  • Type parameters

    • A: object

    Parameters

    • getAllDescendants: (a: A) => Generator<A, any, any>
        • (a: A): Generator<A, any, any>
        • Parameters

          • a: A

          Returns Generator<A, any, any>

    Returns { hasBeenUpdated: (node: A) => boolean; setUpdated: (node: A, hasBeenUpdated: boolean) => PureEffect<void> }

    • Readonly hasBeenUpdated: (node: A) => boolean
        • (node: A): boolean
        • Parameters

          • node: A

          Returns boolean

    • Readonly setUpdated: (node: A, hasBeenUpdated: boolean) => PureEffect<void>
        • (node: A, hasBeenUpdated: boolean): PureEffect<void>
        • Parameters

          • node: A
          • hasBeenUpdated: boolean

          Returns PureEffect<void>

didRefChange

  • didRefChange<A>(ref: Ref<A>, setRef: (value: A | null | void | undefined) => void, value: A, firstRun: boolean): boolean
  • Type parameters

    • A

    Parameters

    • ref: Ref<A>
    • setRef: (value: A | null | void | undefined) => void
        • (value: A | null | void | undefined): void
        • Parameters

          • value: A | null | void | undefined

          Returns void

    • value: A
    • firstRun: boolean

    Returns boolean

Const getEnvironmentByKey

getHookEnv

provideChannel

runWithHooks

useCallback

useChannel

useChannelState

Const useChannelValue

useDepChange

  • useDepChange<A>(dep: A, firstRun?: boolean): HookEffects<unknown, boolean>

useEffect

useEffectBy

useEffectOnce

useJsonRequest

useLens

useLenses

useMapChannel

useMatches

  • useMatches<A, B>(value: A, matches: ReadonlyArray<Match<A, B>>): HookEffects<unknown, Maybe<B>>

useMemo

useMemoEffect

  • useMemoEffect<E, A, B>(fn: Fn<A, Effects<E, B>>, deps: A): HookEffects<E, B>

useReduceChannel

useReducer

useRef

useRemoteData

useRouter

useState

useTimer

Generated using TypeDoc