@oarepo/invenio-api-vuex
Advanced tools
Comparing version 3.1.0-alpha.1 to 3.1.0-alpha.2
@@ -337,2 +337,3 @@ /*! | ||
this.facetMode = null; | ||
this.communicationErrorProcessor = null; | ||
} | ||
@@ -846,13 +847,16 @@ | ||
key: "patch", | ||
value: async function patch(data) { | ||
value: async function patch(_ref2) { | ||
var options = _ref2.options, | ||
patchData = _ref2.patchData; | ||
this.state = State.LOADING; | ||
if (!Array.isArray(data)) { | ||
data = [data]; | ||
if (!Array.isArray(patchData)) { | ||
patchData = [patchData]; | ||
} | ||
var resp; | ||
var usePost = options.usePost !== undefined ? options.usePost : this.config.usePost; | ||
if (this.config.usePost) { | ||
resp = await axios.post(this.recordUrl, data, { | ||
if (usePost) { | ||
resp = await axios.post(options.url || this.recordUrl, patchData, { | ||
headers: { | ||
@@ -865,3 +869,3 @@ 'Content-Type': 'application/json-patch+json', | ||
} else { | ||
resp = await axios.patch(this.recordUrl, data, { | ||
resp = await axios.patch(options.url || this.recordUrl, patchData, { | ||
headers: { | ||
@@ -1025,2 +1029,71 @@ 'Content-Type': 'application/json-patch+json' | ||
var PatchHolderMixin = { | ||
methods: { | ||
makePatchData: function makePatchData(basepath, props) { | ||
if (props.jsonpatch) { | ||
return props.jsonpatch; | ||
} | ||
return props.map(function (_ref) { | ||
var field = _ref.field, | ||
value = _ref.value, | ||
previousValue = _ref.previousValue; | ||
if (value === null || value === undefined) { | ||
return { | ||
op: 'remove', | ||
path: basepath + field | ||
}; | ||
} | ||
if (previousValue === null || previousValue === undefined) { | ||
return { | ||
op: 'add', | ||
path: basepath + field, | ||
value: value | ||
}; | ||
} | ||
return { | ||
op: 'replace', | ||
path: basepath + field, | ||
value: value | ||
}; | ||
}); | ||
}, | ||
patch: async function patch(props) { | ||
var options = this.patchOptions; | ||
var patchData = this.makePatchData(options.basepath, props); | ||
try { | ||
return this.$store.dispatch("".concat(options.store).concat(options.action), { | ||
opts: options, | ||
patchData: patchData | ||
}); | ||
} catch (e) { | ||
this.$oarepo.config.communicationErrorProcessor(e); | ||
return false; | ||
} | ||
} | ||
} | ||
}; | ||
var PatchMixin = { | ||
methods: { | ||
patch: async function patch(props) { | ||
var patcher = this; | ||
while (patcher && !patcher.patch) { | ||
patcher = patcher.$parent; | ||
} | ||
if (!patcher) { | ||
console.error('No patcher found in component hierarchy. Add PatchHolderMixin to the component\'s ancestor'); | ||
return false; | ||
} | ||
return patcher.patch(props); | ||
} | ||
} | ||
}; | ||
// | ||
@@ -1034,2 +1107,3 @@ var script$1 = { | ||
}, | ||
mixins: [PatchHolderMixin], | ||
computed: Object.assign({}, mapState({ | ||
@@ -1049,2 +1123,10 @@ loading: function loading(state) { | ||
} | ||
}, | ||
patchOptions: function patchOptions() { | ||
return { | ||
url: this.$oarepo.record.recordUrl, | ||
basepath: '/', | ||
store: 'oarepoRecord', | ||
action: 'patch' | ||
}; | ||
} | ||
@@ -1219,2 +1301,3 @@ }), | ||
listRecordPreprocessors: {}, | ||
communicationErrorProcessor: console.error, | ||
configModule: ConfigModule, | ||
@@ -1249,2 +1332,3 @@ indicesMixins: [], | ||
config.facetMode = options.facetMode; | ||
config.communicationErrorProcessor = options.communicationErrorProcessor; | ||
var indices = new applyMixins(IndicesModule, options.indicesMixins)(config, { | ||
@@ -1281,2 +1365,2 @@ store: store, | ||
export default index; | ||
export { CallbackList, CollectionModule, ConfigModule, FacetMixin, FacetMode, IndicesModule, __vue_component__ as InvenioCollection, __vue_component__$1 as InvenioRecord, RecordModule, State, collection, record }; | ||
export { CallbackList, CollectionModule, ConfigModule, FacetMixin, FacetMode, IndicesModule, __vue_component__ as InvenioCollection, __vue_component__$1 as InvenioRecord, PatchHolderMixin, PatchMixin, RecordModule, State, collection, record }; |
{ | ||
"name": "@oarepo/invenio-api-vuex", | ||
"version": "3.1.0-alpha.1", | ||
"version": "3.1.0-alpha.2", | ||
"main": "oarepo-invenio-api-vuex.esm.js", | ||
@@ -5,0 +5,0 @@ "private": false, |
59301
1180