Skip to content

faiconqg/core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API

Table of Contents

apiClient

Sets or gets the api client instance

Parameters

  • adapter Adapter
  • options {} (optional, default {})

Returns Adapter

url

Returns the resource's url.

Returns string

isRequest

Questions whether the request exists and matches a certain label

Parameters

Returns boolean

rpc

Call an RPC action for all those non-REST endpoints that you may have in your API.

Parameters

Returns Request

length

Alias for models.length

Returns Number

map

Alias for models.map

Parameters

  • callback function (model: Model): any

Returns Array<any>

forEach

Alias for models.forEach

Parameters

  • callback function (model: Model): void

Returns void

url

Returns the URL where the model's resource would be located on the server.

Returns string

model

Specifies the model class for that collection

Parameters

  • attributes {} (optional, default {})

toJS

Returns a JSON representation of the collection

Returns Array<{}>

toArray

Alias of slice

Returns Array<Model>

slice

Returns a defensive shallow array representation of the collection

Returns Array<Model>

peek

Returns a shallow array representation of the collection

Returns Array<Model>

isEmpty

Wether the collection is empty

Returns boolean

_ids

Gets the ids of all the items in the collection

Returns Array<Id>

at

Get a resource at a given position

Parameters

Returns Model?

get

Get a resource with the given id or uuid

Parameters

  • id Id
  • $1 any (optional, default {})
    • $1.required (optional, default false)

Returns Model?

filter

Get resources matching criteria

Parameters

  • query ({} | function (Model): boolean)

Returns Array<Model>

find

Finds an element with the given matcher

Parameters

  • query ({} | function (Model): boolean)
  • $1 any (optional, default {})
    • $1.required (optional, default false)

Returns Model?

add

Adds a model or collection of models.

Parameters

  • data (Array<({} | Model)> | {} | Model)

Returns void

reset

Resets the collection of models.

Parameters

  • data Array<({} | Model)>

Returns void

remove

Removes the model with the given ids or uuids

Parameters

  • ids (Id | Model | Array<(Id | Model)>)

Returns void

set

Sets the resources into the collection.

You can disable adding, changing or removing.

Parameters

  • resources Array<{}>
  • $1 any (optional, default {})
    • $1.add (optional, default true)
    • $1.change (optional, default true)
    • $1.remove (optional, default true)

Returns void

build

Creates a new model instance with the given attributes

Parameters

  • attributes {} (optional, default {})

Returns Model

create

Creates the model and saves it on the backend

The default behaviour is optimistic but this can be tuned.

Parameters

  • attributesOrModel ({} | Model)
  • $1 any (optional, default {})
    • $1.optimistic (optional, default true)

Returns Request

fetch

Fetches the models from the backend.

It uses set internally so you can use the options to disable adding, changing or removing.

Parameters

  • options SetOptions (optional, default {})

Returns Request

toJS

Returns a JSON representation of the model

primaryKey

Determine what attribute do you use as a primary id

Returns string

urlRoot

Return the base url used in the url method

url

Return the url for this given REST resource

Returns string

isNew

Wether the resource is new or not

We determine this asking if it contains the primaryKey attribute (set by the server).

Returns boolean

get

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.

Parameters

Returns any

has

Returns whether the given field exists for the model.

Parameters

Returns boolean

id

Get an id from the model. It will use either the backend assigned one or the client.

Returns Id

changedAttributes

Get an array with the attributes names that have changed.

Returns Array<string>

changes

Gets the current changes.

Returns {}

hasChanges

If an attribute is specified, returns true if it has changes. If no attribute is specified, returns true if any attribute has changes.

Parameters

Returns boolean

reset

Replace all attributes with new data

Parameters

  • data {}

Returns void

set

Merge the given attributes with the current ones

Parameters

  • data {}

Returns void

fetch

Fetches the model from the backend.

Parameters

  • $0 any (optional, default {})
    • $0.data
    • $0.otherOptions ...any

Returns Request

applyPatchChanges

Merges old attributes with new ones. By default it doesn't merge arrays.

Parameters

  • oldAttributes {}
  • changes {}

Returns {}

save

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

Parameters

  • attributes {}
  • $1 any (optional, default {})
    • $1.optimistic (optional, default true)
    • $1.patch (optional, default true)
    • $1.keepChanges (optional, default true)
    • $1.otherOptions ...any

Returns Request

destroy

Destroys the resurce on the client and requests the backend to delete it there too

Parameters

  • $0 any (optional, default {})
    • $0.optimistic (optional, default true)
    • $0.otherOptions ...any

Returns Request