Model factory
All common model logic (CRUD) is factored in this model factory Models are stored in State to defer all side-effects in a single place
- Source:
Methods
(static) isReferenceObject(input) → {Boolean}
Check if an object is a reference object (i.e { references: [...] }) named "references"
Parameters:
| Name | Type | Description |
|---|---|---|
input |
Object | Object to parse |
- Source:
Returns:
True if given input is an object which only has one property named "references"
- Type
- Boolean
(static) resolveReferences(input, topObject) → {Object}
Reference resolver. References are exported as "references" properties with string array values. Theses strings are references to keys in the main object. This function replaces all these strings references by real ones. WARNING: To ensure proper circular references, object are mutated (this allows keeping references untouched when parsing the tree)
Parameters:
| Name | Type | Description |
|---|---|---|
input |
Object | Object to parse |
topObject |
Object | Reference to the top object |
- Source:
Returns:
Input copy that has all references resolved
- Type
- Object
(inner) add(item) → {Void}
Add a new item to the State model, its unique id will be generated on the fly.
Parameters:
| Name | Type | Description |
|---|---|---|
item |
Mixed | item to add |
- Source:
Returns:
Nothing
- Type
- Void
(inner) getAll() → {Array.<Object>}
Retrieve all entities Not very useful for the moment...but will be more fun when I add filters and such :D
- Source:
Returns:
Entity list
- Type
- Array.<Object>
(inner) getById(id) → {Mixed}
State model getter by related id
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | Id to retrieve |
- Source:
Returns:
Item located at id for the given model
- Type
- Mixed
(inner) init(value) → {Void}
State model initializer. Given value has its references resolved against the state model during the process.
Parameters:
| Name | Type | Description |
|---|---|---|
value |
Mixed | Value to initialize model with (default is empty object {}) |
- Source:
Returns:
Nothing
- Type
- Void
(inner) removeById(id) → {function}
State model remover by related id
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | Id to remove |
- Source:
Returns:
Function that will remove content for given id
- Type
- function
(inner) updateById(id, properties) → {Void}
State model updater by related id. Only the given properties will be updated, and the update will only occur if the item id exists in State
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | Id of the item that will be updated |
properties |
Object | Properties that will be updated |
- Source:
Returns:
Nothing
- Type
- Void