JSFiddle - React, Tailwind, and code Playground

by pwmckenna

JavaScript

import Fluxible from 'fluxible';
import assert from 'assert';
import { createReducerStore } from 'fluxible-reducer-store';

const UserStore = createReducerStore({
    storeName: 'UserStore',
    initialState: null,
    reducers: {
        USER: (state, user) => user
    },
    getters: {
        getUser: state => state
    }
});

it('should restore dehydrated state', done => {
  const fluxible = new Fluxible();
  fluxible.registerStore(UserStore);
  const context = fluxible.createContext();

  const initialUser = { name: 'Initial Name' };
  context.getActionContext().dispatch('USER', initialUser);
  assert.deepEqual(context.getActionContext().getStore(UserStore).getUser(), initialUser);

  const dehydrated = context.dehydrate();

  const updatedUser = { name: 'Updated Name' };
  context.getActionContext().dispatch('USER', updatedUser);
  assert.deepEqual(context.getActionContext().getStore(UserStore).getUser(), updatedUser);

  context.rehydrate(dehydrated).then(() => {
    assert.deepEqual(context.getActionContext().getStore(UserStore).getUser(), initialUser);
    done();
  });