Skip to content

Instantly share code, notes, and snippets.

@trevdor
Created November 2, 2017 22:21
Show Gist options
  • Save trevdor/3c195dece06bc5f6b81cd3534980b2bb to your computer and use it in GitHub Desktop.
Save trevdor/3c195dece06bc5f6b81cd3534980b2bb to your computer and use it in GitHub Desktop.
import _ from 'lodash';
import Immutable from 'immutable';
import {
initialState,
getPlan,
getPlanProperty,
getPlans,
} from '../redux/reducers/PlanReducer';
const fluxClearState = (state, fluxStore) => {
state = initialState;
};
const fluxGetPlan = (state, index) => {
const planObj = index ? getPlanProperty(state, { index }) : getPlan(state);
if (Immutable.Map.isMap(planObj) || Immutable.List.isList(planObj)) {
return planObj.toJS();
} else {
return planObj;
}
};
const fluxGetPlans = state => {
const plans = getPlans(state);
return plans.isEmpty() ? undefined : _.values(plans.toJS());
};
const fluxGetters = {
clearState(state) {
fluxClearState();
this.emitChange();
},
getPlans: state => fluxGetPlans(state),
getPlan: (state, index) => fluxGetPlan(state, index),
};
export default createReduxFluxBridge(fluxGetters);
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
import Dispatcher from 'utils/Dispatcher';
import * as StoreCreator from 'utils/StoreCreator';
export function createReduxFluxBridge(getters) {
return function(reduxStore) {
const fluxStore = StoreCreator.create(
getters.map(getter => {
return (...args) => getter(reduxStore, ...args);
}),
);
Dispatcher.register(({ action }) => {
reduxStore.dispatch(action);
fluxStore.emitChange();
});
return fluxStore;
};
}
// function wip() {
// const fluxStore = StoreCreator.create(getters);
//
// return {
// getGlobalReduxState: store => store.getState(),
// };
// }
//
// function state {
// return reduxStore.getState();
// }
//
// export function setStore(store) {
// reduxStore = store;
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment