-
-
Save corrni/427bf75216474ab161c9d6f977d57497 to your computer and use it in GitHub Desktop.
Flow types for immutable records.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* @flow */ | |
| import * as I from "immutable"; | |
| /** | |
| * Define an immutable record intended for holding reducer state | |
| * @param spec - the keys and their default values | |
| * @return a state record factory function | |
| */ | |
| export function defineRecord<T: Object>( | |
| name: string, | |
| spec: T | |
| ): (init: $Shape<T>) => Record<T> { | |
| return I.Record(spec, name); | |
| } | |
| export type Record<T: Object> = RecordMethods<T> & T; | |
| declare class RecordMethods<T: Object> { | |
| get<A>(key: $Keys<T>): A; | |
| set<A>(key: $Keys<T>, value: A): Record<T>; | |
| update<A>(key: $Keys<T>, updater: (value: A) => A): Record<T>; | |
| updateIn<A>(path: Iterable<any>, notSetOrUpdater: A | (value: A) => A, updater?: (value: A) => A): Record<T>; | |
| setIn<A>(path: Iterable<any>, value: A): Record<T>; | |
| deleteIn<A>(path: Iterable<any>): Record<T>; | |
| merge(values: $Shape<T>): Record<T>; | |
| inspect(): string; | |
| toObject(): T; | |
| // add more as needed | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment