new Record(props, opts)
js-data's Record class.
import {Record} from 'js-data'
Name | Type | Argument | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
props |
Object |
<optional> |
The initial properties of the new Record instance. |
||||||||||
opts |
Object |
<optional> |
Configuration options. Properties
|
Extends
This class extends the Component class.Members
-
_listeners
-
Event listeners attached to this Component. Do not modify. Use Component#on and Component#off instead.
DetailsType Since Source Object 3.0.0 Component.js, line 7 - Inherited From:
Methods
-
afterLoadRelations(relations, opts)
-
TODO
-
beforeLoadRelations(relations, opts)
-
TODO
-
changes(opts)
-
Return changes to this record since it was instantiated or Record#commit was called.
Method parameters:Name Type Argument Description opts
<optional>
Configuration options.
Properties
Name Type Argument Description equalsFn
Function <optional>
Equality function. Default uses
===
.ignore
Array <optional>
Array of strings or RegExp of fields to ignore.
-
commit()
-
TODO
-
dbg(args)
-
Log the provided values at the "debug" level.
Method parameters:Name Type Argument Description args
* <optional>
<repeatable>
Values to log.
DetailsSince Source 3.0.0 Component.js, line 32 - Inherited From:
-
destroy(opts)
-
Call Mapper#destroy using this record's primary key.
Method parameters:Name Type Argument Description opts
Object <optional>
Configuration options passed to Mapper#destroy.
Return value:Type Description Promise The result of calling Mapper#destroy.
-
emit(event, args)
-
Trigger an event on this Component.
Method parameters:Name Type Argument Description event
String Name of event to emit.
args
* <optional>
<repeatable>
Arguments to pass to any listeners.
DetailsSince Source 3.0.0 Component.js, line 98 - Inherited From:
Examplescollection.on('foo', (msg) => { console.log(msg) // "bar" }) collection.emit('foo', 'bar')
store.on('foo', (msg, val1, val2) => { console.log(msg, val1, val2) // "bar" "beep" "boop" }) store.emit('foo', 'bar', 'beep', 'boop')
-
get(key)
-
Return the value at the given path for this instance.
Method parameters:Name Type Description key
String Path of value to retrieve.
Return value:Type Description * Value at path.
-
hasChanges(opts)
-
Return whether this record has changed since it was instantiated or Record#commit was called.
Method parameters:Name Type Argument Description opts
<optional>
Configuration options.
Properties
Name Type Argument Description equalsFn
Function <optional>
Equality function. Default uses
===
.ignore
Array <optional>
Array of strings or RegExp of fields to ignore.
-
hashCode()
-
TODO
-
loadRelations(relations, opts)
-
TODO
Method parameters:Name Type Argument Description relations
Array.<String> <optional>
TODO
opts
Object <optional>
TODO
-
log(level, args)
-
Log the provided values. By default sends values to
console[level]
.Method parameters:Name Type Argument Description level
String Log level
args
* <optional>
<repeatable>
Values to log.
DetailsSince Source 3.0.0 Component.js, line 39 - Inherited From:
-
off(event, listener)
-
Remove an event listener from this Component. If no listener is provided, then all listeners for the specified event will be removed. If no event is specified then all listeners for all events will be removed.
Method parameters:Name Type Argument Description event
String <optional>
Name of event to unsubsribe to.
listener
Function <optional>
Listener to remove.
DetailsSince Source 3.0.0 Component.js, line 79 - Inherited From:
Examplescollection.off('add', handler)
record.off('change')
store.off()
-
on(event, listener, ctx)
-
Register a new event listener on this Component.
Method parameters:Name Type Argument Description event
String Name of event to subsribe to.
listener
Function Listener function to handle the event.
ctx
* <optional>
Optional content in which to invoke the listener.
DetailsSince Source 3.0.0 Component.js, line 49 - Inherited From:
Examplesstore.on('afterCreate', (mapperName, props, opts, result) => { console.log(mapperName) // "post" console.log(props.id) // undefined console.log(result.id) // 1234 }) store.create('post', { title: 'Modeling your data' }).then((post) => { console.log(post.id) // 1234 })
collection.on('add', (records) => { console.log(records) // [...] })
post.on('change', (record, changes) => { console.log(changes) // { changed: { title: 'Modeling your data' } } }) post.title = 'Modeling your data'
-
previous(key)
-
TODO
Method parameters:Name Type Argument Description key
String <optional>
TODO
-
revert(opts)
-
TODO
Method parameters:Name Type Argument Description opts
Object <optional>
Configuration options.
-
save(opts, opts)
-
Delegates to Mapper#create or Mapper#update.
Method parameters:Name Type Argument Description opts
Object <optional>
Configuration options. See Mapper#create.
opts
<optional>
Configuration options.
Properties
Name Type Argument Description changesOnly
Boolean <optional>
Equality function. Default uses
===
.equalsFn
Function <optional>
Passed to Record#changes when
changesOnly
istrue
.ignore
Array <optional>
Passed to Record#changes when
changesOnly
istrue
.Return value:Type Description Promise The result of calling Mapper#create or Mapper#update.
-
set(key, value, opts)
-
Set the value for a given key, or the values for the given keys if "key" is an object.
Method parameters:Name Type Argument Description key
String | Object Key to set or hash of key-value pairs to set.
value
* <optional>
Value to set for the given key.
opts
Object <optional>
Optional configuration.
Properties
Name Type Argument Default Description silent
Boolean <optional>
false Whether to trigger change events.
-
toJSON(opts)
-
Return a plain object representation of this record. If the class from which this record was created has a mapper, then Mapper#toJSON will be called instead.
Method parameters:Name Type Argument Description opts
Object <optional>
Configuration options.
Properties
Name Type Argument Description with
Array.<String> <optional>
Array of relation names or relation fields to include in the representation. Only available as an option if the class from which this record was created has a mapper.
Return value:Type Description Object Plain object representation of this record.
-
unset(key, opts)
-
Unset the value for a given key.
Method parameters:Name Type Argument Description key
String Key to unset.
opts
Object <optional>
Optional configuration.
Properties
Name Type Argument Default Description silent
Boolean <optional>
false Whether to trigger change events.