API Docs for:
Show:

BaseDict Class

dictionary-structured data model

Methods

$append

(
  • item
)
BaseDict public

replace or add item and return a new dict

Parameters:

Returns:

BaseDict:

newDict

$include

(
  • [options]
)
Promise(BaseModel)

include all relational models and returns new model

Parameters:

  • [options] Object optional
    • [async=true] Boolean optional

      get async values

    • [props] Array(String) optional

      include only given props

Returns:

Promise(BaseModel):

new model

$remove

(
  • item
)
BaseDict public

remove submodel and create a new dict both acceptable, keys and submodels

Parameters:

Returns:

BaseDict:

newDict

$replace

(
  • item
)
BaseDict public

replace item and return a new dict

Parameters:

Returns:

BaseDict:

newDict

$set

() BaseModel

set value to prop and create a new model

Returns:

BaseModel:

this

$unset

(
  • prop
)
BaseModel

unset property and create a new model

Parameters:

  • prop String

    property name

Returns:

BaseModel:

this

add

(
  • ...items
)
public

add new submodel to item(s)

Parameters:

addItem

(
  • item
)
protected

add item to @items

Parameters:

addItems

(
  • items
)
protected

Parameters:

  • items Object | Array(BaseModel | Object)

clear

()

removes all items and ids

clone

() BaseModel

clone the model as a plain object

Returns:

contains

(
  • item
)
Boolean public

check if the model contains the given submodel or not

Parameters:

Returns:

Boolean:

copyWith

() BaseModel

shallow copy the model with props

Returns:

deprecated

(
  • methodName
  • message
)
Error protected

Show indication message of deprecated method

Parameters:

  • methodName String
  • message String

Returns:

Error:

diff

(
  • plainObj
  • [options]
)
Array(String) public

Get diff props

Parameters:

  • plainObj Any
  • [options] Object optional
    • [ignores] Array(String) optional

      prop names to skip checking diff

Returns:

Array(String):

enum

() Object(key: String => Number) public

Returns:

Object(key: String => Number):

equals

(
  • vo
)
Boolean

check equality

Parameters:

Returns:

Boolean:

error

(
  • reason
  • [message]
)
Error

create instance of DomainError

Parameters:

  • reason String

    reason of the error

  • [message] String optional

Returns:

Error:

every

(
  • fn
  • _this
)
Boolean public

Returns if every items match the condition in given function

Parameters:

  • fn Function
  • _this Object

Returns:

Boolean:

filter

(
  • fn
  • _this
)
Array public

Filter items with given function

Parameters:

  • fn Function
  • _this Object

Returns:

Array:

forEach

(
  • fn
  • _this
)
public

Execute given function for each item

Parameters:

  • fn Function
  • _this Object

get

(
  • key
)
BaseModel public

return submodel of the given key

Parameters:

  • key String | Number

Returns:

getDiff

(
  • plainObj
  • [options]
)
Object public

Get diff prop values

Parameters:

  • plainObj Any
  • [options] Object optional
    • [ignores] Array(String) optional

      prop names to skip checking diff

Returns:

Object:

getFacade

() Facade deprecated

Inherited from Base: /home/ubuntu/base-domain/src/lib/base.coffee:81

Deprecated: just use this.facade

Get facade

Returns:

getItem

(
  • key
)
BaseModel public

return submodel of the given key throw error when not found.

Parameters:

  • key String | Number

Returns:

getItemModelClass

() Function

get item model

Returns:

Function:

getModelProps

() ModelProps private

Returns:

getModule

() BaseModule

Get module which this class belongs to

Returns:

getParent

() Function

get parent class

Returns:

Function:

has

(
  • key
)
Boolean public

check if the model has submodel of the given key or not

Parameters:

  • key String | Number

Returns:

Boolean:

include

(
  • [options]
)
Promise(BaseModel)

include all relational models if not set

Parameters:

  • [options] Object optional
    • [async=true] Boolean optional

      get async values

    • [props] Array(String) optional

      include only given props

Returns:

Promise(BaseModel):

self

included

() Boolean

Check if all subentities are included.

Returns:

Boolean:

inherit

(
  • anotherModel
)
BaseModel

inherit value of anotherModel

Parameters:

Returns:

BaseModel:

this

initItems

() protected

key

() protected static

get unique key from item

keys

() Array public

get all keys

Returns:

Array:

keyValues

(
  • fn
)
public

iterate key - item

Parameters:

  • fn Function

    1st argument: key, 2nd argument: value

loaded

() Boolean public

Returns:

Boolean:

map

(
  • fn
  • _this
)
Array public

Execute given function for each item returns an array of the result

Parameters:

  • fn Function
  • _this Object

Returns:

Array:

plainClone

() Object public

clone the model as a plain object

Returns:

Object:

remove

(
  • item
)
public

remove submodel from items both acceptable, keys and submodels

Parameters:

setEnum

(
  • prop
  • value
)
private

set enum value

Parameters:

  • prop String
  • value String | Number

setIds

(
  • ids
)
chainable

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
)
Boolean public

Returns if some items match the condition in given function

Parameters:

  • fn Function
  • _this Object

Returns:

Boolean:

toArray

() public

export models to Array

toggle

(
  • item
)

turn on/off the value

Parameters:

toggle

(
  • item
)
BaseDict

turn on/off the value and create a new model

Parameters:

Returns:

BaseDict:

newDict

toObject

() public

to key-value object

toPlainArray

() Array

create plain array.

Returns:

Array:

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:

Object:

plainObject

unset

(
  • prop
)
BaseModel

unset property

Parameters:

  • prop String

    property name

Returns:

BaseModel:

this

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)