forerunnerdb
Version:
A NoSQL document store database for browsers and Node.js.
157 lines (120 loc) • 5.87 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: Section.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: Section.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
var Shared,
Db,
DbInit,
Section;
Shared = require('./Shared');
/**
* The section class.
* @class
* @constructor
*/
Section = function () {
this.init.apply(this, arguments);
};
/**
* Create a constructor method that is called by the instance on instantiation.
* This allows the constructor to be overridden by other modules because
* they can override the init method with their own.
*/
Section.prototype.init = function () {
//var self = this;
};
// Tell ForerunnerDB about our new module
Shared.addModule('Section', Section);
// Mixin some commonly used methods
Shared.mixin(Section.prototype, 'Mixin.Common');
Shared.mixin(Section.prototype, 'Mixin.ChainReactor');
Shared.mixin(Section.prototype, 'Mixin.Constants');
Shared.mixin(Section.prototype, 'Mixin.Events');
// Grab the collection module for use later
Db = Shared.modules.Db;
DbInit = Db.prototype.init;
Db.prototype.init = function () {
var self = this;
self.on('create', function (instance, type, name) {
self._assignSection.call(self, instance, type, name);
});
DbInit.apply(self, arguments);
};
/**
* Denotes a section has been entered. All instances created
* after this call will be assigned to this "section".
*/
Db.prototype.sectionEnter = function () {
this._sectionsEnabled = true;
this._sectionItems = this._sectionItems || [];
this._sectionItems.push([]);
};
/**
* Denotes a section has been left. All instances that were
* created during the section lifespan will be automatically
* dropped.
*/
Db.prototype.sectionLeave = function () {
// Drop all items on the current section
var itemsArr = this._sectionItems[this._sectionId],
i;
if (itemsArr && itemsArr.length) {
for (i = 0; i < itemsArr.length; i++) {
if (itemsArr[i].drop) {
itemsArr[i].drop();
}
}
}
// Remove the items array from the section items array
this._sectionItems.pop();
// Check if there are any section items left and if not,
// disable sectioning5
if (!this._sectionItems.length) {
this._sectionsEnabled = false;
}
};
/**
* Assigns a newly created instance to the active section. This method
* is called by the database from the create event.
* @param {*} instance The item instance.
* @param {String} type The type of instance.
* @param {String} name The name of the instance.
* @private
*/
Db.prototype._assignSection = function (instance, type, name) {
var sectionId = this._sectionItems.length - 1;
instance._sectionId = sectionId;
this._sectionItems[sectionId].push(instance);
};
// Tell ForerunnerDB that our module has finished loading
Shared.finishModule('Section');
module.exports = Section;</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ActiveBucket.html">ActiveBucket</a></li><li><a href="Angular.html">Angular</a></li><li><a href="AutoBind.html">AutoBind</a></li><li><a href="Collection.html">Collection</a></li><li><a href="CollectionGroup.html">CollectionGroup</a></li><li><a href="Condition.html">Condition</a></li><li><a href="Core.html">Core</a></li><li><a href="Db.html">Db</a></li><li><a href="Document.html">Document</a></li><li><a href="Grid.html">Grid</a></li><li><a href="Highchart.html">Highchart</a></li><li><a href="Index2d.html">Index2d</a></li><li><a href="IndexBinaryTree.html">IndexBinaryTree</a></li><li><a href="IndexHashMap.html">IndexHashMap</a></li><li><a href="Infinilist.html">Infinilist</a></li><li><a href="KeyValueStore.html">KeyValueStore</a></li><li><a href="Metrics.html">Metrics</a></li><li><a href="MyModule.html">MyModule</a></li><li><a href="NodeApiClient.html">NodeApiClient</a></li><li><a href="NodeApiServer.html">NodeApiServer</a></li><li><a href="NodeRAS.html">NodeRAS</a></li><li><a href="Odm.html">Odm</a></li><li><a href="OldView.html">OldView</a></li><li><a href="Operation.html">Operation</a></li><li><a href="Overload.html">Overload</a></li><li><a href="Overview.html">Overview</a></li><li><a href="Overview_init.html">init</a></li><li><a href="Path.html">Path</a></li><li><a href="Persist.html">Persist</a></li><li><a href="Procedure.html">Procedure</a></li><li><a href="ReactorIO.html">ReactorIO</a></li><li><a href="Section.html">Section</a></li><li><a href="Serialiser.html">Serialiser</a></li><li><a href="Shared.overload.html">overload</a></li><li><a href="View.html">View</a></li></ul><h3>Mixins</h3><ul><li><a href="ChainReactor.html">ChainReactor</a></li><li><a href="Common.html">Common</a></li><li><a href="Constants.html">Constants</a></li><li><a href="Events.html">Events</a></li><li><a href="Matching.html">Matching</a></li><li><a href="Shared.html">Shared</a></li><li><a href="Sorting.html">Sorting</a></li><li><a href="Tags.html">Tags</a></li><li><a href="Triggers.html">Triggers</a></li><li><a href="Updating.html">Updating</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 01 2018 11:34:22 GMT+0000 (GMT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>