Skip to content

Having problems with sync() and object syntax #103

@giuseppe-esposito-87

Description

@giuseppe-esposito-87

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions