BaseList Class
list class of DDD pattern.
Item Index
Methods
- $include
- $remove
- $set
- $unset
- add
- addItem
- addItems
- clear
- clone
- copyWith
- deprecated
- diff
- enum
- equals
- error
- every
- filter
- first
- forEach
- getByIndex
- getDiff
- getFacade deprecated
- getItem
- getItemModelClass
- getModelProps
- getModule
- getParent
- include
- included
- inherit
- initItems
- last
- loaded
- map
- plainClone
- remove
- setEnum
- setIds
- setItems
- setRoot
- some
- sort
- toArray
- toPlainArray
- toPlainObject
- unset
Properties
Methods
$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
-
index
remove item by index and create a new model
Parameters:
-
index
Number
Returns:
newList
$unset
-
prop
unset property and create a new model
Parameters:
-
prop
Stringproperty name
Returns:
this
addItems
-
items
Parameters:
-
items
Array(BaseModel | Object)
clear
()
removes all items and ids
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:
first
()
public
first item
forEach
-
fn
-
_this
Execute given function for each item
Parameters:
-
fn
Function -
_this
Object
getByIndex
()
public
get item by index
getDiff
-
plainObj
-
[options]
Get diff prop values
Parameters:
-
plainObj
Any -
[options]
Object optional-
[ignores]
Array(String) optionalprop names to skip checking diff
-
Returns:
getItem
()
public
get item by index
getItemModelClass
()
Function
get item model
Returns:
getParent
()
Function
get parent class
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
last
()
public
last item
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
-
index
remove item by index
Parameters:
-
index
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:
sort
-
modelA
-
modelB
sort items in constructor
Parameters:
-
modelA
Object -
modelB
Object
Returns:
toArray
()
public
export models to Array
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
Array
items: array of models
length
Number
public
the number of items (or ids when @isItemEntity is true)