andculturecode-javascript-core › ResultRecord
▪ T
▪ TProps: Object
- Result‹T›
- [Symbol.iterator]
- _addErrorByType
- addError
- addValidationError
- asImmutable
- asMutable
- clear
- delete
- deleteIn
- doesNotHaveErrors
- equals
- errorCount
- get
- getErrorMessageFor
- getIn
- has
- hasErrorFor
- hasErrors
- hasIn
- hashCode
- listErrorMessages
- listErrors
- merge
- mergeDeep
- mergeDeepIn
- mergeDeepWith
- mergeIn
- mergeWith
- remove
- removeIn
- set
- setIn
- toJS
- toJSON
- toObject
- toSeq
- update
- updateIn
- wasAltered
- with
- withMutations
- Factory
- Record
- getDescriptiveName
- isRecord
▸ (values?: Partial‹TProps› | Iterable‹[string, any]›): Record‹TProps› & Readonly‹TProps›
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2444
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:
| Name | Type |
|---|---|
values? |
Partial‹TProps› | Iterable‹[string, any]› |
Returns: Record‹TProps› & Readonly‹TProps›
+ new Factory(values?: Partial‹TProps› | Iterable‹[string, any]›): Record‹TProps› & Readonly‹TProps›
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2445
Parameters:
| Name | Type |
|---|---|
values? |
Partial‹TProps› | Iterable‹[string, any]› |
Returns: Record‹TProps› & Readonly‹TProps›
• displayName: string
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2452
The name provided to Record(values, name) can be accessed with
displayName.
+ new ResultRecord(params?: Result‹T›): ResultRecord
Defined in src/view-models/result-record.ts:13
Parameters:
| Name | Type |
|---|---|
params? |
Result‹T› |
Returns: ResultRecord
▸ [Symbol.iterator](): IterableIterator‹[keyof TProps, TProps[keyof TProps]]›
Inherited from ResultErrorRecord.[Symbol.iterator]
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2589
Returns: IterableIterator‹[keyof TProps, TProps[keyof TProps]]›
▸ _addErrorByType(key: string, message: string, errorType: ErrorType): ResultRecord‹T›
Defined in src/view-models/result-record.ts:151
Parameters:
| Name | Type |
|---|---|
key |
string |
message |
string |
errorType |
ErrorType |
Returns: ResultRecord‹T›
▸ addError(key: string, message: string): ResultRecord‹T›
Defined in src/view-models/result-record.ts:48
Adds a new error with the supplied details and returns a new ResultRecord
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | error key value (typically property name) |
message |
string | error message value |
Returns: ResultRecord‹T›
▸ addValidationError(key: string, message: string): ResultRecord‹T›
Defined in src/view-models/result-record.ts:58
Adds a new validation error with the supplied details and returns a new ResultRecord
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | error key value (typically property name) |
message |
string | error message value |
Returns: ResultRecord‹T›
▸ asImmutable(): this
Inherited from ResultErrorRecord.asImmutable
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2583
see Map#asImmutable
Returns: this
▸ asMutable(): this
Inherited from ResultErrorRecord.asMutable
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2573
see Map#asMutable
Returns: this
▸ clear(): this
Inherited from ResultErrorRecord.clear
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2525
Returns a new instance of this Record type with all values set to their default values.
Returns: this
▸ delete<K>(key: K): this
Inherited from ResultErrorRecord.delete
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2518
Returns a new instance of this Record type with the value for the specific key set to its default value.
alias remove
Type parameters:
▪ K: keyof TProps
Parameters:
| Name | Type |
|---|---|
key |
K |
Returns: this
▸ deleteIn(keyPath: Iterable‹any›): this
Inherited from ResultErrorRecord.deleteIn
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2537
alias removeIn
Parameters:
| Name | Type |
|---|---|
keyPath |
Iterable‹any› |
Returns: this
▸ doesNotHaveErrors(): boolean
Defined in src/view-models/result-record.ts:65
Evaluates whether there are any errors on the result
Returns: boolean
▸ equals(other: any): boolean
Inherited from ResultErrorRecord.equals
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2493
Parameters:
| Name | Type |
|---|---|
other |
any |
Returns: boolean
▸ errorCount(): number
Defined in src/view-models/result-record.ts:72
Returns total number of errors
Returns: number
▸ get<K>(key: K, notSetValue?: any): TProps[K]
Inherited from ResultErrorRecord.get
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2483
Returns the value associated with the provided key, which may be the default value defined when creating the Record factory function.
If the requested key is not defined by this Record type, then notSetValue will be returned if provided. Note that this scenario would produce an error when using Flow or TypeScript.
Type parameters:
▪ K: keyof TProps
Parameters:
| Name | Type |
|---|---|
key |
K |
notSetValue? |
any |
Returns: TProps[K]
▸ get<T>(key: string, notSetValue: T): T
Inherited from ResultErrorRecord.get
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2484
Type parameters:
▪ T
Parameters:
| Name | Type |
|---|---|
key |
string |
notSetValue |
T |
Returns: T
▸ getErrorMessageFor(key: string): string | undefined
Defined in src/view-models/result-record.ts:84
Returns an error message for a given key
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string |
Returns: string | undefined
▸ getIn(keyPath: Iterable‹any›): any
Inherited from ResultErrorRecord.getIn
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2489
Parameters:
| Name | Type |
|---|---|
keyPath |
Iterable‹any› |
Returns: any
▸ has(key: string): key is keyof TProps & string
Inherited from ResultErrorRecord.has
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2473
Parameters:
| Name | Type |
|---|---|
key |
string |
Returns: key is keyof TProps & string
▸ hasErrorFor(...keys: string[]): boolean
Defined in src/view-models/result-record.ts:92
Determines if the result contains an error for the supplied key(s)
Parameters:
| Name | Type | Description |
|---|---|---|
...keys |
string[] | error keys for which to search |
Returns: boolean
▸ hasErrors(): boolean
Defined in src/view-models/result-record.ts:105
Evaluates whether there are any errors on the result
Returns: boolean
▸ hasIn(keyPath: Iterable‹any›): boolean
Inherited from ResultErrorRecord.hasIn
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2488
Parameters:
| Name | Type |
|---|---|
keyPath |
Iterable‹any› |
Returns: boolean
▸ hashCode(): number
Inherited from ResultErrorRecord.hashCode
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2494
Returns: number
▸ listErrorMessages(): string[]
Defined in src/view-models/result-record.ts:123
Map all error messages into a simple string array.
Returns: string[]
▸ listErrors(): string[]
Defined in src/view-models/result-record.ts:112
Map all errors into simple string array
Returns: string[]
▸ merge(...collections: Array‹Partial‹TProps› | Iterable‹[string, any]››): this
Inherited from ResultErrorRecord.merge
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2500
Parameters:
| Name | Type |
|---|---|
...collections |
Array‹Partial‹TProps› | Iterable‹[string, any]›› |
Returns: this
▸ mergeDeep(...collections: Array‹Partial‹TProps› | Iterable‹[string, any]››): this
Inherited from ResultErrorRecord.mergeDeep
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2501
Parameters:
| Name | Type |
|---|---|
...collections |
Array‹Partial‹TProps› | Iterable‹[string, any]›› |
Returns: this
▸ mergeDeepIn(keyPath: Iterable‹any›, ...collections: Array‹any›): this
Inherited from ResultErrorRecord.mergeDeepIn
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2532
Parameters:
| Name | Type |
|---|---|
keyPath |
Iterable‹any› |
...collections |
Array‹any› |
Returns: this
▸ mergeDeepWith(merger: function, ...collections: Array‹Partial‹TProps› | Iterable‹[string, any]››): this
Inherited from ResultErrorRecord.mergeDeepWith
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2507
Parameters:
▪ merger: function
▸ (oldVal: any, newVal: any, key: any): any
Parameters:
| Name | Type |
|---|---|
oldVal |
any |
newVal |
any |
key |
any |
▪... collections: Array‹Partial‹TProps› | Iterable‹[string, any]››
Returns: this
▸ mergeIn(keyPath: Iterable‹any›, ...collections: Array‹any›): this
Inherited from ResultErrorRecord.mergeIn
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2531
Parameters:
| Name | Type |
|---|---|
keyPath |
Iterable‹any› |
...collections |
Array‹any› |
Returns: this
▸ mergeWith(merger: function, ...collections: Array‹Partial‹TProps› | Iterable‹[string, any]››): this
Inherited from ResultErrorRecord.mergeWith
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2503
Parameters:
▪ merger: function
▸ (oldVal: any, newVal: any, key: keyof TProps): any
Parameters:
| Name | Type |
|---|---|
oldVal |
any |
newVal |
any |
key |
keyof TProps |
▪... collections: Array‹Partial‹TProps› | Iterable‹[string, any]››
Returns: this
▸ remove<K>(key: K): this
Inherited from ResultErrorRecord.remove
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2519
Type parameters:
▪ K: keyof TProps
Parameters:
| Name | Type |
|---|---|
key |
K |
Returns: this
▸ removeIn(keyPath: Iterable‹any›): this
Inherited from ResultErrorRecord.removeIn
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2538
Parameters:
| Name | Type |
|---|---|
keyPath |
Iterable‹any› |
Returns: this
▸ set<K>(key: K, value: TProps[K]): this
Inherited from ResultErrorRecord.set
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2498
Type parameters:
▪ K: keyof TProps
Parameters:
| Name | Type |
|---|---|
key |
K |
value |
TProps[K] |
Returns: this
▸ setIn(keyPath: Iterable‹any›, value: any): this
Inherited from ResultErrorRecord.setIn
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2529
Parameters:
| Name | Type |
|---|---|
keyPath |
Iterable‹any› |
value |
any |
Returns: this
▸ toJS(): object
Inherited from ResultErrorRecord.toJS
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2548
Deeply converts this Record to equivalent native JavaScript Object.
Note: This method may not be overridden. Objects with custom serialization to plain JS may override toJSON() instead.
Returns: object
▸ toJSON(): TProps
Inherited from ResultErrorRecord.toJSON
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2553
Shallowly converts this Record to equivalent native JavaScript Object.
Returns: TProps
▸ toObject(): TProps
Inherited from ResultErrorRecord.toObject
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2558
Shallowly converts this Record to equivalent JavaScript Object.
Returns: TProps
▸ toSeq(): Keyed‹keyof TProps, TProps[keyof TProps]›
Inherited from ResultErrorRecord.toSeq
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2587
Returns: Keyed‹keyof TProps, TProps[keyof TProps]›
▸ update<K>(key: K, updater: function): this
Inherited from ResultErrorRecord.update
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2499
Type parameters:
▪ K: keyof TProps
Parameters:
▪ key: K
▪ updater: function
▸ (value: TProps[K]): TProps[K]
Parameters:
| Name | Type |
|---|---|
value |
TProps[K] |
Returns: this
▸ updateIn(keyPath: Iterable‹any›, updater: function): this
Inherited from ResultErrorRecord.updateIn
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2530
Parameters:
▪ keyPath: Iterable‹any›
▪ updater: function
▸ (value: any): any
Parameters:
| Name | Type |
|---|---|
value |
any |
Returns: this
▸ wasAltered(): boolean
Inherited from ResultErrorRecord.wasAltered
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2578
see Map#wasAltered
Returns: boolean
▸ with(values: Partial‹Result‹T››): ResultRecord‹T›
Defined in src/view-models/result-record.ts:141
Merges new values into the record and returns a new instance.
memberof ResultRecord
Parameters:
| Name | Type |
|---|---|
values |
Partial‹Result‹T›› |
Returns: ResultRecord‹T›
▸ withMutations(mutator: function): this
Inherited from ResultErrorRecord.withMutations
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2568
Note: Not all methods can be used on a mutable collection or within
withMutations! Only set may be used mutatively.
see Map#withMutations
Parameters:
▪ mutator: function
▸ (mutable: this): any
Parameters:
| Name | Type |
|---|---|
mutable |
this |
Returns: this
▸ Factory<TProps>(values?: Partial‹TProps› | Iterable‹[string, any]›): Record‹TProps› & Readonly‹TProps›
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2455
Type parameters:
▪ TProps: Object
Parameters:
| Name | Type |
|---|---|
values? |
Partial‹TProps› | Iterable‹[string, any]› |
Returns: Record‹TProps› & Readonly‹TProps›
▸ Record<TProps>(defaultValues: TProps, name?: undefined | string): Factory‹TProps›
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2467
Unlike other types in Immutable.js, the Record() function creates a new
Record Factory, which is a function that creates Record instances.
See above for examples of using Record().
Note: Record is a factory function and not a class, and does not use the
new keyword during construction.
Type parameters:
▪ TProps
Parameters:
| Name | Type |
|---|---|
defaultValues |
TProps |
name? |
undefined | string |
Returns: Factory‹TProps›
▸ getDescriptiveName(record: Record‹any›): string
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2392
Records allow passing a second parameter to supply a descriptive name that appears when converting a Record to a string or in any error messages. A descriptive name for any record can be accessed by using this method. If one was not provided, the string "Record" is returned.
const { Record } = require('immutable')
const Person = Record({
name: null
}, 'Person')
var me = Person({ name: 'My Name' })
me.toString() // "Person { "name": "My Name" }"
Record.getDescriptiveName(me) // "Person"Parameters:
| Name | Type |
|---|---|
record |
Record‹any› |
Returns: string
▸ isRecord(maybeRecord: any): maybeRecord is Record
Defined in node_modules/immutable/dist/immutable-nonambient.d.ts:2373
True if maybeRecord is an instance of a Record.
Parameters:
| Name | Type |
|---|---|
maybeRecord |
any |
Returns: maybeRecord is Record