@onehat/data
Version:
JS data modeling package with adapters for many storage mediums.
1,327 lines (459 loc) • 19.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>@onehat/data Class: LocalFromRemoteRepository</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.yeti.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top ">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">@onehat/data</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="topNavigation">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="module-Entity.html">Entity</a></li><li><a href="module-OneHatData.html">OneHatData</a></li><li><a href="module-Property.html">Property</a></li><li><a href="module-Reader.html">Reader</a></li><li><a href="module-Repository.html">Repository</a></li><li><a href="module-Schema.html">Schema</a></li><li><a href="module-Writer.html">Writer</a></li><li><a href="module-@onehat_data.html">@onehat/data</a></li>
</ul>
</li>
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="module-Entity-Entity.html">Entity~Entity</a></li><li><a href="module-OneHatData.OneHatData.html">OneHatData.OneHatData</a></li><li><a href="module-Reader-JsonReader.html">Reader~JsonReader</a></li><li><a href="module-Reader-Reader.html">Reader~Reader</a></li><li><a href="module-Reader-XmlReader.html">Reader~XmlReader</a></li><li><a href="module-Repository-AjaxRepository.html">Repository~AjaxRepository</a></li><li><a href="module-Repository-CommandRepository.html">Repository~CommandRepository</a></li><li><a href="module-Repository-LocalFromRemoteRepository.html">Repository~LocalFromRemoteRepository</a></li><li><a href="module-Repository-MemoryRepository.html">Repository~MemoryRepository</a></li><li><a href="module-Repository-NullRepository.html">Repository~NullRepository</a></li><li><a href="module-Repository-OfflineRepository.html">Repository~OfflineRepository</a></li><li><a href="module-Repository-OneBuildRepository.html">Repository~OneBuildRepository</a></li><li><a href="module-Repository-RestRepository.html">Repository~RestRepository</a></li><li><a href="module-Writer-JsonWriter.html">Writer~JsonWriter</a></li><li><a href="module-Writer-Writer.html">Writer~Writer</a></li><li><a href="module-Writer-XmlWriter.html">Writer~XmlWriter</a></li>
</ul>
</li>
</ul>
<div class="col-sm-3 col-md-3">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
<div class="input-group-btn">
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="container" id="toc-content">
<div class="row">
<div class="col-md-8">
<div id="main">
<h1 class="page-title">Class: LocalFromRemoteRepository</h1>
<section>
<header>
<h2>
<span class="ancestors"><a href="module-Repository.html">Repository</a>~</span>
LocalFromRemoteRepository
</h2>
<div class="class-description">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</div>
</header>
<article>
<div class="container-overview">
<hr>
<dt>
<h4 class="name" id="LocalFromRemoteRepository"><span class="type-signature"></span>new LocalFromRemoteRepository()</h4>
</dt>
<dd>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
</div>
<h3 class="subsection-title">Extends</h3>
<ul>
<li>EventEmitter</li>
</ul>
<h3 class="subsection-title">Members</h3>
<dl>
<hr>
<dt class="name" id="registerCommands">
<h4 id="registerCommands"><span class="type-signature"></span>registerCommands<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Registers multiple commands for when syncing in MODE_COMMAND_QUEUE mode.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="registerCommandHandler">
<h4 id="registerCommandHandler"><span class="type-signature"></span>registerCommandHandler<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Adds a handler to a registered command.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="unregisterCommandHandler">
<h4 id="unregisterCommandHandler"><span class="type-signature"></span>unregisterCommandHandler<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Removes a handler from a registered command.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="isRegisteredCommand">
<h4 id="isRegisteredCommand"><span class="type-signature"></span>isRegisteredCommand<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Checks to see if command has been registered.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="getCommand">
<h4 id="getCommand"><span class="type-signature"></span>getCommand<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Gets a registered command.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="add">
<h4 id="add"><span class="type-signature"></span>add<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Adds a hook into the normal Repository.add() method,
so we can sync immediately after add for MODE_COMMAND_QUEUE mode.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="sync">
<h4 id="sync"><span class="type-signature"></span>sync<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Syncs local and remote repositories, based on operation mode.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="_doAutoSync">
<h4 id="_doAutoSync"><span class="type-signature"></span>_doAutoSync<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
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.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="getLastSync">
<h4 id="getLastSync"><span class="type-signature"></span>getLastSync<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Gets lastSync from private variable,
or from local storage medium, if possible.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="setAutoSync">
<h4 id="setAutoSync"><span class="type-signature"></span>setAutoSync<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Sets autoSync. If autoSync is enabled, it immediately starts autosync process.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt class="name" id="setIsOnline">
<h4 id="setIsOnline"><span class="type-signature"></span>setIsOnline<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
Sets isOnline. If isOnline and autoSync is enabled, it immediately starts autosync process.
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<dl>
<hr>
<dt>
<h4 class="name" id="initialize"><span class="type-signature"><async> </span>initialize()</h4>
</dt>
<dd>
<div class="description">
Initializes the Repository.
- Relays all events from sub-repositories
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
</dd>
<hr>
<dt>
<h4 class="name" id="destroy"><span class="type-signature"></span>destroy()</h4>
</dt>
<dd>
<div class="description">
Destroy this object.
- Removes child objects
- Removes event listeners
</div>
<dl class="details">
<dt class="tag-source method-doc-label method-doc-details-label">Source:</dt>
<dd class="tag-source">
Repository/LocalFromRemote/LocalFromRemote.js
</dd>
</dl>
<h5>Fires:</h5>
<ul>
<li>event:destroy</li>
</ul>
</dd>
</dl>
</article>
</section>
</div>
</div>
<div class="clearfix"></div>
<div class="col-md-3">
<div id="toc" class="col-md-3 hidden-xs hidden-sm hidden-md"></div>
</div>
</div>
</div>
<div class="modal fade" id="searchResults">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Search results</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<footer>
<div style="text-align:center;"><p><a href="https://www.npmjs.com/package/@onehat/data">@onehat/data NPM Module</a></p><p><a href="https://github.com/OneHatRepo/data">@onehat/data Github Repo</a></p></div
<span class="copyright">
<div style="text-align:center;"><p>©2020 OneHat Technologies, LLC</p></div>
</span>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.5</a>
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>
<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
<script>
$( function () {
$( "[id*='$']" ).each( function () {
var $this = $( this );
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
} );
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
var $this = $( this );
var example = $this.find( "code" );
exampleText = example.html();
var lang = /{@lang (.*?)}/.exec( exampleText );
if ( lang && lang[1] ) {
exampleText = exampleText.replace( lang[0], "" );
example.html( exampleText );
lang = lang[1];
} else {
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
lang = langClassMatch ? langClassMatch[1] : "javascript";
}
if ( lang ) {
$this
.addClass( "sunlight-highlight-" + lang )
.addClass( "linenums" )
.html( example.html() );
}
} );
Sunlight.highlightAll( {
lineNumbers : true,
showMenu : true,
enableDoclinks : true
} );
$.catchAnchorLinks( {
navbarOffset: 10
} );
$( "#toc" ).toc( {
anchorName : function ( i, heading, prefix ) {
return $( heading ).attr( "id" ) || ( prefix + i );
},
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
showAndHide : false,
smoothScrolling: true
} );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
$( '.dropdown-toggle' ).dropdown();
$( "table" ).each( function () {
var $this = $( this );
$this.addClass('table');
} );
} );
</script>
<!--Navigation and Symbol Display-->
<script>
$( function () {
$( '#main' ).localScroll( {
offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
} );
$( "dt.name" ).each( function () {
var $this = $( this ).find("h4");
var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
var dt = $(this);
var children = dt.next( "dd" );
dt.prepend( icon ).css( {cursor : "pointer"} );
dt.addClass( "member-collapsed" ).addClass( "member" );
children.hide();
dt.children().on( "click", function () {
children = dt.next( "dd" );
children.slideToggle( "fast", function () {
if ( children.is( ":visible" ) ) {
icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
dt.addClass( "member-open" ).animate( "member-collapsed" );
} else {
icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
dt.addClass( "member-collapsed" ).removeClass( "member-open" );
}
} );
} );
} );
} );
</script>
<!--Google Analytics-->
<script type="text/javascript">
$(document).ready(function() {
SearcherDisplay.init();
});
</script>
</body>
</html>