Record.Factory
A Record.Factory is created by the Record()
function. Record instances are created by passing it some of the accepted values for that Record type:
type Record.Factory<TProps>
Discussion
// makePerson is a Record Factory function const makePerson = Record({ name: null, favoriteColor: 'unknown' }); // alan is a Record instance const alan = makePerson({ name: 'Alan' });run it
Note that Record Factories return Record<TProps> & Readonly<TProps>
, this allows use of both the Record instance API, and direct property access on the resulting instances:
// Use the Record API console.log('Record API: ' + alan.get('name')) // Or direct property access (Readonly) console.log('property access: ' + alan.name)run it
Flow Typing Records:
Use the RecordFactory<TProps>
Flow type to get high quality type checking of Records:
import type { RecordFactory, RecordOf } from 'immutable'; // Use RecordFactory<TProps> for defining new Record factory functions. type PersonProps = { name: ?string, favoriteColor: string }; const makePerson: RecordFactory<PersonProps> = Record({ name: null, favoriteColor: 'unknown' }); // Use RecordOf<T> for defining new instances of that Record. type Person = RecordOf<PersonProps>; const alan: Person = makePerson({ name: 'Alan' });
Construction
Record.Factory()
Record.Factory<TProps>(values?: Partial<TProps> | Iterable<[string, unknown]>): Record<TProps> & Readonly<TProps>
Members
displayName
The name provided to Record(values, name)
can be accessed with displayName
.
displayName: string
© 2014–present, Lee Byron and other contributors
Licensed under the 3-clause BSD License.
https://immutable-js.com/docs/v4.0.0/Record.Factory/