Show:

Base class for application store. service:store should point to instance of that class.

Methods

_dbInit

() private

Update all databases in accordance with actual schemas.

_getModelName

(
  • methodName
  • methodArguments
)
String private

Detect model name by method name and arguments.

Parameters:

Returns:

adapterFor

(
  • modelName
  • [useOnlineStore]
)
DS.Adapter or subclass

Returns an instance of the adapter for a given type.

Parameters:

  • modelName String
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

DS.Adapter or subclass:

Adapter

batchUpdate

(
  • models
  • [useOnlineStore]
)
Promise

A method to send batch update, create or delete models in single transaction.

All models saving using this method must have identifiers.

The array which fulfilled the promise may contain the following values:

  • same model object - for created, updated or unaltered records.
  • null - for deleted records.

Parameters:

  • models DS.Model[] | DS.Model

    Is array of models or single model for batch update.

  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status.

Returns:

Promise:

A promise that fulfilled with an array of models in the new state.

createExistingRecord

(
  • modelName
  • primaryKey
  • [useOnlineStore]
)

Pushes into store the model that exists in backend without a request to it.

Parameters:

  • modelName String

    Name of the model to push into store.

  • primaryKey String

    Primery key of the model to push into store.

  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

createRecord

(
  • modelName
  • inputProperties
  • [useOnlineStore]
)
Promise

Create a new record in the current store. The properties passed to this method are set on the newly created record.

Parameters:

  • modelName String
  • inputProperties Object

    A hash of properties to set on the newly created record.

  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

Promise:

promise

deleteRecord

(
  • record
  • [useOnlineStore]
)

For symmetry, a record can be deleted via the store.

Parameters:

  • record DS.Model
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

deleteRecord

(
  • record
  • [useOnlineStore]
)

Delete all record from the current store.

Parameters:

  • record DS.Model
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

findAll

(
  • modelName
  • options
)
Promise

This method returns a fresh collection from the server, regardless of if there is already records in the store or not.

Parameters:

  • modelName String
  • options Object
    • [useOnlineStore] Boolean optional

      Allow to explicitly specify online or offline store using independently of global online status

Returns:

Promise:

promise

findRecord

(
  • modelName
  • id
  • options
)
Promise

This method returns a record for a given type and id combination. NOTE: this will trigger syncUp twice, this is OK. And since this is a public method, we probably want to preserve this.

Parameters:

  • modelName String
  • id String | Integer
  • options Object
    • [useOnlineStore] Boolean optional

      Allow to explicitly specify online or offline store using independently of global online status

Returns:

Promise:

promise

getCurrentUserName

() String

Returns current user name. Method must be overridden if application uses some authentication.

Returns:

String:

Current user name. Returns 'userName' as default value if method is not overridden.

getReference

(
  • type
  • id
  • [useOnlineStore]
)
RecordReference

Get the reference for the specified record.

Parameters:

  • type String
  • id String | Integer
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

RecordReference:

promise

hasRecordForId

(
  • modelName
  • inputId
  • [useOnlineStore]
)
Boolean

Returns true if a record for a given type and ID is already loaded.

Parameters:

  • modelName String | DS.Model
  • inputId String | Integer
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

normalize

(
  • modelName
  • payload
  • [useOnlineStore]
)
Object

Converts a json payload into the normalized form that BaseStore/push:method expects.

Parameters:

  • modelName String

    The name of the model type for this payload

  • payload Object
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

Object:

The normalized payload

peekAll

(
  • modelName
  • [useOnlineStore]
)
DS.RecordArray

This method returns a filtered array that contains all of the known records for a given type in the store.

Parameters:

  • modelName String
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

peekRecord

(
  • modelName
  • id
  • [useOnlineStore]
)
DS.Model | Null

Get a record by a given type and ID without triggering a fetch.

Parameters:

  • modelName String
  • id String | Integer
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

DS.Model | Null:

Record

push

(
  • data
  • [useOnlineStore]
)
DS.Model | Array

Push some data for a given type into the store.

Parameters:

  • data Object
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

DS.Model | Array:

The record(s) that was created or updated.

pushPayload

(
  • modelName
  • inputPayload
  • [useOnlineStore]
)

Push some raw data into the store.

Parameters:

  • modelName String
  • inputPayload Object
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

query

(
  • modelName
  • query
)
Promise

Query for records that meet certain criteria. Resolves with DS.RecordArray. For more information see query method of DS.Store.

Parameters:

  • modelName String
  • query Object
    • [useOnlineStore] Boolean optional

      Allow to explicitly specify online or offline store using independently of global online status

Returns:

Promise:

promise

query

(
  • modelName
  • query
)
Promise

Query for record that meet certain criteria. Resolves with single record.

Parameters:

  • modelName String
  • query Object
    • [useOnlineStore] Boolean optional

      Allow to explicitly specify online or offline store using independently of global online status

Returns:

Promise:

promise

recordIsLoaded

(
  • modelName
  • id
  • [useOnlineStore]
)
Boolean

This method returns if a certain record is already loaded in the store.

Parameters:

  • modelName String
  • id String | Integer
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

serializerFor

(
  • modelName
  • [useOnlineStore]
)
DS.Serializer or subclass

Returns an instance of the serializer for a given type.

Parameters:

  • modelName String
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Returns:

DS.Serializer or subclass:

Serializer

unloadAll

(
  • modelName
  • [useOnlineStore]
)

This method unloads all records in the store.

Parameters:

  • modelName String
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

unloadRecord

(
  • record
  • [useOnlineStore]
)

For symmetry, a record can be unloaded via the store. Only non-dirty records can be unloaded.

Parameters:

  • record DS.Model
  • [useOnlineStore] Boolean optional

    Allow to explicitly specify online or offline store using independently of global online status

Properties

_offlineSchema

Object private

Store offline schemas for all databases.

Default: 'Schema of 1 version for internal models of addon'

dexieService

Offline.DexieService

Instance of dexie service.

offlineModels

Object

Add model names that be loaded from offline store.

Default: {}

Example:

// app/services/store.js
                    ...
                      offlineModels: {
                        myModel: true,
                      },
                    ...
                    

offlineSchema

Object

Set schema for your database.

Example:

// app/services/store.js
                    ...
                      init() {
                        this.set('offlineSchema', {
                          <name of database>: {
                            <number of version>: {
                              <name of model>: <table definition>,
                            },
                          },
                          dbName: {
                            1: {
                              modelName: 'id,attribute1,attribute2,belongsToRelationship1,belongsToRelationship2,*hasManyRelationship1,*hasManyRelationship2',
                              changedModelName: 'id,attribute1,attribute2',
                              thisModelWillBeRemovedInNextVersion: 'id,attribute1',
                            },
                            2: {
                              newModelName: 'id,attribute1',
                              changedModelName: 'id,attribute1,attribute3,attribute4',
                              thisModelWillBeRemovedInNextVersion: null,
                            },
                          },
                        });
                        return this._super(...arguments);
                      },
                    ...
                    

offlineStore

DS.Store

Store that use for making requests in offline mode. By default it is set to global instane of LocalStore class.

onlineStore

DS.Store

Store that use for making requests in online mode. It can be specified in application that use offline mode support. If it is not specified then instance of DS.Store is set as value of this property during initialization of BaseStore class.

syncer

Syncer

Global instance of Syncer class that contains methods to sync model.