aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/lib/getHistory.js
blob: daa984b9767679527783e1d7db4e6912410c97c4 (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
34
35
import {
  weekFromLocation,
  userFromLocation,
  makeUpdatePathname,
  makeUpdateQuery,
} from './url';

/**
 * Make a getHistory function. This function is used in index.js when creating
 * the redux store.
 * @param {history} history
 *   The history object from the `history` package.
 *   There may only be a single shared history object in the application, which
 *   is why it's delivered from `../index.js`.
 */
export default function makeGetHistory(history) {
  /**
   * Get a collection of helpers for common browser history interactions, and a
   * collection of precalculated values from the address bar. This function is
   * used in actions.
   */
  return function getHistory() {
    const user = userFromLocation(history.location);
    const week = weekFromLocation(history.location);
    const updatePathname = makeUpdatePathname(history);
    const updateQuery = makeUpdateQuery(history);

    return {
      user,
      week,
      updatePathname,
      updateQuery,
    };
  };
}