JSFiddle - React, Tailwind, and code Playground

by evgkch

JavaScript

const store = { state: {}, _stack: null };

store.dispatch = function(state) {
	store.state = Object.assign(store.state, state);
  console.log('store updated');
  console.log(store.state);
}

let dispatchStack;

function dispatch(state){
	if (typeof state == 'fucntion')
  {
  	
  }
	clearTimeout(dispatchStack);
	dispatchStack = setTimeout(
  	() => store.dispatch(state), 0
  );
}

dispatch({ a: 1 });
dispatch({ a: 2 });
dispatch({ a: 3 });