0.2.1 • Published 1 year ago

@faicon/core v0.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
1 year ago

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

0.2.1

1 year ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.118

3 years ago

0.0.117

3 years ago

0.0.116

3 years ago

0.0.115

3 years ago

0.0.114

3 years ago

0.0.113

3 years ago

0.0.112

3 years ago

0.0.111

3 years ago

0.0.110

3 years ago

0.0.109

3 years ago

0.0.108

3 years ago

0.0.107

3 years ago

0.0.106

3 years ago

0.0.105

3 years ago

0.0.104

3 years ago

0.0.103

3 years ago

0.0.102

4 years ago

0.0.101

4 years ago

0.0.100

4 years ago

0.0.99

4 years ago

0.0.98

4 years ago

0.0.97

4 years ago

0.0.96

4 years ago

0.0.95

4 years ago

0.0.94

4 years ago

0.0.93

4 years ago

0.0.92

4 years ago

0.0.91

4 years ago

0.0.90

4 years ago

0.0.89

4 years ago

0.0.87

4 years ago

0.0.88

4 years ago

0.0.86

4 years ago

0.0.85

4 years ago

0.0.84

4 years ago

0.0.83

4 years ago

0.0.82

4 years ago

0.0.81

4 years ago

0.0.80

4 years ago

0.0.79

4 years ago

0.0.78

4 years ago

0.0.77

4 years ago

0.0.76

4 years ago

0.0.75

4 years ago

0.0.74

4 years ago

0.0.73

5 years ago

0.0.72

5 years ago

0.0.71

5 years ago

0.0.70

5 years ago

0.0.69

5 years ago

0.0.68

5 years ago

0.0.67

5 years ago

0.0.66

5 years ago

0.0.65

5 years ago

0.0.64

5 years ago

0.0.63

5 years ago

0.0.62

5 years ago

0.0.61

5 years ago

0.0.60

5 years ago

0.0.59

5 years ago

0.0.58

5 years ago

0.0.57

5 years ago

0.0.56

5 years ago

0.0.55

5 years ago

0.0.54

5 years ago

0.0.53

5 years ago

0.0.52

5 years ago

0.0.51

5 years ago

0.0.50

5 years ago

0.0.49

5 years ago

0.0.48

5 years ago

0.0.47

5 years ago

0.0.46

5 years ago

0.0.45

5 years ago

0.0.44

5 years ago

0.0.43

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.38

5 years ago

0.0.37

5 years ago

0.0.35

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago