vuex-pathify: Having problems with sync() and object syntax

Hi,

I cannot make sync work with a nested object.

In my store, inside order.js I have:

import { make } from "vuex-pathify";

const state = {
  order: {},
};

const mutations = make.mutations(state);
const defaultActions = make.actions(state);
const actions = {
  ...defaultActions,
  setOrderItemQuantity: async (foo, payload) => {
    //todo
    console.log(foo);
    console.log(payload);
  },
};
const getters = make.getters(state);

export default {
  state,
  mutations,
  actions,
  getters,
};

inside the index.js

import Vue from "vue";
import Vuex from "vuex";
import order from "./Modules/order";
import pathify from "@/plugins/pathify";
import * as restActions from "./Modules/restActions";

const store = {
  state: {},
  mutations: {},
  actions: { ...restActions },
  modules: {
    order: {
      namespaced: true,
      modules: {
        order,
      },
    },
  },
};

Vue.use(Vuex);
export default new Vuex.Store({
  plugins: [pathify.plugin],
  ...store,
});

The order object loaded inside the state (via a rest action) is like this:

order = {
  uuid: 1,
  id: 1,
 warranty: true,
  orderItems: [
    {
      id: 1,
      title: 'myTitle',
      quantity: 10,
      totalPrice: 100,
      unitPrice: 10,
    },
    {
      // other orderItem
    },
    {
      // another one
    }
  ]
};

Then in my component I’m trying to set a computed property for the v-model as seen in the doc\examples:

[...]
export default {
[...]
  data() {
    return {
      index: 0 //this will be dynamic
    };
  },
  computed: {
    quantitySelected: sync("order/order@orderItems[:index].quantity|setOrderItemQuantity")
  }
}

But that is not working.

What I’ve discovered so far:

  1. quantitySelected: get("order/order@orderItems[0].quantity does work (I can print 10)
  2. quantitySelected: get("order/order@orderItems[:index].quantity|setOrderItemQuantity") does not work

Any idea what I’m doing wrong? Thank you

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (6 by maintainers)

Most upvoted comments

You said this is not working:

export default {
[...]
  data() {
    return {
      index: 0 //this will be dynamic
    };
  },
  computed: {
    quantitySelected: sync("order/order@orderItems[:index].quantity|setOrderItemQuantity")
  }
}

do this instead:

export default {
[...]
  data() {
    return {
      index: 0, //this will be dynamic
      name: 'order'
    };
  },
  computed: {
    quantitySelected: sync("order/:name@orderItems[:index].quantity|setOrderItemQuantity")
  }
}

Hey, sorry for the long wait! I’ve had quite a busy couple of weeks myself.

I’ll look into this tomorrow