• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

spautz / react-hibernate / 10893842371

16 Sep 2024 11:48PM UTC coverage: 90.476% (-0.7%) from 91.176%
10893842371

push

github

web-flow
build(deps): bump express from 4.19.2 to 4.21.0 (#65)

Bumps [express](https://github.com/expressjs/express) from 4.19.2 to 4.21.0.
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.0/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.19.2...4.21.0)

---
updated-dependencies:
- dependency-name: express
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Steven Pautz <spautz@gmail.com>

21 of 23 branches covered (91.3%)

Branch coverage included in aggregate %.

74 of 82 relevant lines covered (90.24%)

14.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.94
/packages/redux-pauseable-store/src/createPauseableStore.tsx
1
import { Action, Store } from 'redux';
2

3
import { PauseableStoreInstance, PauseableStoreOptions } from './types';
4

5
const createPauseableStore = (
5✔
6
  parentStore: Store,
7
  options?: PauseableStoreOptions,
8
): PauseableStoreInstance => {
9
  const {
10
    isPaused: isInitiallyPaused = false,
48✔
11
    canDispatch: canInitiallyDispatch = 'warn',
49✔
12
    notifyListersOnUnpause: notifyListenersInitially = true,
52✔
13
  } = options || {};
54✔
14

15
  const pauseableStore = {} as PauseableStoreInstance;
54✔
16
  let stateAtPause = isInitiallyPaused ? parentStore.getState() : null;
54✔
17
  const listeners: Array<() => void> = [];
54✔
18

19
  const dispatch = (action: Action) => {
54✔
20
    if (
62✔
21
      pauseableStore.isPaused &&
68✔
22
      pauseableStore.canDispatch !== true &&
23
      pauseableStore.canDispatch !== false
24
    ) {
25
      console.warn(
3✔
26
        'Something is trying to dispatch an action to a paused PauseableStore. Set `canDispatch` to true or false to disable this warning.',
27
        { action, pauseableStore },
28
      );
29
    }
30
    if (pauseableStore.canDispatch) {
62✔
31
      return parentStore.dispatch(action);
38✔
32
    }
33
    return null;
24✔
34
  };
35

36
  const subscribe = (listener: () => void) => {
54✔
37
    listeners.push(listener);
4✔
38

39
    const wrappedListener = () => {
4✔
40
      // Ignore when paused
41
      if (!pauseableStore.isPaused) {
7✔
42
        listener();
4✔
43
      }
44
    };
45

46
    const unsubscribe = parentStore.subscribe(wrappedListener);
4✔
47
    const wrappedUnsubscribe = () => {
4✔
48
      const indexOfListener = listeners.indexOf(listener);
1✔
49
      if (indexOfListener !== -1) {
1!
50
        listeners.splice(indexOfListener, 1);
1✔
51
      } else if (process.env.NODE_ENV !== 'production') {
×
52
        console.error(
×
53
          'Internal error: tried to unsubscribe a listener, but the listener was not found',
54
        );
55
      }
56
      unsubscribe();
1✔
57
    };
58

59
    return wrappedUnsubscribe;
4✔
60
  };
61

62
  const getState = () => {
54✔
63
    if (pauseableStore.isPaused) {
62✔
64
      return stateAtPause;
23✔
65
    }
66
    return parentStore.getState();
39✔
67
  };
68

69
  const setPaused = (newIsPaused: boolean) => {
54✔
70
    pauseableStore.isPaused = newIsPaused;
16✔
71
    const currentState = parentStore.getState();
16✔
72

73
    if (newIsPaused) {
16✔
74
      stateAtPause = currentState;
9✔
75
    } else {
76
      if (pauseableStore.notifyListersOnUnpause && currentState !== stateAtPause) {
7✔
77
        // Let subscribers know that something has changed
78
        listeners.forEach((listener) => listener());
6✔
79
      }
80
      stateAtPause = null;
7✔
81
    }
82
  };
83

84
  const setDispatch = (newCanDispatch: boolean | 'warn') => {
54✔
85
    pauseableStore.canDispatch = newCanDispatch;
12✔
86
  };
87

88
  const replaceReducer = () => {
54✔
89
    throw new Error(
1✔
90
      'Cannot replaceReducer on a pauseableStore: replaceReducer on the parent store, instead',
91
    );
92
  };
93

94
  Object.assign(pauseableStore, {
54✔
95
    // Redux Store interface
96
    ...parentStore,
97
    dispatch,
98
    subscribe,
99
    getState,
100
    replaceReducer,
101
    // @TODO: Do we also need to handle [$$observable]: observable, ?
102

103
    // PauseableStore additions
104
    isPaused: isInitiallyPaused,
105
    setPaused,
106
    canDispatch: canInitiallyDispatch,
107
    setDispatch,
108
    notifyListersOnUnpause: notifyListenersInitially,
109

110
    _parentStore: parentStore,
111
  });
112

113
  return pauseableStore;
54✔
114
};
115

116
export { createPauseableStore };
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc