Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documented plugin utils #1621

Merged
merged 4 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions docma-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@
"iconClass": "ico-mouse-pointer",
"label": "Reference",
"items": [
{ "label": "Components", "href": "api/components"},
{ "label": "Actions", "href": "api/actions" },
{ "label": "Reducers", "href": "api/reducers" },
{ "label": "Epics", "href": "api/epics" },
{ "label": "Framework", "href": "api/framework"},

{ "separator": true },
{ "label": "Plugins", "href": "api/plugins" }

Expand Down Expand Up @@ -106,11 +104,24 @@
},
"src": [
{
"components" : ["web/client/components/mapcontrols/search/SearchBar.jsx"],
"actions" : ["web/client/actions/search.js"],
"reducers" : ["web/client/reducers/search.js"],
"epics": "web/client/epics/search.js",
"framework" : [
"web/client/components/index.jsdoc",
"web/client/components/mapcontrols/search/SearchBar.jsx",

"web/client/actions/index.jsdoc",
"web/client/actions/search.js",

"web/client/reducers/index.jsdoc",
"web/client/reducers/search.js",

"web/client/epics/index.jsdoc",
"web/client/epics/search.js",

"web/client/utils/index.jsdoc",
"web/client/utils/PluginsUtils.js"
],
"plugins": [
"web/client/plugins/index.jsdoc",
"web/client/plugins/Search.jsx",
"web/client/plugins/BackgroundSwitcher.jsx",
"web/client/plugins/Map.jsx",
Expand Down
1 change: 1 addition & 0 deletions inch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"web/client/plugins/*.jsx",
"web/client/actions/*js",
"web/client/reducers/*js",
"web/client/utils/*.js",
"web/client/epics/*js",
"web/client/jsapi/*js"
]
Expand Down
2 changes: 1 addition & 1 deletion web/client/actions/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ function loadMapInfo(url, mapId) {
}
module.exports = {MAP_CONFIG_LOADED, MAP_CONFIG_LOAD_ERROR,
MAP_INFO_LOAD_START, MAP_INFO_LOADED, MAP_INFO_LOAD_ERROR,
loadMapConfig, loadMapInfo, configureMap};
loadMapConfig, loadMapInfo, configureMap, configureError};
6 changes: 6 additions & 0 deletions web/client/actions/index.jsdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Redux actions.
* @see {@link http://redux.js.org/docs/basics/Actions.html|the redux documentation} for details
* @name actions
*
*/
5 changes: 4 additions & 1 deletion web/client/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

const TEXT_SEARCH_STARTED = 'TEXT_SEARCH_STARTED';
const TEXT_SEARCH_RESULTS_LOADED = 'TEXT_SEARCH_RESULTS_LOADED';
const TEXT_SEARCH_PERFORMED = 'TEXT_SEARCH_PERFORMED';
Expand Down Expand Up @@ -158,6 +157,10 @@ function cancelSelectedItem(item) {
};
}

/**
* Actions for search
* @name actions.search
*/
module.exports = {
TEXT_SEARCH_STARTED,
TEXT_SEARCH_LOADING,
Expand Down
6 changes: 6 additions & 0 deletions web/client/components/index.jsdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* React components
* @see {@link https://facebook.github.io/react/docs/react-component.html|the React documentation} for details
* @name components
*
*/
5 changes: 5 additions & 0 deletions web/client/epics/index.jsdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* redux-observable epics
* @see {@link https://redux-observable.js.org/docs/basics/Epics.html|the redux-observable documentation} for details
* @name epics
*/
9 changes: 6 additions & 3 deletions web/client/epics/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const {get} = require('lodash');
* Gets every `TEXT_SEARCH_STARTED` event.
* Dispatches the request to all the services in the action, postprocess them
* and updates every tume the results
* @param {Observable} action$ manages `TEXT_SEARCH_STARTED` and `TEXT_SEARCH_RESULTS_PURGE`, `TEXT_SEARCH_RESET`, `TEXT_SEARCH_ITEM_SELECTED` for cancellation
* @param {external:Observable} action$ manages `TEXT_SEARCH_STARTED` and `TEXT_SEARCH_RESULTS_PURGE`, `TEXT_SEARCH_RESET`, `TEXT_SEARCH_ITEM_SELECTED` for cancellation
* @memberof epics.search
* @return {Observable}
* @return {external:Observable}
*/
const searchEpic = action$ =>
action$.ofType(TEXT_SEARCH_STARTED)
Expand Down Expand Up @@ -130,7 +130,10 @@ const searchItemSelected = action$ =>
}
return Rx.Observable.from(actions);
});

/**
* Actions for search
* @name epics.search
*/
module.exports = {
searchEpic,
searchItemSelected
Expand Down
6 changes: 6 additions & 0 deletions web/client/plugins/index.jsdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* MapStore2 plugins
* @name plugins
* @see {@link plugins-architecture}
*
*/
6 changes: 6 additions & 0 deletions web/client/reducers/index.jsdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Redux reducers.
* @see {@link http://redux.js.org/docs/basics/Reducers.html|the redux documentation} for details
* @name reducers
*
*/
39 changes: 37 additions & 2 deletions web/client/utils/PluginsUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright 2016, GeoSolutions Sas.
* All rights reserved.
*
Expand Down Expand Up @@ -121,17 +121,29 @@ const getReducers = (plugins) => Object.keys(plugins).map((name) => plugins[name
.reduce((previous, current) => assign({}, previous, current), {});
const getEpics = (plugins) => Object.keys(plugins).map((name) => plugins[name].epics)
.reduce((previous, current) => assign({}, previous, current), {});

/**
* Utilities to manage plugins
* @class
* @memberof utils
*/
const PluginsUtils = {
/**
* Produces the reducers from the plugins, combined with other plugins
* @param {array} plugins the plugins
* @param {array} reducers other plugins
* @param {object} [reducers] other reducers
* @returns {function} a reducer made from the plugins' reducers and the reducers passed as 2nd parameter
*/
combineReducers: (plugins, reducers) => {
const pluginsReducers = getReducers(plugins);
return combineReducers(assign({}, reducers, pluginsReducers));
},
/**
* Produces the rootEpic for the plugins, combined with other epics passed as 2nd argument
* @param {array} plugins the plugins
* @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]);
Expand All @@ -140,6 +152,29 @@ const PluginsUtils = {
filterState,
getPlugins: (plugins) => Object.keys(plugins).map((name) => plugins[name])
.reduce((previous, current) => assign({}, previous, omit(current, 'reducers')), {}),
/**
* provide the pluginDescriptor for a given plugin, with a state and a configuration
* @param {object} state the state. This is required to laod plugins that depend from the state itself
* @param {object} plugins all the plugins, like this:
* ```
* {
* P1Plugin: connectdComponent1,
* P2Plugin: connectdComponent2
* }
* ```
* @param {array} pluginConfig the configurations of the plugins
* @param {object} [loadedPlugins] the plugins loaded with `require.ensure`
* @return {object} a pluginDescriptor like this:
* ```
* {
* id: "P1",
* name: "P1",
* items: // the contained items
* cfg: // the configuration
* impl // the real implementation
* }
* ```
*/
getPluginDescriptor: (state, plugins, pluginsConfig, pluginDef, loadedPlugins = {}) => {
const name = isObject(pluginDef) ? pluginDef.name : pluginDef;
const id = isObject(pluginDef) ? pluginDef.id : null;
Expand Down
5 changes: 5 additions & 0 deletions web/client/utils/index.jsdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Misc utility objects and methods
* @name utils
*
*/