Пример #1
0
document.addEventListener('keydown', function(e) {
  // cmd+shift+k
  const cmdShiftK = e.metaKey && e.shiftKey && e.keyCode === 75;
  const cmdShiftI = e.metaKey && e.shiftKey && e.keyCode === 73;

  if(cmdShiftI) {
    const str = transitImmutable.toJSON(store.getState());
    console.log(str);
  }
  else if(cmdShiftK) {
    e.preventDefault();
    const str = transitImmutable.toJSON(store.getState());
    const response = prompt(
      'App State (note: router will be broken after this. I don\'t ' +
      'know how to fix it yet)',
      str
    );
    let state = store.getState();
    try {
      if(response) {
        state = transitImmutable.fromJSON(response);
      }
      else {
        return;
      }
    }
    catch(e) {
      console.log('error', e);
    }

    loadSnapshot(state, store, getRoutes(store, history));
  }
});
Пример #2
0
const loadSnapshot = require('../../src/lib/load-snapshot');
const createStore = require('../../src/create-store');
const { updateUser, updatePageTitle } = require('../../src/actions/page');
const getRoutes = require('../../src/routes');
const { syncReduxAndRouter } = require('redux-simple-router');
const api = require('./impl/api');

// CSS dependencies

require('nprogress/nprogress.css');
require('../css/theme/main.less');

// App init

const payload = transitImmutable.fromJSON(
  decodeTextContent(document.getElementById('payload').textContent)
);

const store = createStore(payload.state ? payload.state : undefined);
store.dispatch(updateUser(payload.user));

// Allow copying and pasting app state
document.addEventListener('keydown', function(e) {
  // cmd+shift+k
  const cmdShiftK = e.metaKey && e.shiftKey && e.keyCode === 75;
  const cmdShiftI = e.metaKey && e.shiftKey && e.keyCode === 73;

  if(cmdShiftI) {
    const str = transitImmutable.toJSON(store.getState());
    console.log(str);
  }
Пример #3
0
 }).then(doc => {
   const immutableState = transit.fromJSON(JSON.stringify(doc.state));
   t.equal(store.getState().get('x'), immutableState.get('x'));
 }).then(() => {
Пример #4
0
const DUMMY_INITIAL_DATA = Map({
    visibilityFilter: filters.VISIBILITY_FILTER.ALL,
    todos: List([
        Map({isDone: true, text: 'make components'}),
        Map({isDone: false, text: 'design actions'}),
        Map({isDone: false, text: 'implement reducer'}),
        Map({isDone: false, text: 'connect components'})
    ])
});

// create the saga middleware
const sagaMiddleware = createSagaMiddleware();

/* parse data from local storage (if exists) to initial state*/
const PERSISTED_STATE = sessionStorage.getItem('reduxState') ? Map(fromJSON(sessionStorage.getItem('reduxState'))) : DUMMY_INITIAL_DATA;

/* create store and init it by initial data, enhance by middleware*/
// const store = createStore(reducer, PERSISTED_STATE, applyMiddleware(actionsLogger, thunk));
const store = createStore(reducer, PERSISTED_STATE, applyMiddleware(actionsLogger, sagaMiddleware));

sagaMiddleware.run(rootSaga);

/*
 * Subscribe on store change event.
 * Serialize state and save to local storage.
 */
store.subscribe(()=> {
    sessionStorage.setItem('reduxState', toJSON(store.getState()));
});
 function(raw){
   if(typeof raw === 'string'){
     return transit.fromJSON(raw)
   }
   return raw
 },