# Class: LocalFromRemoteRepository

## Repository~ LocalFromRemoteRepository

Class representing a (pseudo) Repository that has two sides: local, and remote. Local can be any subclass of Repository where isLocal === true. Remote can be any subclass of Repository where isRemote === true. The most common use is for local to be an OfflineRepository and remote to be an AjaxRepository. Note: This is not a true subclass of Repository. Instead, its properties and methods are Proxy'd from the "ActiveRepository", either the local or remote, depending upon operating mode. Multiple operating modes: - MODE_LOCAL_MIRROR - This mode is for keeping local copies of data that doesn't change very often. - *Add/Edit/Delete operations are disabled.* - First time in use, it loads its data from remote. - From then on, it primarily depends upon local. - Keeps track of the last time it pulled down from remote. - Can be set to reload its local data periodically, to make sure its data doesn't get too stale. - MODE_COMMAND_QUEUE - This mode provides the ability to send remote commands when isConnected, and to queue them up in an offline manner when !isConnected. - Items added locally are automatically transmitted to back-end when isConnected. - Data only goes from local --> remote; not the other way around. However, we do get a response from the server on the returned object. - Remote only uses C, not RUD - Sort by date, transmit by date NOTE: This mode is able to send commands of many different types, and have specialized event handlers for each separate type. In order to do that, this Repository becomes nothing more than a generic data transport pipeline between client and server. The Entities it returns are representative of what was returned from the server (raw payload, response info). In order to use these entities in any kind of meaningful way, we process them into Command objects. Each Command type can have its own set of processing handlers. As a result, when operating in this mode, OneHatData::_createRepository forces this Repository's remote repository type to be a CommandRepository. - MODE_REMOTE_WITH_OFFLINE - This mode provides an offline backup to the normal operation of remote. - Normally uses remote, but automatically switches to local if necessary (i.e. if offline). - Any changes made while offline will be saved to a queue, and then replayed to remote when the remote source becomes available again

#### new LocalFromRemoteRepository()

  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

### Extends

- EventEmitter

### Members

#### registerCommands

  Registers multiple commands for when syncing in MODE_COMMAND_QUEUE mode.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### registerCommandHandler

  Adds a handler to a registered command.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### unregisterCommandHandler

  Removes a handler from a registered command.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### isRegisteredCommand

  Checks to see if command has been registered.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### getCommand

  Gets a registered command.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### add

  Adds a hook into the normal Repository.add() method, so we can sync immediately after add for MODE_COMMAND_QUEUE mode.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### sync

  Syncs local and remote repositories, based on operation mode.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### _doAutoSync

  Sync on a regular schedule. Two operating modes: isRetry or !isRetry. If !isRetry, then we're just doing a regular autoSync. This will schedule the next sync based on nextDue. if isRetry, we are retrying to sync, due to being offline. This will schedule the next sync based on nextRetryDate.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### getLastSync

  Gets lastSync from private variable, or from local storage medium, if possible.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### setAutoSync

  Sets autoSync. If autoSync is enabled, it immediately starts autosync process.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### setIsOnline

  Sets isOnline. If isOnline and autoSync is enabled, it immediately starts autosync process.
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

### Methods

#### <async> initialize()

  Initializes the Repository. - Relays all events from sub-repositories
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

#### destroy()

  Destroy this object. - Removes child objects - Removes event listeners
  Source:
    Repository/LocalFromRemote/LocalFromRemote.js

  ##### Fires:

  - event:destroy

#### Search results