```//object to store throttled function for each t...
# javascript
r
Copy code
//object to store throttled function for each topic
var topic_funcs = {}

//function to create new throttled dispatch function
var createDispatchFunc = ()=>{
  return _.throttle( (payload)=>{
    store.dispatch('broker/handleMessage', payload)
  }, 3000);
}

//function to retrieve dispatch function 
var getFunc = (topic) => {
  if( topic_funcs[topic] == undefined ){
    topic_funcs[topic] = createDispatchFunc();
  }
  return topic_funcs[topic];
}

// on message recieved from mqtt broker
client.on('message', (topic,payload) => {
  //get func and execute
  getFunc(topic)(payload);
} )
p
build a throttle function that your
client.on
function uses to delay the output...I can send an example
r
So I am using the throttle function from lodash the library if thats where you headed
p
Yea you are right, I missed your store.dispatch delay there; basically what I was going to suggest
👍 1