Skip to content

Commit

Permalink
Fix: Patch to nested object is changing object content order #300
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Apr 22, 2020
1 parent 128c639 commit 34d9f7b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 43 deletions.
20 changes: 9 additions & 11 deletions dist/index.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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];
Expand Down
20 changes: 9 additions & 11 deletions dist/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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];
Expand Down
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -72,14 +72,8 @@
},
"ava": {
"compileEnhancements": false,
"extensions": [
"ts"
],
"require": [
"ts-node/register"
],
"helpers": [
"**/helpers/**/*"
]
"extensions": ["ts"],
"require": ["ts-node/register"],
"helpers": ["**/helpers/**/*"]
}
}
20 changes: 9 additions & 11 deletions test/helpers/index.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 34d9f7b

Please sign in to comment.