baselinejs
Advanced tools
Comparing version 8.0.0 to 8.0.1
@@ -169,3 +169,3 @@ var _ = require( 'underscore' ); | ||
return _this._sync( url, 'delete', recordIdsToDeleteRemotely.length > 1 ? recordIdsToDeleteRemotely : undefined, options.ajax ).then( function( result ) { | ||
return _this._sync( url, 'DELETE', recordIdsToDeleteRemotely.length > 1 ? recordIdsToDeleteRemotely : undefined, options.ajax ).then( function( result ) { | ||
if( result.success ) deleteLocally(); | ||
@@ -213,3 +213,3 @@ | ||
_.each( newRecordDTOs, function( thisDto ) { | ||
_this._mergeDTO( thisDto, 'get' ); | ||
_this._mergeDTO( thisDto ); | ||
}, this ); | ||
@@ -251,4 +251,4 @@ }, | ||
return _this._sync( url, 'get', null, options.ajax ).then( function( result ) { | ||
if( result.success ) _this._mergeDTO( result.data, 'get' ); | ||
return _this._sync( url, 'GET', null, options.ajax ).then( function( result ) { | ||
if( result.success ) _this._mergeDTO( result.data ); | ||
@@ -268,9 +268,10 @@ return result; | ||
var method = this.isNew( recordId ) ? 'create' : 'update'; | ||
var isUpdate = ! this.isNew( recordId ); | ||
var url = _this._getRESTEndpoint( method, recordId ); | ||
var dto = this._recordToDTO( recordId, method ); | ||
return _this._sync( url, method, dto, options.ajax ).then( function( result ) { | ||
return _this._sync( url, isUpdate ? 'PUT' : 'POST', dto, options.ajax ).then( function( result ) { | ||
if( result.success ) { | ||
if( method === 'create' ) _this._newRecordIds = _.without( _this._newRecordIds, recordId ); | ||
if( options.merge ) _this._mergeDTO( result.data, method ); | ||
if( ! isUpdate ) _this._newRecordIds = _.without( _this._newRecordIds, recordId ); | ||
if( options.merge ) _this._mergeDTO( result.data ); | ||
} | ||
@@ -369,3 +370,3 @@ | ||
_mergeDTO : function( dto, method ) { | ||
_mergeDTO : function( dto ) { | ||
var recordId = dto[ this._idFieldName ]; | ||
@@ -389,18 +390,9 @@ | ||
_sync : function( url, method, payload, ajaxOptions ) { | ||
_sync : function( url, verb, payload, ajaxOptions ) { | ||
var options = _.defaults( {}, options ); | ||
var methodMap = { | ||
'create' : 'POST', | ||
'update' : 'PUT', | ||
'patch' : 'PATCH', | ||
'delete' : 'DELETE', | ||
'get' : 'GET', | ||
'search' : 'SEARCH' | ||
}; | ||
// Default JSON-request options. | ||
var params = { | ||
url : url, | ||
type : methodMap[ method ], | ||
type : verb, | ||
dataType : 'json', | ||
@@ -407,0 +399,0 @@ contentType : 'application/json', |
{ | ||
"name": "baselinejs", | ||
"version": "8.0.0", | ||
"version": "8.0.1", | ||
"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
109388
379