0.2.2 • Published 6 years ago

jsfp-runner v0.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago
const app = require('./index');

const debug = false;
const actions = ['inc', 'reset', 'log'];

function initializeState(actions) {
  return [
    {
      counter: 0
    },
    [async () => actions.inc()]
  ];
}

function update(msg, state, actions) {
  switch (msg.type) {
    case actions.inc_type:
      const nextCounter = state.counter + 1;
      return [
        { ...state, counter: nextCounter },
        [
          async () => actions.log(),
          async state =>
            setTimeout(
              () => (state.counter >= 10 ? actions.reset() : actions.inc()),
              1000
            )
        ]
      ];

    case actions.reset_type:
      return [{ ...state, counter: 0 }, [async () => actions.inc()]];

    case actions.log_type:
      console.log('Counter', state.counter);
      return [state];
  }

  return state;
}

app(actions, initializeState, update, app.logger);
0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.0

6 years ago