baselinejs
Advanced tools
Comparing version 4.1.1 to 4.2.0
@@ -10,55 +10,14 @@ var _ = require( 'underscore' ); | ||
this._tape = []; | ||
this._recording = true; | ||
// hook up dependencies | ||
_.each( this.services, function( thisService ) { | ||
_.each( thisService.dependencies, function( thisDependency ) { | ||
thisService.setDependency( thisDependency, _this.services[ thisDependency ] ); | ||
thisService.baseline = _this; | ||
_.each( _this.services, function( thisOtherService, thisOtherServiceIdent ) { | ||
thisService.setDependency( thisOtherServiceIdent, thisOtherService ); | ||
} ); | ||
} ); | ||
}, | ||
fetch : function( manifest, callback ) { | ||
var _this = this; | ||
var onGotResults = function( err, boatContents ) { | ||
if( err ) return callback( err ); | ||
try { | ||
_.each( boatContents, function( containerContents, containerName ) { | ||
_this.services[ containerName ].merge( containerContents ); | ||
} ); | ||
} catch( err ) { | ||
return callback( err ); | ||
} | ||
callback(); | ||
}; | ||
if( _isServer() ) { | ||
var boat = this.createBoat( manifest ); | ||
boat.stuff( onGotResults ); | ||
} | ||
else { | ||
// on the client side we have to do a remote sync request via our sync url. | ||
if( ! this._syncUrl ) return callback( new Error( 'Attempt to sync but no syncUrl has been supplied.' ) ); | ||
return $.ajax( { | ||
url : this._syncUrl, | ||
contentType : 'application/json', | ||
type : 'POST', | ||
data : JSON.stringify( manifest ), | ||
dataType : 'json', | ||
success : function( boatContents ) { | ||
onGotResults( null, boatContents ); | ||
}, | ||
error : function( errorObj, error ) { | ||
callback( new Error( 'Baseline sync failed: ' + errorObj.responseText ) ); | ||
} | ||
} ); | ||
} | ||
}, | ||
merge : function( data ) { | ||
merge : function( data, options ) { | ||
var options = _.extend( {}, { empty : false }, options ); | ||
var _this = this; | ||
@@ -68,4 +27,6 @@ | ||
_.each( data, function( thisServiceData, thisServiceIdent ) { | ||
if( _this.services[ thisServiceIdent ] && _.isFunction( _this.services[ thisServiceIdent ].merge ) ) | ||
if( _this.services[ thisServiceIdent ] && _.isFunction( _this.services[ thisServiceIdent ].merge ) ) { | ||
if( options.empty ) _this.services[ thisServiceIdent ].empty(); | ||
_this.services[ thisServiceIdent ].merge( thisServiceData ); | ||
} | ||
} ); | ||
@@ -84,4 +45,5 @@ } | ||
var thisDependencyService = _this.services[ thisDependency ]; | ||
if( _.isUndefined( thisDependencyService ) ) | ||
if( _.isUndefined( thisDependencyService ) ) { | ||
throw new Error( 'The service \'' + thisDependency + '\' is not available on this page.' ); | ||
} | ||
@@ -88,0 +50,0 @@ obj[ thisDependency ] = thisDependencyService; |
@@ -14,2 +14,5 @@ var Class = require( 'class-con-leche' ); | ||
empty : function() { | ||
}, | ||
merge : function( data ) { | ||
@@ -16,0 +19,0 @@ }, |
@@ -15,14 +15,8 @@ var _ = require( 'underscore' ); | ||
if( _.isUndefined( this.collectionName ) ) throw new Error( 'The collectionName attribute must be defined on collection service instances.' ); | ||
// if( _.isUndefined( this.fieldNames ) ) throw new Error( 'The fieldNames attribute must be defined on data service instances.' ); | ||
this.length = 0; | ||
// this._fieldNames = this.fieldNames; | ||
this._recordIds = []; | ||
this._recordsById = {}; | ||
this._newRecordIds = []; | ||
this._idFieldName = options.idFieldName; | ||
this._defaultAjaxErrorHandler = options.defaultAjaxErrorHandler; | ||
this.empty(); | ||
Events.mixin( this ); | ||
@@ -57,6 +51,2 @@ | ||
// if( ! _.isUndefined( this.comparator ) ) { | ||
// this.sort(); | ||
// } | ||
return newRecordId; | ||
@@ -191,24 +181,2 @@ }, | ||
// sortIds : function( ids ) { | ||
// var allIds = this.ids(); | ||
// var sortedIds = []; | ||
// for( var i = 0, len = allIds.length; i < len; i++ ) { | ||
// if( ids.indexOf( allIds[ i ] ) !== -1 ) | ||
// sortedIds.push( allIds[ i ] ); | ||
// } | ||
// return sortedIds; | ||
// // not sure why were were doing this below? we were returning just 'ids', but | ||
// // this seems equivilent to just returning sortedIds at this point | ||
// // // copy the sortedIds back to ids so its as if we did it in place | ||
// // for( i = 0, len = sortedIds.length; i < len; i++ ) { | ||
// // ids[ i ] = sortedIds[ i ]; | ||
// // } | ||
// // return ids; | ||
// }, | ||
isPresent : function( recordId, fieldName ) { | ||
@@ -227,13 +195,11 @@ // fieldName is optional.. if not supplied function will return true iff recordId is present | ||
// sort : function() { | ||
// if( ! this.comparator ) | ||
// throw new Error( 'Cannot sort without a comparator' ); | ||
empty : function() { | ||
this.length = 0; | ||
// if( _.isString( this.comparator ) || this.comparator.length === 1 ) | ||
// this._recordIds = this.sortBy( this.comparator, this ); | ||
// else | ||
// this._recordIds.sort( _.bind( this.comparator, this ) ); | ||
// }, | ||
this._recordIds = []; | ||
this._recordsById = {}; | ||
this._newRecordIds = []; | ||
}, | ||
merge : function( newRecordDTOs ) { | ||
merge : function( newRecordDTOs, options ) { | ||
var _this = this; | ||
@@ -244,6 +210,2 @@ | ||
}, this ); | ||
// if( ! _.isUndefined( this.comparator ) ) { | ||
// this.sort(); | ||
// } | ||
}, | ||
@@ -408,6 +370,2 @@ | ||
_mergeDTO : function( dto, method ) { | ||
// var options = _.defaults( {}, options, { | ||
// sort : true | ||
// } ); | ||
var recordId = dto[ this._idFieldName ]; | ||
@@ -428,6 +386,2 @@ | ||
_.extend( this._recordsById[ recordId ], dto ); | ||
// if( options.sort && ! _.isUndefined( this.comparator ) ) { | ||
// this.sort(); | ||
// } | ||
}, | ||
@@ -434,0 +388,0 @@ |
{ | ||
"name": "baselinejs", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "Share code and data between the client and the server in full stack JavaScript applications.", | ||
@@ -5,0 +5,0 @@ "main": "baseline.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109616
398