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