- apiClient
- url
- isRequest
- rpc
- length
- map
- forEach
- url
- model
- toJS
- toArray
- slice
- peek
- isEmpty
- _ids
- at
- get
- filter
- find
- add
- reset
- remove
- set
- build
- create
- fetch
- toJS
- primaryKey
- urlRoot
- url
- isNew
- get
- has
- id
- changedAttributes
- changes
- hasChanges
- reset
- set
- fetch
- applyPatchChanges
- save
- destroy
Sets or gets the api client instance
adapter
Adapteroptions
{} (optional, default{}
)
Returns Adapter
Returns the resource's url.
Returns string
Questions whether the request exists and matches a certain label
label
string
Returns boolean
Call an RPC action for all those non-REST endpoints that you may have in your API.
endpoint
stringoptions
{}
Returns Request
Alias for models.length
Returns Number
Alias for models.map
callback
function (model: Model): any
Returns Array<any>
Alias for models.forEach
callback
function (model: Model): void
Returns void
Returns the URL where the model's resource would be located on the server.
Returns string
Specifies the model class for that collection
attributes
{} (optional, default{}
)
Returns a JSON representation of the collection
Returns Array<{}>
Alias of slice
Returns Array<Model>
Returns a defensive shallow array representation of the collection
Returns Array<Model>
Returns a shallow array representation of the collection
Returns Array<Model>
Wether the collection is empty
Returns boolean
Gets the ids of all the items in the collection
Returns Array<Id>
Get a resource at a given position
index
number
Returns Model?
Get a resource with the given id or uuid
id
Id$1
any (optional, default{}
)$1.required
(optional, defaultfalse
)
Returns Model?
Get resources matching criteria
query
({} | function (Model): boolean)
Returns Array<Model>
Finds an element with the given matcher
query
({} | function (Model): boolean)$1
any (optional, default{}
)$1.required
(optional, defaultfalse
)
Returns Model?
Adds a model or collection of models.
data
(Array<({} | Model)> | {} | Model)
Returns void
Resets the collection of models.
data
Array<({} | Model)>
Returns void
Removes the model with the given ids or uuids
ids
(Id | Model | Array<(Id | Model)>)
Returns void
Sets the resources into the collection.
You can disable adding, changing or removing.
resources
Array<{}>$1
any (optional, default{}
)$1.add
(optional, defaulttrue
)$1.change
(optional, defaulttrue
)$1.remove
(optional, defaulttrue
)
Returns void
Creates a new model instance with the given attributes
attributes
{} (optional, default{}
)
Returns Model
Creates the model and saves it on the backend
The default behaviour is optimistic but this can be tuned.
attributesOrModel
({} | Model)$1
any (optional, default{}
)$1.optimistic
(optional, defaulttrue
)
Returns Request
Fetches the models from the backend.
It uses set
internally so you can
use the options to disable adding, changing
or removing.
options
SetOptions (optional, default{}
)
Returns Request
Returns a JSON representation of the model
Determine what attribute do you use as a primary id
Returns string
Return the base url used in
the url
method
Return the url for this given REST resource
Returns string
Wether the resource is new or not
We determine this asking if it contains
the primaryKey
attribute (set by the server).
Returns boolean
Get the attribute from the model.
Since we want to be sure changes on the schema don't fail silently we throw an error if the field does not exist.
If you want to deal with flexible schemas
use has
to check wether the field
exists.
attribute
string
Returns any
Returns whether the given field exists for the model.
attribute
string
Returns boolean
Get an id from the model. It will use either the backend assigned one or the client.
Returns Id
Get an array with the attributes names that have changed.
Gets the current changes.
Returns {}
If an attribute is specified, returns true if it has changes. If no attribute is specified, returns true if any attribute has changes.
attribute
string
Returns boolean
Replace all attributes with new data
data
{}
Returns void
Merge the given attributes with the current ones
data
{}
Returns void
Fetches the model from the backend.
$0
any (optional, default{}
)$0.data
$0.otherOptions
...any
Returns Request
Merges old attributes with new ones. By default it doesn't merge arrays.
oldAttributes
{}changes
{}
Returns {}
Saves the resource on the backend.
If the item has a primaryKey
it updates it,
otherwise it creates the new resource.
It supports optimistic and patch updates.
TODO: Add progress
attributes
{}$1
any (optional, default{}
)$1.optimistic
(optional, defaulttrue
)$1.patch
(optional, defaulttrue
)$1.keepChanges
(optional, defaulttrue
)$1.otherOptions
...any
Returns Request
Destroys the resurce on the client and requests the backend to delete it there too
$0
any (optional, default{}
)$0.optimistic
(optional, defaulttrue
)$0.otherOptions
...any
Returns Request