Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
raresp committed Feb 28, 2019
1 parent 23df812 commit 824c397
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/index.js
@@ -1,5 +1,5 @@
import arrayToObject from './lib/array-to-object';
import Vue from 'vue';
import arrayToObject from './lib/array-to-object';

function normalizeNamespace(fn) {
return (...params) => {
Expand All @@ -19,26 +19,23 @@ function normalizeNamespace(fn) {
}

export function getField(state) {
return path => path.split(/[.[\]]+/).reduce((prev, key) => prev && prev.hasOwnProperty(key)?prev[key]:null, state);
return path => path.split(/[.[\]]+/).reduce((prev, key) => (prev && prev[key] ? prev[key] : null), state);
}

export function updateField(state, { path, value }) {

path.split(/[.[\]]+/).reduce((prev, key, index, array) => {
// console.log(`BEFORE: array: ${array} -- index:${index} -- key:${key} --- prev:`, prev);
// console.log('BEFORE: prev[key]:', prev[key]);

if (index < array.length - 1){
Vue.set(prev, key, prev[key] ? prev[key]: {});
}
else { // last key
if (index < array.length - 1) {
Vue.set(prev, key, prev[key] ? prev[key] : {});
} else { // last key
Vue.set(prev, key, value);
}

// console.log(`AFTER: array: ${array} -- index:${index} -- key:${key} --- prev:`, prev);

return prev[key];

}, state);
}

Expand Down
2 changes: 1 addition & 1 deletion test/nested-dynamic-store.test.js
Expand Up @@ -51,7 +51,7 @@ describe(`Component initialized with customized getter and mutation functions.`,
});

test(`It should update field values when the store is updated.`, () => {
store.commit('updateFormField', {path:'foo1.foo11.foo2.foo3', value:'fooValue'}, true);
store.commit(`updateFormField`, { path: `foo1.foo11.foo2.foo3`, value: `fooValue` }, true);
// store.state.form.foo1.foo11.foo2.foo3 = `fooValue`;

expect(wrapper.element.value).toBe(`fooValue`);
Expand Down

0 comments on commit 824c397

Please sign in to comment.