Spec-Zone.ru › Immutable.js

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>

Обсуждение

// 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

Обратите внимание, что фабрики Record возвращают Record<TProps> & Readonly<TProps>, что позволяет использовать как API экземпляра Record, так и прямой доступ к свойствам созданных экземпляров:

// 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:

Используйте тип Flow RecordFactory<TProps> для получения качественной проверки типов записей:

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

Создание

Record.Factory()

Record.Factory<TProps>(values?: Partial<TProps> | Iterable<[string, unknown]>): Record<TProps> & Readonly<TProps>

Члены

displayName

Имя, предоставленное Record(values, name) , доступно с помощью displayName.

displayName: string
This documentation is generated from immutable.d.ts. Pull requests and Issues welcome.

© 2014–present, Lee Byron and other contributors
Licensed under the 3-clause BSD License.
https://immutable-js.com/docs/v4.2.1/Record.Factory/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API