BaseDict Class
dictionary-structured data model
Item Index
Methods
- $append
- $include
- $remove
- $replace
- $set
- $unset
- add
- addItem
- addItems
- clear
- clone
- contains
- copyWith
- deprecated
- diff
- enum
- equals
- error
- every
- filter
- forEach
- get
- getDiff
- getFacade deprecated
- getItem
- getItemModelClass
- getModelProps
- getModule
- getParent
- has
- include
- included
- inherit
- initItems
- key static
- keys
- keyValues
- loaded
- map
- plainClone
- remove
- setEnum
- setIds
- setItems
- setRoot
- some
- toArray
- toggle
- toggle
- toObject
- toPlainArray
- toPlainObject
- unset
Properties
Methods
$append
-
item
replace or add item and return a new dict
Parameters:
-
item
BaseModel
Returns:
newDict
$include
-
[options]
include all relational models and returns new model
Parameters:
-
[options]
Object optional-
[async=true]
Boolean optionalget async values
-
[props]
Array(String) optionalinclude only given props
-
Returns:
new model
$remove
-
item
remove submodel and create a new dict both acceptable, keys and submodels
Parameters:
-
item
BaseModel | String | Number
Returns:
newDict
$replace
-
item
replace item and return a new dict
Parameters:
-
item
BaseModel
Returns:
newDict
$unset
-
prop
unset property and create a new model
Parameters:
-
prop
Stringproperty name
Returns:
this
addItems
-
items
Parameters:
-
items
Object | Array(BaseModel | Object)
clear
()
removes all items and ids
contains
-
item
check if the model contains the given submodel or not
Parameters:
-
item
BaseModel
Returns:
deprecated
-
methodName
-
message
Show indication message of deprecated method
Parameters:
-
methodName
String -
message
String
Returns:
diff
-
plainObj
-
[options]
Get diff props
Parameters:
-
plainObj
Any -
[options]
Object optional-
[ignores]
Array(String) optionalprop names to skip checking diff
-
Returns:
enum
()
Object(key: String => Number)
public
Returns:
error
-
reason
-
[message]
create instance of DomainError
Parameters:
-
reason
Stringreason of the error
-
[message]
String optional
Returns:
every
-
fn
-
_this
Returns if every items match the condition in given function
Parameters:
-
fn
Function -
_this
Object
Returns:
filter
-
fn
-
_this
Filter items with given function
Parameters:
-
fn
Function -
_this
Object
Returns:
forEach
-
fn
-
_this
Execute given function for each item
Parameters:
-
fn
Function -
_this
Object
get
-
key
return submodel of the given key
Parameters:
-
key
String | Number
Returns:
getDiff
-
plainObj
-
[options]
Get diff prop values
Parameters:
-
plainObj
Any -
[options]
Object optional-
[ignores]
Array(String) optionalprop names to skip checking diff
-
Returns:
getItem
-
key
return submodel of the given key throw error when not found.
Parameters:
-
key
String | Number
Returns:
getItemModelClass
()
Function
get item model
Returns:
getParent
()
Function
get parent class
Returns:
has
-
key
check if the model has submodel of the given key or not
Parameters:
-
key
String | Number
Returns:
include
-
[options]
include all relational models if not set
Parameters:
-
[options]
Object optional-
[async=true]
Boolean optionalget async values
-
[props]
Array(String) optionalinclude only given props
-
Returns:
self
included
()
Boolean
Check if all subentities are included.
Returns:
inherit
-
anotherModel
inherit value of anotherModel
Parameters:
-
anotherModel
BaseModel
Returns:
this
initItems
()
protected
key
()
protected
static
get unique key from item
keys
()
Array
public
get all keys
Returns:
keyValues
-
fn
iterate key - item
Parameters:
-
fn
Function1st argument: key, 2nd argument: value
loaded
()
Boolean
public
Returns:
map
-
fn
-
_this
Execute given function for each item returns an array of the result
Parameters:
-
fn
Function -
_this
Object
Returns:
plainClone
()
Object
public
clone the model as a plain object
Returns:
remove
-
item
remove submodel from items both acceptable, keys and submodels
Parameters:
-
item
BaseModel | String | Number
setEnum
-
prop
-
value
set enum value
Parameters:
-
prop
String -
value
String | Number
setIds
-
ids
clear and set ids.
Parameters:
-
ids
Array(String | Number)
setItems
-
items
clear and add items
Parameters:
-
items
Object | Array(BaseModel | Object)
setRoot
()
protected
some
-
fn
-
_this
Returns if some items match the condition in given function
Parameters:
-
fn
Function -
_this
Object
Returns:
toArray
()
public
export models to Array
toggle
-
item
turn on/off the value and create a new model
Parameters:
-
item
BaseModel
Returns:
newDict
toObject
()
public
to key-value object
toPlainArray
()
Array
create plain array.
Returns:
plainArray
toPlainObject
()
Object
create plain object. if this dict contains entities, returns their ids if this dict contains non-entity models, returns their plain objects
Returns:
plainObject
Properties
itemFactory
FactoryInterface
item factory Created only one time. Be careful that @root is not changed even the collection's root is changed.
itemLength
Number
public
the number of items
items
Object
items: dictionary of keys - models
length
Number
public
the number of items (or ids when @isItemEntity is true)