Home Reference Source
import DataModel from 'potassium-es/src/DataModel.js'
public class | source

DataModel

Extends:

EventHandlerDataObject → DataModel

DataModel holds a map of string,value pairs, sometimes fetched from or sent to a back-end server.

It fires events when values are changed so that {Component}s and other logic can react.

Constructor Summary

Public Constructor
public

constructor(data: Object, options: Object, fieldDataObjects: Object)

Member Summary

Public Members
public
public

data: {}

Method Summary

Public Methods
public
public

delete(): *

public

equals(obj: *): boolean

public

get(fieldName: *, defaultValue: undefined): *

Find a value held within this DataModel.

public

has(fieldName: *): *

public

increment(fieldName: *, amount: number)

public

reset(data: {})

public

set(fieldName: *, value: *): *

Set a key/value pair

public

setBatch(values: *): *

Set a group of values.

Inherited Summary

From class EventHandler
public get

listeners: EventListener[]: *

public

addListener(callback: function(eventName: string, eventSource: EventHandler), eventName: Object | Symbol, once: bool)

public
public

removeListener(callback: *, eventName: undefined)

public

trigger(eventName: *, params: ...*)

Send an event to listeners

From class DataObject
public static

fetchAll(dataObjects: ...*): *

Fetch each DataObject and then wait for them all to return Note: this resolves when the fetches complete, regardless of whether they succeed or fail.

public get

fetchOptions: {"credentials": string}

public get

isNew: bool

public get
public
public

options: *

public
public

delete(): *

public

equals(obj: *): *

public

fetch(): *

public

onFirstReset(func: *)

public

parse(data: *): *

public

reset(data: {})

Clear out old data and set it to data, should trigger a 'reset' event

public

save(): *

Public Constructors

public constructor(data: Object, options: Object, fieldDataObjects: Object) source

Override:

DataObject#constructor

Params:

NameTypeAttributeDescription
data Object
  • optional
  • default: {}
options Object
  • optional
  • default: {}
fieldDataObjects Object
  • optional
  • default: null

a map of fieldName (string) to DataObject (class), used to create sub-objects in this Model's data

Public Members

public collection: * source

public data: {} source

Public Methods

public cleanup() source

Override:

DataObject#cleanup

public delete(): * source

Override:

DataObject#delete

Return:

*

public equals(obj: *): boolean source

Override:

DataObject#equals

Params:

NameTypeAttributeDescription
obj *

Return:

boolean

public get(fieldName: *, defaultValue: undefined): * source

Find a value held within this DataModel.

Params:

NameTypeAttributeDescription
fieldName *
defaultValue undefined
  • optional
  • default: undefined

Return:

*

may be native types or, if mapped by options.fieldDataObjects, another DataObject

public has(fieldName: *): * source

Params:

NameTypeAttributeDescription
fieldName *

Return:

*

public increment(fieldName: *, amount: number) source

Params:

NameTypeAttributeDescription
fieldName *
amount number
  • optional
  • default: 1

public reset(data: {}) source

Clear out old data and set it to data, should trigger a 'reset' event

Override:

DataObject#reset

Params:

NameTypeAttributeDescription
data {}
  • optional
  • default: {}

public set(fieldName: *, value: *): * source

Set a key/value pair

Params:

NameTypeAttributeDescription
fieldName *
value *

Return:

*

public setBatch(values: *): * source

Set a group of values. The 'values' parameter should be an object that works in for(key in values) loops like a dictionary: {} If a key is in options.fieldDataObjects then the value will be used to contruct a DataObject and that will be the saved value.

Params:

NameTypeAttributeDescription
values *

Return:

*