import EventEmitter from 'eventemitter3';

const EVENT_NAME = 'ACTIONIZER_STORE.NOTIFY';

export const createStore = (initialState) => {
  let state = initialState;
  const emitter = new EventEmitter();

  const subscribe = (listener) => {
    emitter.on(EVENT_NAME, listener);

    return () => {
      emitter.removeListener(EVENT_NAME, listener);
    };
  };

  const getState = () => {
    return state;
  };

  const next = (nextState) => {
    if (state !== nextState) {
      state = nextState;
      emitter.emit(EVENT_NAME, state);
    }
  };

  const actionize = (action) => {
    return action(next, getState);
  };

  return {
    subscribe,
    getState,
    actionize
  };
};

@@ -40,44 +40,327 @@
 ';%0A%0A
+%0A
 const 
-EVENT_NAME = 'ACTIONIZER_STORE
+PUT_ACTION_EVENT  = 'ACTIONIZER.ACTION.PUT';%0Aconst CALL_ACTION_EVENT = 'ACTIONIZER.ACTION.CALL';%0A%0Aexport const put = (nextState) =%3E %7B%0A  return %7Btype: PUT_ACTION_EVENT, nextState%7D;%0A%7D;%0A%0Aexport const call = (fn, args) =%3E %7B%0A  return %7Btype: CALL_ACTION_EVENT, fn, args%7D;%0A%7D;%0A%0A%0Aconst EMITTER_EVENT = 'ACTIONIZER.EMITTER
 .NOT
@@ -532,25 +532,28 @@
 ter.on(E
-VENT_NAME
+MITTER_EVENT
 , listen
@@ -607,25 +607,28 @@
 stener(E
-VENT_NAME
+MITTER_EVENT
 , listen
@@ -704,20 +704,24 @@
   const 
-next
+setState
  = (next
@@ -750,9 +750,9 @@
 ate 
-!
+=
 == n
@@ -762,19 +762,28 @@
 State) %7B
-%0A  
+ return; %7D%0A%0A
     stat
@@ -797,26 +797,24 @@
 tState;%0A    
-  
 emitter.emit
@@ -819,105 +819,648 @@
 it(E
-VENT_NAME, state);%0A    %7D%0A  %7D;%0A%0A  const actionize = (action) =%3E %7B%0A    return action(next, getState
+MITTER_EVENT, state);%0A  %7D;%0A%0A  const dispatch = (actionGenerator) =%3E %7B%0A%0A    const step = (result) =%3E %7B%0A      const %7B done, value %7D = result;%0A%0A      if (done) %7B return; %7D%0A%0A      switch (value.type) %7B%0A        case PUT_ACTION_EVENT:%0A          setState(value.nextState);%0A          step(actionGenerator.next(state));%0A          break;%0A        case CALL_ACTION_EVENT:%0A          const promise = value.fn(...value.args);%0A          promise.then((val) =%3E %7B%0A            step(actionGenerator.next(val));%0A          %7D).catch((e) =%3E %7B%0A            step(actionGenerator.throw(e));%0A          %7D);%0A          break;%0A      %7D%0A    %7D;%0A%0A    step(actionGenerator.next()
 );%0A 
@@ -1512,22 +1512,22 @@
     
-actionize
+dispatch
 %0A  %7D;%0A
+%0A
 %7D;%0A

Change interface