Skip to content

Commit

Permalink
Merge e9229e7 into 462d143
Browse files Browse the repository at this point in the history
  • Loading branch information
arraintxo authored Mar 19, 2021
2 parents 462d143 + e9229e7 commit c239108
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ export const mapModel = normalizeNamespace((namespace, models) => {

const valify = String(val);

const originState = valify.substring(
valify.indexOf('state.') + 6,
valify.indexOf(';') === -1 ? undefined : valify.indexOf(';'),
);
let originState;

if (valify.startsWith('state.')) {
originState = valify.substring(
valify.indexOf('state.') + 6,
valify.indexOf(';') === -1 ? undefined : valify.indexOf(';'),
);
} else {
originState = valify.substring(valify.indexOf('.') + 1, valify.indexOf(';'));
}

this.$store.commit(type, { label: originState || key, value });
},
Expand Down
12 changes: 6 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ describe('vuex-bound', () => {
const Component = {
template: `
<div>
<input v-model="foo"> {{ foo }}
<input v-model="fooBarBaz"> {{ fooBarBaz }}
</div>
`,
computed: {
...mapModel('a/b', ['foo']),
...mapModel('a/b', ['fooBarBaz']),
},
};

Expand All @@ -144,7 +144,7 @@ describe('vuex-bound', () => {
modules: {
b: {
namespaced: true,
state: { foo: 'foo' },
state: { fooBarBaz: 'foo' },
mutations: { ...updateModel() },
},
},
Expand All @@ -155,11 +155,11 @@ describe('vuex-bound', () => {
const wrapper = shallowMount(Component, { localVue, store });

expect(wrapper.html()).toMatchSnapshot();
expect(store.state.a.b.foo).toMatch('foo');
expect(store.state.a.b.fooBarBaz).toMatch('foo');

wrapper.setData({ foo: 'bar' });
wrapper.setData({ fooBarBaz: 'bar' });
expect(wrapper.html()).toMatchSnapshot();
expect(store.state.a.b.foo).toMatch('bar');
expect(store.state.a.b.fooBarBaz).toMatch('bar');
});

it('should handle object', () => {
Expand Down

0 comments on commit c239108

Please sign in to comment.