baselinejs
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -56,5 +56,5 @@ var _ = require( 'underscore' ); | ||
if( ! _.isUndefined( this.comparator ) ) { | ||
this.sort(); | ||
} | ||
// if( ! _.isUndefined( this.comparator ) ) { | ||
// this.sort(); | ||
// } | ||
@@ -153,7 +153,14 @@ return newRecordId; | ||
var recordIdsToDeleteRemotely = []; | ||
if( options.sync ) { | ||
var url = this._getRESTEndpoint( 'delete', recordIdOrIds ); | ||
recordIdsToDeleteRemotely = _.filter( _.isArray( recordIdOrIds ) ? recordIdOrIds : [ recordIdOrIds ], function( thisRecordId ) { | ||
return ! _this.isNew( thisRecordId ); | ||
} ); | ||
} | ||
if( recordIdsToDeleteRemotely.length > 0 ) { | ||
var url = this._getRESTEndpoint( 'delete', recordIdsToDeleteRemotely.length > 1 ? recordIdsToDeleteRemotely : recordIdsToDeleteRemotely[0] ); | ||
return new Promise( function( resolve, reject ) { | ||
_this._sync( url, 'delete', _.isArray( recordIdOrIds ) ? recordIdOrIds : undefined, { | ||
_this._sync( url, 'delete', recordIdsToDeleteRemotely.length > 1 ? recordIdsToDeleteRemotely : undefined, { | ||
success : function( returnedJson, textStatus, xhr ) { | ||
@@ -173,3 +180,6 @@ if( options.success ) options.success.apply( this, arguments ); | ||
} ); | ||
} else deleteLocally(); | ||
} else { | ||
deleteLocally(); | ||
return Promise.resolve( { success : true } ); | ||
} | ||
}, | ||
@@ -182,23 +192,23 @@ | ||
sortIds : function( ids ) { | ||
var allIds = this.ids(); | ||
// sortIds : function( ids ) { | ||
// var allIds = this.ids(); | ||
var sortedIds = []; | ||
// var sortedIds = []; | ||
for( var i = 0, len = allIds.length; i < len; i++ ) { | ||
if( ids.indexOf( allIds[ i ] ) !== -1 ) | ||
sortedIds.push( allIds[ i ] ); | ||
} | ||
// for( var i = 0, len = allIds.length; i < len; i++ ) { | ||
// if( ids.indexOf( allIds[ i ] ) !== -1 ) | ||
// sortedIds.push( allIds[ i ] ); | ||
// } | ||
return sortedIds; | ||
// 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 ]; | ||
// } | ||
// // 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; | ||
}, | ||
// // return ids; | ||
// }, | ||
@@ -214,12 +224,16 @@ isPresent : function( recordId, fieldName ) { | ||
sort : function() { | ||
if( ! this.comparator ) | ||
throw new Error( 'Cannot sort without a comparator' ); | ||
if( _.isString( this.comparator ) || this.comparator.length === 1 ) | ||
this._recordIds = this.sortBy( this.comparator, this ); | ||
else | ||
this._recordIds.sort( _.bind( this.comparator, this ) ); | ||
isNew : function( recordId ) { | ||
return _.contains( this._newRecordIds, recordId ) | ||
}, | ||
// sort : function() { | ||
// if( ! this.comparator ) | ||
// throw new Error( 'Cannot sort without a comparator' ); | ||
// if( _.isString( this.comparator ) || this.comparator.length === 1 ) | ||
// this._recordIds = this.sortBy( this.comparator, this ); | ||
// else | ||
// this._recordIds.sort( _.bind( this.comparator, this ) ); | ||
// }, | ||
merge : function( newRecordDTOs ) { | ||
@@ -229,8 +243,8 @@ var _this = this; | ||
_.each( newRecordDTOs, function( thisDto ) { | ||
_this._mergeDTO( thisDto, 'get', { sort : false } ); | ||
_this._mergeDTO( thisDto, 'get' ); | ||
}, this ); | ||
if( ! _.isUndefined( this.comparator ) ) { | ||
this.sort(); | ||
} | ||
// if( ! _.isUndefined( this.comparator ) ) { | ||
// this.sort(); | ||
// } | ||
}, | ||
@@ -298,4 +312,3 @@ | ||
var isNew = _.contains( this._newRecordIds, recordId ); | ||
var method = isNew ? 'create' : 'update'; | ||
var method = this.isNew( recordId ) ? 'create' : 'update'; | ||
var url = _this._getRESTEndpoint( method, recordId ); | ||
@@ -310,3 +323,3 @@ var dto = this._recordToDTO( recordId, method ); | ||
if( options.merge ) _this._mergeDTO( returnedJson, method ); | ||
if( options.success ) options.success.apply( this, arguments ); | ||
if( options.success ) options.success.call( this, xhr, options ); | ||
@@ -316,4 +329,4 @@ resolve( { success : true, xhr : xhr } ); | ||
error : function( xhr ) { | ||
if( options.error ) options.error.apply( this, arguments ); | ||
else if( _this._defaultAjaxErrorHandler ) _this._defaultAjaxErrorHandler.apply( this, arguments ); | ||
if( options.error ) options.error.call( this, xhr, options ); | ||
else if( _this._defaultAjaxErrorHandler ) _this._defaultAjaxErrorHandler.call( this, xhr, options ); | ||
@@ -398,6 +411,6 @@ resolve( { success : false, xhr : xhr } ); | ||
_mergeDTO : function( dto, method, options ) { | ||
var options = _.defaults( {}, options, { | ||
sort : true | ||
} ); | ||
_mergeDTO : function( dto, method ) { | ||
// var options = _.defaults( {}, options, { | ||
// sort : true | ||
// } ); | ||
@@ -420,5 +433,5 @@ var recordId = dto[ this._idFieldName ]; | ||
if( options.sort && ! _.isUndefined( this.comparator ) ) { | ||
this.sort(); | ||
} | ||
// if( options.sort && ! _.isUndefined( this.comparator ) ) { | ||
// this.sort(); | ||
// } | ||
}, | ||
@@ -425,0 +438,0 @@ |
{ | ||
"name": "baselinejs", | ||
"version": "4.0.0", | ||
"version": "4.1.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
111928
463