Search code examples
javascriptvue.jsvuexvue-reactivity

How can I pass vuex getter to module which isn't vuejs component, but keep it reactive?


For example following code. I want to do some tasks repeatedly in my module and I depend on value of getter which doesn't get updated right now. How can I keep it in sync with my vuex state? Thank you.

Inside my Vuex:

import { start, stop } from './externa-module.js

START_ACTION ({getters}) {
   start(getters.myVuexGetters);
}

Inside my external-module.js

let myVuexGetter = null;

function doSomeStuffRepeatedly(){
  console.log(myVuexGetter);
}

export function start(importedGetter){
   myVuexGetter = importedGetter;
   doSomeStuffRepeatedly();
}

Solution

  • Ok, it looks like I can't pass a single getter but a whole getters object which I get within the action. If anyone has a better answer I will be glad to learn it.