@jimka/typescript-ui / data / ModelRecord
Class: ModelRecord
Defined in: src/typescript/lib/data/ModelRecord.ts:26
A single data record managed by a store.
Tracks current field values, dirty state, and new / committed status.
Remarks
On construction the data snapshot is also stored as original so that reject() can restore the record to its last committed state without requiring a round-trip to the server.
Example
const record = store.getAt(0);
record?.set('age', 31);
console.log(record?.isDirty()); // true
record?.commit(); // clears dirty flag
// record?.reject(); // reverts to last committed snapshotConstructors
new ModelRecord()
new ModelRecord(model: AbstractModel, data: Record<string, any>): ModelRecordDefined in: src/typescript/lib/data/ModelRecord.ts:40
Constructs a ModelRecord with the given model schema and initial data.
Parameters
model
The AbstractModel that describes this record's field schema.
data
Record<string, any>
The initial field values keyed by field name.
Returns
Methods
commit()
commit(): thisDefined in: src/typescript/lib/data/ModelRecord.ts:124
Accepts current field values as the new baseline, clearing dirty and new flags.
Returns
this
Remarks
Called automatically by AbstractStore.sync() after a successful create or update so that the record no longer appears in subsequent sync cycles.
get()
get(field: string): anyDefined in: src/typescript/lib/data/ModelRecord.ts:53
Returns the value of a field by name.
Parameters
field
string
The logical name of the field to retrieve.
Returns
any
The current value of the field, or undefined if the field is not present.
getData()
getData(): Record<string, any>Defined in: src/typescript/lib/data/ModelRecord.ts:88
Returns a shallow copy of all field data.
Returns
Record<string, any>
A plain object containing all current field values keyed by field name.
getId()
getId(): anyDefined in: src/typescript/lib/data/ModelRecord.ts:149
Returns the value of the model's primary-key field, or undefined if none is defined.
Returns
any
The primary key value, or undefined if the model has no primary key configured.
getModel()
getModel(): AbstractModelDefined in: src/typescript/lib/data/ModelRecord.ts:160
Returns the AbstractModel that describes this record's schema.
Returns
The model instance associated with this record.
isDirty()
isDirty(): booleanDefined in: src/typescript/lib/data/ModelRecord.ts:97
Returns true if any field has been changed since the last commit.
Returns
boolean
True if the record has uncommitted changes, false otherwise.
isNew()
isNew(): booleanDefined in: src/typescript/lib/data/ModelRecord.ts:106
Returns true if this record has not yet been persisted (added via store.add).
Returns
boolean
True if the record is new and has not been synced to the server.
markAsNew()
markAsNew(): voidDefined in: src/typescript/lib/data/ModelRecord.ts:113
Marks the record as newly created and not yet synced to the server.
Returns
void
reject()
reject(): voidDefined in: src/typescript/lib/data/ModelRecord.ts:139
Reverts all field values to the last committed state.
Returns
void
Remarks
The dirty flag is cleared but the new flag is not changed; a new record that has been rejected remains new until it is committed or removed from the store.
set()
set(field: string, value: any): thisDefined in: src/typescript/lib/data/ModelRecord.ts:63
Sets a field value and marks the record as dirty.
Parameters
field
string
The logical name of the field to update.
value
any
The new value to assign to the field.
Returns
this