Classes
Members
ALLOW_INCOMPLETE
- Source:
This symbol can be used to create models with missing "required" fields. Note that this value is inherited, and so can be referenced from your own model's name rather than using Model.ALLOW_INCOMPLETE.
E.g.
class Something extends Model {
// ...
}
Something.create(undefined, Something.ALLOW_INCOMPLETE);
Methods
(static) create(allowIncompleteopt) → {Model}
- Source:
Create an instance of this model, with an optional data object that will be used to bootstrap the model's fields.
Note that this data must be schema-conformant for this model, or this function will throw.
If a backend store is used, this function will run async
,
returning a Promise
that can be await
ed,
or handled with .then()
When no backend is used, this function will run synchronously.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
allowIncomplete |
Symbol |
<optional> |
allows models to be created without specifying all required data, if set to Model.ALLOW_INCOMPLETE. |
Throws:
Returns:
- Type
- Model
(async, static) load(recordName) → {*}
- Source:
Load a stored record that uses this model from the back end.
Note that this will throw if:
- there is no stored record to load
- the stored record is not valid JSON
- the stored record is not schema-conformant
Parameters:
Name | Type | Description |
---|---|---|
recordName |
* |
Throws:
-
one of several errors
- Type
- *
Returns:
- Type
- *
(async) delete()
- Source:
Delete this model from the backend.
Throws:
-
one of several errors
- Type
- *
get(pathkey) → {*}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
pathkey |
* |
Returns:
- Type
- *
reset(postResetPayload)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
postResetPayload |
* | the data with which to bootstrap this model after resetting. |
(async) save()
- Source:
Save this model instance to the backend. Note that this
requires the model class to specify a __meta.recordName
field, which must indicate which key path to use as
"primary key" equivalent, or be a function that, given a
model, yields a string to be used as record key.
Throws:
-
one of several errors
- Type
- *
set(pathkey, value)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
pathkey |
* | |
value |
* |
toForm(options) → {*}
- Source:
- See:
Generate a node tree for working with this model's data in some non-HTML context. By default, this yields the (P)React equivalent of a <form>, with options.onSubmit being used for submission handling.
See tree.createFormTree for details on what the
available options
are.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | a configuration object |
Returns:
- Type
- *
toHTMLForm(options) → {String}
- Source:
- See:
options
are.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | a configuration object |
Returns:
- Type
- String
toHTMLTable(options) → {String}
- Source:
- See:
options
are.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | a configuration object |
Returns:
- Type
- String
toHTMLTableRows(options) → {String}
- Source:
- See:
options
are.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | a configuration object |
Returns:
- Type
- String
toString() → {*}
- Source:
Returns:
- Type
- *
toTable(options) → {*}
- Source:
- See:
-
- tree.createTableTree
Generate a node tree for working with this model's data in some non-HTML context. By default, this yields the (P)React equivalent of a <table> for templating into a component render.
See tree.createTableTree for details on what the
available options
are.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | a configuration object |
Returns:
- Type
- *
toTableRows(options) → {*}
- Source:
- See:
Generate an array of table rows for working with this model's data in some non-HTML context. By default, this yields an array of the (P)React equivalent of <tr>, for templating into a component render.
See tree.createTableTree for details on what the
available options
are.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | a configuration object |
Returns:
- Type
- *
updateFromSubmission(data)
- Source:
Update this model from a form submission, or any data payload
that encodes the model data using a flat
{
prop1: val1,
prop2: {
prop3: val2,
prop4: {
prop5: val3
}
}
}
as this flat object:
{
"prop1": "val1",
"prop2.prop3": "val2",
"prop2.prop4.prop5": "val3",
}
Parameters:
Name | Type | Description |
---|---|---|
data |
* |
Throws:
-
one of several errors
- Type
- *
valueOf() → {*}
- Source:
Returns:
- Type
- *