import 'babel-polyfill';
import { applyMiddleware, createStore } from 'redux';
import { resourceMiddleware, createResourceAction } from '../src';

const createStoreWithMiddleWare = applyMiddleware(resourceMiddleware)(createStore);

const match = (expression, matchers, defaultState) => {
  for (const key of Object.keys(matchers)) {
    if (expression === key) {
      return matchers[key]();
    }
  }

  return defaultState;
};

const INITIAL_STATE = {
  fetching: false,
  user: null,
  error: null
};

const reducer = (state = INITIAL_STATE, action) => match(action.type, {
  FETCH_USER:       () => ({ ...state, fetching: true }),
  RECEIVE_USER:     () => ({ ...state, fetching: false, user: action.payload }),
  ERR_RECEIVE_USER: () => ({ ...state, fetching: false, error: action.payload })
}, state);

const store = createStoreWithMiddleWare(reducer);

const fetchUser = createResourceAction(
  '/users/:id', 'FETCH_USER', 'RECEIVE_USER', 'ERR_RECEIVE_USER'
);

store.dispatch(fetchUser({ id: 1 })).then(() => {
  document.getElementById('main').innerHTML =
    JSON.stringify(store.getState(), null, '  ');
});

@@ -794,177 +794,707 @@
 d %7D)
-%0A%7D, state);%0A%0Aconst store = createStoreWithMiddleWare(reducer);%0A%0Aconst fetchUser = createResourceAction(%0A  '/users/:id', 'FETCH_USER', 'RECEIVE_USER', 'ERR_RECEIVE_USER'%0A
+,%0A  ADD_USER:         () =%3E (%7B ...state, adding: true %7D),%0A  ADDED_USER:       () =%3E (%7B ...state, adding: false, user: action.payload %7D),%0A  ERR_ADDING_USER:  () =%3E (%7B ...state, adding: false, error: action.payload %7D)%0A%7D, state);%0A%0Aconst store = createStoreWithMiddleWare(reducer);%0A%0Aconst fetchUser = createResourceAction(%0A  '/users/:id', 'FETCH_USER', 'RECEIVE_USER', 'ERR_RECEIVE_USER'%0A);%0A%0A//const createUser = createResourceAction(%0A//  %7B url: '/users/create', method: 'POST' %7D,%0A//  'ADD_USER', 'ADDED_USER', 'ERR_ADDING_USER'%0A//);%0A%0A//store.dispatch(createUser(null, %7B name: 'Tom' %7D)).then(() =%3E %7B%0A//  document.getElementById('main').innerHTML =%0A//    JSON.stringify(store.getState(), null, '  ');%0A//%7D
 );%0A%0A

Add some code for testing POST requests