henrybuilt-js-library
Advanced tools
Comparing version 1.6.9 to 1.6.10
{ | ||
"name": "henrybuilt-js-library", | ||
"version": "1.6.9", | ||
"version": "1.6.10", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -81,3 +81,3 @@ var libString = require('@src/string'); | ||
this.cacheResourceProps(); | ||
this.cacheResourceProps({forUpdate: true}); | ||
} | ||
@@ -115,3 +115,3 @@ | ||
if (!this.isCreated && !this.isCreating) { | ||
this.cacheResourceProps(); | ||
this.cacheResourceProps({forUpdate: true}); | ||
@@ -122,3 +122,4 @@ params = _.merge({props: {...this.props.resourceProps}}, params); | ||
var {id} = await makeApiBatchRequest({resourceKey: this.resourceKey, actionKey: 'create', params});//libApi.create(this.resourceKey, params); | ||
var resource = await makeApiBatchRequest({resourceKey: this.resourceKey, actionKey: 'create', params}); | ||
var {id} = resource; | ||
@@ -136,15 +137,14 @@ this.isCreating = false; | ||
var propsChanged = !_.isEqual(this.props.resourceProps, this.cachedResourceProps); | ||
var changedProps = _.pickBy(this.props.resourceProps, (newValue, key) => { | ||
var cachedValue = this.cachedResourcePropsForUpdate[key]; | ||
return !_.isEqual(cachedValue, newValue); | ||
}); | ||
//TODO make sure update goes through eventually if isCreating | ||
if (this.exists && propsChanged) { | ||
this.cacheResourceProps(); | ||
if (this.exists && _.size(changedProps) > 0) { | ||
this.cacheResourceProps({forUpdate: true}); | ||
// await lib.api.update(this.resourceKey, { | ||
// props: _.omit(this.props.resourceProps, ['id']), | ||
// where: {id: this.id} | ||
// }); | ||
await makeApiBatchRequest({resourceKey: this.resourceKey, actionKey: 'update', params: { | ||
props: _.omit(this.props.resourceProps, ['id']), | ||
props: _.omit(changedProps, ['id']), | ||
where: {id: this.id} | ||
@@ -162,3 +162,2 @@ }}); | ||
//TODO make sure update goes through eventually if isCreating | ||
// await lib.api.destroy(this.resourceKey, {where: {id: this.id}}); | ||
await makeApiBatchRequest({resourceKey: this.resourceKey, actionKey: 'destroy', params: {where: {id: this.id}}}); | ||
@@ -206,4 +205,8 @@ | ||
cacheResourceProps() { | ||
cacheResourceProps({forUpdate=false} = {}) { | ||
this.cachedResourceProps = _.cloneDeep(this.resourceProps); | ||
if (forUpdate) { | ||
this.cachedResourcePropsForUpdate = _.cloneDeep(this.resourceProps); | ||
} | ||
} | ||
@@ -210,0 +213,0 @@ |
Sorry, the diff of this file is too big to display
644625
5091