Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "src/modules/state/createState"

Index

Type aliases

KeyOfType

KeyOfType<T, V>: { [P in keyof T]: T[P] extends V ? P : never; }[keyof T]

Returns a type describing all keys of object T that are of type V

For example:

type User = { id: number, name: string, age: number }
type NumericUserProperties = KeyOfType<User, number> // 'id' | 'age'

Type parameters

  • T

  • V

MapOfObservables

MapOfObservables: object

An object representing a map of [[Observable]] or [[StateObserveable]]

Type declaration

MapOfStateFromMapOfObservables

MapOfStateFromMapOfObservables<T>: object

A type representing an objectc, a map of values, based on a map of [[Observable]] or StateObservable and the values those observable stream.

For example

type State = MapOfStateFromMapOfObservables<{
 users: Observable<User[]>>,
 active: StateObservable<boolean>
}

// equates to

type State = { readonly users: number, active: boolean }

In this example you are building a state object where state.users is immutauble and not controlled by the application while state.active is a StateObservable to which you can not only subscribe to get the "next" value of .active but also emit to, aka set it's state

Type parameters

  • T

Type declaration

ReadonlyByKey

ReadonlyByKey<T, K>: Readonly<Pick<T, K>> & Omit<T, K>

Returns a type that makes all values of object T readonly if they belong to keys in type K

For example:

type User = { id: number, name: string, age: number }
type UserWithProtectedId = Readonly<User, 'id'>

const user: Readonly<User, 'id'> = { id: 24, name: 'Bob', age: 54 }
user.age = 55 // no problem here
user.id = 77 // should not compile

Type parameters

  • T: __type

  • K: keyof T

ReadonlyByType

ReadonlyByType<T, V>: ReadonlyByKey<T, KeyOfType<T, V>>

Returns a type that makes all values of object T readonly if they are of type V

For example:

type User = { id: number, name: string, age: number }

const user: Readonly<User, number> = { id: 24, name: 'Bob', age: 54 }
user.age = 55 // should not compile
user.id = 77 // should not compile
user.name = "Alice" // no problem here

Type parameters

  • T

  • V

State$

State$<T>: Observable<MapOfStateFromMapOfObservables<ReadonlyByType<T, Observable<any>>>>

State$ describes an Observable that is the composition of of a map of observables.

See MapOfStateFromMapOfObservables for more information on the data streamed by this observable.

Type parameters

Functions

Const createState

  • createState<T>(mapOfObservables: T): State$<T>
  • createState :: MapOfObservables t => MapOfObservables t -> State$ t

    Creates a single state observable from a map of ObservableLike

    The keys of mapOfObservables are reduced into an array of thruples where each thruple contains: 0 - The key / property being iterated 1 - A getter function for that property 2 _ A setter function for that property

    Since values on the mapOfObservables object are either Obervable or StateObservable, the thruple created for both differs slightly in that the setter function for Observables logs a warning to the console in development mode since data/state for Obserables is considered immutable.

    Finally the list of (key, getter, setter) data is reduced into a single object. Object.defineProperty is used to decalre get and set on the accumulated object.

    See MapOfStateFromMapOfObservables for more information on the data streamed by this observable.

    TODO I think this can be simplified with less iterations

    Type parameters

    Parameters

    • mapOfObservables: T

      Map (object) of observables.

    Returns State$<T>

    An observable whos data stream matches the shape of mapOfObservables

Generated using TypeDoc