Config
Table of Contents

Class

O.AggregateSource

An O.AggregateSource instance can be used to collect several O.Source instances together to present to an instance of O.Store. Each method call on an aggregate source is passed around the sources it is managing until it finds one that can handle it.

"use strict";

( function ( NS ) {

var AggregateSource = NS.Class({

 Extends: NS.Source,

 init: function ( mixin ) {
   this.sources = [];
   AggregateSource.parent.init.call( this, mixin );
 },

Property

O.AggregateSource#sources

  • O.Source[]

List of sources to pass requests to. Will be tried in order.

Method

O.AggregateSource#addSource( source )

Parameters

sourceO.Source The source to add to the end of the list of aggregated sources.

Returns

O.AggregateSource Returns self.

addSource: function ( source ) {
   source.set( 'store', this.get( 'store' ) );
   this.get( 'sources' ).push( source );
   return this;
 },

Method

O.AggregateSource#removeSource( source )

Parameters

sourceO.Source The source to remove from the list of aggregated sources.

Returns

O.AggregateSource Returns self.

removeSource: function ( source ) {
   this.get( 'sources' ).erase( source );
   return this;
 },

 storeWasSet: function () {
   var store = this.get( 'store' );
   this.sources.forEach( function ( source ) {
     source.set( 'store', store );
   });
 }.observes( 'store' ),

 fetchRecord: function ( Type, id, callback ) {
   return this.get( 'sources' ).some( function ( source ) {
     return source.fetchRecord( Type, id, callback );
   });
 },

 fetchAllRecords: function ( Type, state, callback ) {
   return this.get( 'sources' ).some( function ( source ) {
     return source.fetchAllRecords( Type, state, callback );
   });
 },

 refreshRecord: function ( Type, id, callback ) {
   return this.get( 'sources' ).some( function ( source ) {
     return source.refreshRecord( Type, id, callback );
   });
 },

 commitChanges: function ( changes, callback ) {
   var waiting = 0,
     callbackAfterAll;
   if ( callback ) {
     callbackAfterAll = function () {
       if ( !( waiting-= 1 ) ) {
         callback();
       }
     };
   }
   this.get( 'sources' ).forEach( function ( source ) {
     if ( source.commitChanges( changes, callbackAfterAll ) ) {
       waiting += 1;
     }
   });
   return this;
 },

 fetchQuery: function ( query, callback ) {
   return this.get( 'sources' ).some( function ( source ) {
     return source.fetchQuery( query, callback );
   });
 }
});

NS.AggregateSource = AggregateSource;

}( O ) );
Animation
Application
Core
DataStore
DOM
DragDrop
Foundation
IO
Localisation
Selection
Parser
TimeZones
Storage
Touch
CollectionViews
UA
ContainerViews
ControlViews
PanelViews
View