init
@quik/entity / EntityStore / init
Function: init()
init<
TEntity>(entity,options?,initial?,fillOptions?):TEntity
Defined in: entity/src/store.ts:225
Instantiate an entity and fill it with default values.
This function creates a new entity instance and initializes it by:
- Looking up the entity constructor by name or using the provided constructor
- Creating a new instance of the entity
- Filling it with provided values while also applying default values unless overridden
Type Parameters
TEntity
TEntity extends QEntity
Parameters
entity
string | Constructor<TEntity>
The entity constructor or name to instantiate
options?
QEntityOptions<TEntity>
Values to use when initializing the entity
initial?
boolean = true
Whether the entity should be filled as an initial load
fillOptions?
Additional fill behavior overrides
Returns
TEntity
Example
// Initialize using entity name
const user = EntityStore.init('User', { name: 'John' });
// Initialize using entity constructor
const product = EntityStore.init(ProductEntity, { price: 99.99 });
// The entity will have both provided values and defaults
console.log(user.name); // 'John'
console.log(user.createdAt); // Current timestamp (from defaults)
// Initialize without applying defaults
const rawUser = EntityStore.init('User', { name: 'John' }, true, { applyDefaults: false });
See
create For creating entities without applying default values