diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-09-28 18:14:35 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-09-28 18:14:35 +0200 |
commit | 287c80b2e116572669f2a7073731ba7350e3619a (patch) | |
tree | 1572bab423b927e16bca4d56020aeec6442fe1a9 /packages/gitbook-plugin-search/src/reducers/search.js | |
parent | 26fc021b900f6b28a180fa8360313b3193e6bf5e (diff) | |
download | gitbook-287c80b2e116572669f2a7073731ba7350e3619a.zip gitbook-287c80b2e116572669f2a7073731ba7350e3619a.tar.gz gitbook-287c80b2e116572669f2a7073731ba7350e3619a.tar.bz2 |
Start search plugin
Diffstat (limited to 'packages/gitbook-plugin-search/src/reducers/search.js')
-rw-r--r-- | packages/gitbook-plugin-search/src/reducers/search.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-search/src/reducers/search.js b/packages/gitbook-plugin-search/src/reducers/search.js new file mode 100644 index 0000000..ac49698 --- /dev/null +++ b/packages/gitbook-plugin-search/src/reducers/search.js @@ -0,0 +1,37 @@ +const GitBook = require('gitbook-core'); +const { Record, List, OrderedMap } = GitBook.Immutable; + +const TYPES = require('../actions/types'); + +const Result = Record({ + url: String(''), + title: String(''), + body: String('') +}); + +const SearchState = Record({ + // Current query + query: String(''), + // Current list of results + results: List(), + // Search handlers + handlers: OrderedMap() +}); + +module.exports = (state = SearchState(), action) => { + switch (action.type) { + + case TYPES.REGISTER_HANDLER: + return state.merge({ + handlers: state.handlers.set(action.name, action.handler) + }); + + case TYPES.UNREGISTER_HANDLER: + return state.merge({ + handlers: state.handlers.remove(action.name) + }); + + default: + return state; + } +}; |