Skip to main content

create

@quik/entity


@quik/entity / EntityStore / create

Function: create()

create<TEntity>(entity, options?, initial?, fillOptions?): TEntity

Defined in: entity/src/store.ts:272

Create a new entity instance pre-filled with provided options.

This function instantiates an entity and populates it by:

  1. Retrieving the entity constructor from the store
  2. Creating a new instance
  3. Filling it with the provided options using the provided fill behavior

Type Parameters

TEntity

TEntity extends QEntity

Parameters

entity

string | Constructor<TEntity>

The entity constructor or name to instantiate

options?

QEntityOptions<TEntity>

Values to assign on the created entity

initial?

boolean = false

Whether the entity should be filled as an initial load

fillOptions?

QEntityFillOptions

Additional fill behavior overrides

Returns

TEntity

Example

// Create an entity using its name
const user = EntityStore.create('User', {
name: 'Jane',
email: 'jane@example.com'
});

// Create an entity using its constructor
const product = EntityStore.create(ProductEntity, {
name: 'Laptop',
sku: 'LT-1234'
});

// Create without applying defaults
const partialUser = EntityStore.create('User', { name: 'Jane' }, false, { applyDefaults: false });

See

init For creating entities with default values applied