From 34d9f7b3ae341fa00b58645a233a1761f2be2a3d Mon Sep 17 00:00:00 2001 From: Mesqueeb Date: Thu, 23 Apr 2020 00:17:22 +0900 Subject: [PATCH] Fix: Patch to nested object is changing object content order #300 --- dist/index.cjs.js | 20 +++++++++----------- dist/index.esm.js | 20 +++++++++----------- package.json | 14 ++++---------- test/helpers/index.cjs.js | 20 +++++++++----------- 4 files changed, 31 insertions(+), 43 deletions(-) diff --git a/dist/index.cjs.js b/dist/index.cjs.js index fdac34ec..f6fa1fd8 100644 --- a/dist/index.cjs.js +++ b/dist/index.cjs.js @@ -331,6 +331,15 @@ function isIncrementHelper(payload) { payload.isIncrementHelper === true); } +function convertHelpers(originVal, newVal) { + if (isWhat.isArray(originVal) && isArrayHelper(newVal)) { + newVal = newVal.executeOn(originVal); + } + if (isWhat.isNumber(originVal) && isIncrementHelper(newVal)) { + newVal = newVal.executeOn(originVal); + } + return newVal; // always return newVal as fallback!! +} /** * Creates the params needed to $set a target based on a nested.path * @@ -434,17 +443,6 @@ function pluginMutations (userState) { } if (!ref) return error('patch-no-ref'); - function convertHelpers(originVal, newVal) { - if (isWhat.isArray(originVal) && isArrayHelper(newVal)) { - newVal = newVal.executeOn(originVal); - } - if (isWhat.isNumber(originVal) && isIncrementHelper(newVal)) { - newVal = newVal.executeOn(originVal); - } - return newVal; // always return newVal as fallback!! - } - // const refPropsPicked = filter(ref, Object.keys(patches)) - // const patchesSanitised = merge({ extensions: [convertHelpers] }, refPropsPicked, patches) var patchesFlat = flatten.flattenObject(patches); for (var _i = 0, _b = Object.entries(patchesFlat); _i < _b.length; _i++) { var _c = _b[_i], path = _c[0], value = _c[1]; diff --git a/dist/index.esm.js b/dist/index.esm.js index 9d30050a..8151880e 100644 --- a/dist/index.esm.js +++ b/dist/index.esm.js @@ -324,6 +324,15 @@ function isIncrementHelper(payload) { payload.isIncrementHelper === true); } +function convertHelpers(originVal, newVal) { + if (isArray(originVal) && isArrayHelper(newVal)) { + newVal = newVal.executeOn(originVal); + } + if (isNumber(originVal) && isIncrementHelper(newVal)) { + newVal = newVal.executeOn(originVal); + } + return newVal; // always return newVal as fallback!! +} /** * Creates the params needed to $set a target based on a nested.path * @@ -427,17 +436,6 @@ function pluginMutations (userState) { } if (!ref) return error('patch-no-ref'); - function convertHelpers(originVal, newVal) { - if (isArray(originVal) && isArrayHelper(newVal)) { - newVal = newVal.executeOn(originVal); - } - if (isNumber(originVal) && isIncrementHelper(newVal)) { - newVal = newVal.executeOn(originVal); - } - return newVal; // always return newVal as fallback!! - } - // const refPropsPicked = filter(ref, Object.keys(patches)) - // const patchesSanitised = merge({ extensions: [convertHelpers] }, refPropsPicked, patches) var patchesFlat = flattenObject(patches); for (var _i = 0, _b = Object.entries(patchesFlat); _i < _b.length; _i++) { var _c = _b[_i], path = _c[0], value = _c[1]; diff --git a/package.json b/package.json index d7f53563..1427de16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vuex-easy-firestore", - "version": "1.35.8", + "version": "1.35.9", "description": "Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!", "main": "dist/index.cjs.js", "module": "dist/index.esm.js", @@ -72,14 +72,8 @@ }, "ava": { "compileEnhancements": false, - "extensions": [ - "ts" - ], - "require": [ - "ts-node/register" - ], - "helpers": [ - "**/helpers/**/*" - ] + "extensions": ["ts"], + "require": ["ts-node/register"], + "helpers": ["**/helpers/**/*"] } } diff --git a/test/helpers/index.cjs.js b/test/helpers/index.cjs.js index adbf5957..7c07ce4d 100644 --- a/test/helpers/index.cjs.js +++ b/test/helpers/index.cjs.js @@ -850,6 +850,15 @@ function isIncrementHelper(payload) { payload.isIncrementHelper === true); } +function convertHelpers(originVal, newVal) { + if (isWhat.isArray(originVal) && isArrayHelper(newVal)) { + newVal = newVal.executeOn(originVal); + } + if (isWhat.isNumber(originVal) && isIncrementHelper(newVal)) { + newVal = newVal.executeOn(originVal); + } + return newVal; // always return newVal as fallback!! +} /** * Creates the params needed to $set a target based on a nested.path * @@ -953,17 +962,6 @@ function pluginMutations (userState) { } if (!ref) return error('patch-no-ref'); - function convertHelpers(originVal, newVal) { - if (isWhat.isArray(originVal) && isArrayHelper(newVal)) { - newVal = newVal.executeOn(originVal); - } - if (isWhat.isNumber(originVal) && isIncrementHelper(newVal)) { - newVal = newVal.executeOn(originVal); - } - return newVal; // always return newVal as fallback!! - } - // const refPropsPicked = filter(ref, Object.keys(patches)) - // const patchesSanitised = merge({ extensions: [convertHelpers] }, refPropsPicked, patches) var patchesFlat = flatten.flattenObject(patches); for (var _i = 0, _b = Object.entries(patchesFlat); _i < _b.length; _i++) { var _c = _b[_i], path = _c[0], value = _c[1];