Prodigious-Aim-Solutions/Kronicle6

View on GitHub
docs/DataSources.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>

<html>
<head>
  <title>DataSources.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="Core.html">
                Core.js
              </a>
            
              
              <a class="source" href="EventTypes.html">
                EventTypes.js
              </a>
            
              
              <a class="source" href="Kronicle.html">
                Kronicle.js
              </a>
            
              
              <a class="source" href="Module.html">
                Module.js
              </a>
            
              
              <a class="source" href="ArrayDataSource.html">
                ArrayDataSource.js
              </a>
            
              
              <a class="source" href="Component.html">
                Component.js
              </a>
            
              
              <a class="source" href="Controller.html">
                Controller.js
              </a>
            
              
              <a class="source" href="DataSource.html">
                DataSource.js
              </a>
            
              
              <a class="source" href="DataSources.html">
                DataSources.js
              </a>
            
              
              <a class="source" href="DataSourcesEvents.html">
                DataSourcesEvents.js
              </a>
            
              
              <a class="source" href="View.html">
                View.js
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>DataSources.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              
            </div>
            
            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">require</span>(<span class="hljs-string">"babel/polyfill"</span>);
import {Module} from <span class="hljs-string">'../Module.js'</span>;
import {<span class="hljs-keyword">default</span> as PubSub} from <span class="hljs-string">'pubsub-js'</span>; 
import {events} from <span class="hljs-string">'./DataSourcesEvents.js'</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <h1 id="kronicle-datasources-class">Kronicle.Datasources class</h1>
<p>depends: <a href="Module.html">Kronicle.Module</a>, <a href="DataSourcesEvents">Kronicle.DataSourcesEvents</a>, pubsub-js
This class is used to load Kronicle Datasources.
The object is then passed along to the core to allow access to DataSources
The constructor takes one argument:</p>
<ul>
<li>sources - an array of Kronicle DataSource
The constructor throws events at various points.
The class has two properties:</li>
<li>name - a string constant ‘DataSources’</li>
<li>sources - an object that will contain the Kronicle DataSource
Events are fired at various points to indiciate the status and can be used as hooks for library modules.</li>
</ul>

            </div>
            
            <div class="content"><div class='highlight'><pre>export <span class="hljs-keyword">class</span> DataSources extends Module {
    constructor(sources = []){
        
        <span class="hljs-keyword">this</span>.name = <span class="hljs-string">"DataSources"</span>;
        <span class="hljs-keyword">this</span>.sources = { };
        
        PubSub.publish(events.BeforeDataSourcesLoaded);
        
        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> source of sources) {
            <span class="hljs-keyword">this</span>.sources[source.name] = source;
            
            PubSub.publish(events.DataSourceLoaded, source);
        }
        
        PubSub.publish(events.AfterDataSourcesLoaded);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>;
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <h2 id="beforedatasourcesloaded-method">beforeDataSourcesLoaded method</h2>
<p>This method is a hook into the BeforeDataSourcesLoaded event.
It takes one argument:</p>
<ul>
<li>cb - the callback to be called when the event is triggered.</li>
</ul>

            </div>
            
            <div class="content"><div class='highlight'><pre>    beforeDataSourcesLoaded(cb) {
        PubSub.subscribe(events.BeforeDataSourcesLoaded, cb);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <h2 id="datasourceloaded-method">dataSourceLoaded method</h2>
<p>This method is a hook into the DataSourceLoaded event.
Triggered after each DataSource is loaded.
It takes one argument:</p>
<ul>
<li>cb - the callback to be called when the event is triggered, it is passed one argument.<ul>
<li>source - the source that is loaded.</li>
</ul>
</li>
</ul>

            </div>
            
            <div class="content"><div class='highlight'><pre>    dataSourceLoaded(cb){
        PubSub.subscribe(events.DataSourceLoaded, cb);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-5">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-5">&#182;</a>
              </div>
              <h2 id="afterdatasourcesloaded-method">afterDataSourcesLoaded method</h2>
<p>This method is a hook into the AfterDataSourcesLoaded event.
Triggered after all DataSource are loaded.
It takes one argument:</p>
<ul>
<li>cb - the callback to be called when the event is triggered, it is passed one argument.<ul>
<li>sources - the sources that have been loaded.</li>
</ul>
</li>
</ul>

            </div>
            
            <div class="content"><div class='highlight'><pre>    afterDataSourcesLoaded(cb){
        PubSub.subscribe(events.AfterDataSourcesLoaded, cb);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-6">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-6">&#182;</a>
              </div>
              <h2 id="adddatasource">addDataSource</h2>
<p>This method is used to add a DataSource to the sources.
It takes one argument:</p>
<ul>
<li>source - the source to be added.</li>
</ul>

            </div>
            
            <div class="content"><div class='highlight'><pre>    addDataSource(source){
        <span class="hljs-keyword">this</span>.sources[source.name] = source;
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-7">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-7">&#182;</a>
              </div>
              <h2 id="removedatasource">removeDataSource</h2>
<p>This method is used to remove a DataSource from the sources.
It takes one argument:</p>
<ul>
<li>name - the name of the source to be removed.</li>
</ul>

            </div>
            
            <div class="content"><div class='highlight'><pre>    removeDataSource(name){
        <span class="hljs-keyword">this</span>.sources[name] = <span class="hljs-literal">null</span>;
    }
}</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>