-
Notifications
You must be signed in to change notification settings - Fork 7
/
subscriptions.js
41 lines (36 loc) · 1.06 KB
/
subscriptions.js
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
34
35
36
37
38
39
40
41
import {
searchWillEnter$,
searchDidEnter$,
} from '@shopgate/engage/search';
import { getCurrentRoute } from '@shopgate/engage/core';
import { fetchSearchResults } from '@shopgate/engage/search';
import { fetchFilters } from '@shopgate/engage/filter';
import { searchFiltersDidUpdate$ } from './streams';
/**
* Filter subscriptions.
* @param {Function} subscribe The subscribe function.
*/
export default function search(subscribe) {
subscribe(searchWillEnter$, ({ action, dispatch }) => {
const { filters } = action.route.state;
const { s: searchPhrase, sort } = action.route.query;
dispatch(fetchSearchResults({
filters,
searchPhrase,
sort,
}));
});
subscribe(searchFiltersDidUpdate$, ({ action, dispatch, getState }) => {
const { filters } = action;
const { query } = getCurrentRoute(getState());
const { s: searchPhrase, sort } = query;
dispatch(fetchSearchResults({
filters,
searchPhrase,
sort,
}));
});
subscribe(searchDidEnter$, ({ dispatch }) => {
dispatch(fetchFilters());
});
}