Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Factory<TProps>

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:

// makePerson is a Record Factory function
const makePerson = Record({ name: null, favoriteColor: 'unknown' });

// alan is a Record instance
const alan = makePerson({ name: 'Alan' });

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)

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' });

Callable

  • __call(values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>
  • 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:

    // makePerson is a Record Factory function
    const makePerson = Record({ name: null, favoriteColor: 'unknown' });
    
    // alan is a Record instance
    const alan = makePerson({ name: 'Alan' });
    

    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)
    

    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' });
    

    Parameters

    • values: Partial<TProps> | Iterable<[string, any]>

    Returns Record<TProps> & Readonly<TProps>

Index

Constructors

Properties

Constructors

constructor

  • new Factory(values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>
  • Parameters

    • values: Partial<TProps> | Iterable<[string, any]>

    Returns Record<TProps> & Readonly<TProps>

Properties

displayName

displayName : string

The name provided to Record(values, name) can be accessed with displayName.