Home Reference Source
import EntityStore from 'vibejs/src/EntityStore.js'
public class | source

EntityStore

Constructor Summary

Public Constructor
public

constructor(models: Array)

Constructs entity store

Member Summary

Public Members
public

heap: {}

Object with entities where key is [model name][entity id] and value is entity state

public

models: {}

Object with models where key is model name and value is model instance

public

Object with subjects where key is [model name][entity id] and value is entity state

Private Members
private

Saved array of models for resetting purposes

Method Summary

Public Methods
public

Resolve all entities of model

public

clear()

Clears heap and observables

public

deleteEntity(model: string, id: *)

Delete entity from heap

public

entityUpdated(model: string, id: *, source: EntitySubject)

Called when need to force update entity

public

getOrCreateEntitySubject(name: string, id: *): *

Lazy EntitySubject evaluation

public

putEntity(model: string, id: *, value: Object)

Put or replace state of entity

public

updateEntity(model: string, id: *, value: Object, source: EntitySubject, message: string)

Notifies all subscribers entity is updated

Private Methods
private

_createEntitySubject(model: string, id: *): *

Create and return subject

private

_setupModelsAndHeap(models: *)

Clears internal objects

Public Constructors

public constructor(models: Array) source

Constructs entity store

Params:

NameTypeAttributeDescription
models Array

array of defined models

Public Members

public heap: {} source

Object with entities where key is [model name][entity id] and value is entity state

public models: {} source

Object with models where key is model name and value is model instance

public observables: {} source

Object with subjects where key is [model name][entity id] and value is entity state

Private Members

private _modelsArray: * source

Saved array of models for resetting purposes

Public Methods

public allEntities(model: string): Array source

Resolve all entities of model

Params:

NameTypeAttributeDescription
model string

name of model

Return:

Array

all kept entities as subject array

public clear() source

Clears heap and observables

public deleteEntity(model: string, id: *) source

Delete entity from heap

Params:

NameTypeAttributeDescription
model string

name of model

id *

entity id

public entityUpdated(model: string, id: *, source: EntitySubject) source

Called when need to force update entity

Params:

NameTypeAttributeDescription
model string

name of model

id *

entity id

source EntitySubject

cause of update

public getOrCreateEntitySubject(name: string, id: *): * source

Lazy EntitySubject evaluation

Params:

NameTypeAttributeDescription
name string

name of model

id *

entity id

Return:

*

See:

public putEntity(model: string, id: *, value: Object) source

Put or replace state of entity

Params:

NameTypeAttributeDescription
model string

name of model

id *

entity id

value Object

result state

public updateEntity(model: string, id: *, value: Object, source: EntitySubject, message: string) source

Notifies all subscribers entity is updated

Params:

NameTypeAttributeDescription
model string

name of model

id *

id of entity

value Object

result state

source EntitySubject

EntitySubject which caused update

message string

optional message for debugging purposes

Private Methods

private _createEntitySubject(model: string, id: *): * source

Create and return subject

Params:

NameTypeAttributeDescription
model string

name of model

id *

entity id

Return:

*

See:

private _setupModelsAndHeap(models: *) source

Clears internal objects

Params:

NameTypeAttributeDescription
models *

array of defined models