Skip to content

Commit

Permalink
Added appEpics that eanble to pass an object with app specific Epics.…
Browse files Browse the repository at this point in the history
… If Epic's name is the same the one in plugins this will override plugin's one
  • Loading branch information
kappu committed Mar 27, 2017
1 parent c8938c7 commit 5c158ac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion web/client/jsapi/MapStore2.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ const MapStore2 = {
pages
}))(require('../components/app/StandardRouter'));

const appStore = require('../stores/StandardStore').bind(null, initialState || {}, {});
const appStore = require('../stores/StandardStore').bind(null, initialState || {}, {}, {});
const initialActions = getInitialActions(options);
const appConfig = {
storeOpts: assign({}, storeOpts, {notify: true}),
Expand Down
2 changes: 1 addition & 1 deletion web/client/product/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const startApp = () => {
const appStore = require('../stores/StandardStore').bind(null, initialState, {
home: require('./reducers/home'),
maps: require('../reducers/maps')
});
}, {});

const initialActions = [
() => loadMaps(ConfigUtils.getDefaults().geoStoreUrl, ConfigUtils.getDefaults().initialMapFilter || "*")
Expand Down
4 changes: 2 additions & 2 deletions web/client/stores/StandardStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const {createEpicMiddleware} = require('redux-observable');
const SecurityUtils = require('../utils/SecurityUtils');
const ListenerEnhancer = require('@carnesen/redux-add-action-listener-enhancer').default;

module.exports = (initialState = {defaultState: {}, mobile: {}}, appReducers = {}, plugins, storeOpts) => {
module.exports = (initialState = {defaultState: {}, mobile: {}}, appReducers = {}, appEpics = {}, plugins, storeOpts) => {
const allReducers = combineReducers(plugins, {
...appReducers,
localConfig: require('../reducers/localConfig'),
Expand All @@ -39,7 +39,7 @@ module.exports = (initialState = {defaultState: {}, mobile: {}}, appReducers = {
mapInitialConfig: () => {return null; },
layers: () => {return null; }
});
const rootEpic = combineEpics(plugins);
const rootEpic = combineEpics(plugins, appEpics);
const defaultState = initialState.defaultState;
const mobileOverride = initialState.mobile;
const epicMiddleware = createEpicMiddleware(rootEpic);
Expand Down
6 changes: 3 additions & 3 deletions web/client/utils/PluginsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ const PluginsUtils = {
* @param {function[]} [epics] the epics to add to the plugins' ones
* @return {function} the rootEpic, obtained combining plugins' epics and the other epics passed as argument.
*/
combineEpics: (plugins, epics = []) => {
const pluginEpics = getEpics(plugins);
return combineEpics(...[ ...Object.keys(pluginEpics).map(k => pluginEpics[k]), ...epics]);
combineEpics: (plugins, epics = {}) => {
const pluginEpics = assign({}, getEpics(plugins), epics);
return combineEpics( ...Object.keys(pluginEpics).map(k => pluginEpics[k]));
},
getReducers,
filterState,
Expand Down
7 changes: 7 additions & 0 deletions web/client/utils/__tests__/PluginUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const expect = require('expect');
const PluginsUtils = require('../PluginsUtils');
const assign = require('object-assign');
const MapSearchPlugin = require('../../plugins/MapSearch')

describe('PluginsUtils', () => {
beforeEach( () => {
Expand Down Expand Up @@ -72,5 +73,11 @@ describe('PluginsUtils', () => {
expect(desc1.items[0].cfg).toExist();

});
it('combineEpics', () => {
const plugins = {MapSearchPlugin: MapSearchPlugin};
const appEpics = {appEpics: (actions$) => actions$};
const epics = PluginsUtils.combineEpics(plugins, appEpics);
expect(typeof epics ).toEqual('function');
});

});

0 comments on commit 5c158ac

Please sign in to comment.