reactish-state 1.2.1-alpha.1 → 1.2.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,18 +9,20 @@ const useSelector = (selectorParamFactory, deps) => {
9
9
  const cutoff = items.length - 1;
10
10
  const selectorFunc = items[cutoff];
11
11
  items.length = cutoff;
12
- const [context] = React.useState(() => [utils.createSubscriber(items)]);
12
+ const [context] = React.useState(() =>
13
+ // eslint-disable-next-line no-sparse-arrays
14
+ [, utils.createSubscriber(items)]);
13
15
  return useSnapshot.useSnapshot({
14
16
  get: () => {
15
- const cache = context[1];
17
+ const [cache] = context;
16
18
  const selectorValues = utils.getSelectorValues(items);
17
19
  const args = selectorValues.concat(deps || selectorFunc);
18
20
  if (cache && utils.isEqual(args, cache[0])) return cache[1];
19
- const val = selectorFunc(...selectorValues);
20
- context[1] = [args, val];
21
- return val;
21
+ const value = selectorFunc(...selectorValues);
22
+ context[0] = [args, value];
23
+ return value;
22
24
  },
23
- subscribe: context[0]
25
+ subscribe: context[1]
24
26
  });
25
27
  };
26
28
 
@@ -5,9 +5,7 @@ var utils = require('../utils.cjs');
5
5
  const createSelector = ({
6
6
  plugin
7
7
  } = {}) => (...items) => {
8
- const {
9
- length
10
- } = items;
8
+ const length = items.length;
11
9
  const cutoff = typeof items[length - 1] === 'function' ? length - 1 : length - 2;
12
10
  const selectorFunc = items[cutoff];
13
11
  const config = items[cutoff + 1];
@@ -17,9 +15,9 @@ const createSelector = ({
17
15
  get: () => {
18
16
  const args = utils.getSelectorValues(items);
19
17
  if (cache && utils.isEqual(args, cache[0])) return cache[1];
20
- const val = selectorFunc(...args);
21
- cache = [args, val];
22
- return val;
18
+ const value = selectorFunc(...args);
19
+ cache = [args, value];
20
+ return value;
23
21
  },
24
22
  subscribe: utils.createSubscriber(items)
25
23
  };
@@ -7,18 +7,20 @@ const useSelector = (selectorParamFactory, deps) => {
7
7
  const cutoff = items.length - 1;
8
8
  const selectorFunc = items[cutoff];
9
9
  items.length = cutoff;
10
- const [context] = useState(() => [createSubscriber(items)]);
10
+ const [context] = useState(() =>
11
+ // eslint-disable-next-line no-sparse-arrays
12
+ [, createSubscriber(items)]);
11
13
  return useSnapshot({
12
14
  get: () => {
13
- const cache = context[1];
15
+ const [cache] = context;
14
16
  const selectorValues = getSelectorValues(items);
15
17
  const args = selectorValues.concat(deps || selectorFunc);
16
18
  if (cache && isEqual(args, cache[0])) return cache[1];
17
- const val = selectorFunc(...selectorValues);
18
- context[1] = [args, val];
19
- return val;
19
+ const value = selectorFunc(...selectorValues);
20
+ context[0] = [args, value];
21
+ return value;
20
22
  },
21
- subscribe: context[0]
23
+ subscribe: context[1]
22
24
  });
23
25
  };
24
26
 
@@ -3,9 +3,7 @@ import { createSubscriber, getSelectorValues, isEqual } from '../utils.mjs';
3
3
  const createSelector = ({
4
4
  plugin
5
5
  } = {}) => (...items) => {
6
- const {
7
- length
8
- } = items;
6
+ const length = items.length;
9
7
  const cutoff = typeof items[length - 1] === 'function' ? length - 1 : length - 2;
10
8
  const selectorFunc = items[cutoff];
11
9
  const config = items[cutoff + 1];
@@ -15,9 +13,9 @@ const createSelector = ({
15
13
  get: () => {
16
14
  const args = getSelectorValues(items);
17
15
  if (cache && isEqual(args, cache[0])) return cache[1];
18
- const val = selectorFunc(...args);
19
- cache = [args, val];
20
- return val;
16
+ const value = selectorFunc(...args);
17
+ cache = [args, value];
18
+ return value;
21
19
  },
22
20
  subscribe: createSubscriber(items)
23
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactish-state",
3
- "version": "1.2.1-alpha.1",
3
+ "version": "1.2.1-alpha.2",
4
4
  "description": "Simple, decentralized (atomic) state management for React.",
5
5
  "author": "Zheng Song",
6
6
  "license": "MIT",