blob: bc6c406fdb0b9504394f6347b5c22a9005e2b858 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
const GitBook = require('gitbook-core');
const SearchInput = require('./components/Input');
const SearchResults = require('./components/Results');
const reducers = require('./reducers');
const Search = require('./actions/search');
/**
* Url of the page changed, we update the search according to this.
* @param {GitBook.Location} location
* @param {Function} dispatch
*/
const onLocationChange = (location, dispatch) => {
const { query } = location;
const q = query.get('q');
dispatch(Search.handleQuery(q));
};
module.exports = GitBook.createPlugin({
activate: (dispatch, getState, { Navigation, Components }) => {
// Register the navigation handler
dispatch(Navigation.listen(onLocationChange));
// Register components
dispatch(Components.registerComponent(SearchInput, { role: 'search:input' }));
dispatch(Components.registerComponent(SearchResults, { role: 'search:results' }));
},
reduce: reducers,
actions: {
Search
}
});
|