extra-react-store 0.1.5 → 0.1.6
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.
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ function createStoreContext<State>(): StoreContext<State>
|
|
|
84
84
|
function useSelector<State, Value>(
|
|
85
85
|
context: StoreContext<State>
|
|
86
86
|
, selector: (state: State) => Value
|
|
87
|
-
, isEqual: (a: Value, b: Value) => boolean =
|
|
87
|
+
, isEqual: (a: Value, b: Value) => boolean = isReferenceEqual
|
|
88
88
|
): Value
|
|
89
89
|
```
|
|
90
90
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useContext } from 'react';
|
|
2
2
|
import { produce } from 'immer';
|
|
3
|
-
import { go
|
|
3
|
+
import { go } from '@blackglory/prelude';
|
|
4
|
+
import { isFunction } from 'extra-utils';
|
|
4
5
|
export function usePartialUpdater(context, extractPartialState, mergePartialState) {
|
|
5
6
|
const store = useContext(context);
|
|
6
7
|
const updater = useCallback(newPartialStateOrFn => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-partial-updater.js","sourceRoot":"","sources":["../src/use-partial-updater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,EAAS,OAAO,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"use-partial-updater.js","sourceRoot":"","sources":["../src/use-partial-updater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAC/C,OAAO,EAAS,OAAO,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,UAAU,iBAAiB,CAC/B,OAA4B,EAC5B,mBAAmD,EACnD,iBAAsE;IAEtE,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IAEjC,MAAM,OAAO,GAA0B,WAAW,CAAC,mBAAmB,CAAC,EAAE;QACvE,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAA;QAEjC,MAAM,eAAe,GAAiB,EAAE,CAAC,GAAG,EAAE;YAC5C,IAAI,UAAU,CAAC,mBAAmB,CAAC,EAAE;gBACnC,MAAM,EAAE,GAAG,mBAAmB,CAAA;gBAC9B,MAAM,eAAe,GAAG,OAAO,CAC7B,mBAAmB,CAAC,QAAQ,CAAC,EAE7B,EAAE,CACH,CAAA;gBACD,OAAO,eAAe,CAAA;aACvB;iBAAM;gBACL,MAAM,eAAe,GAAG,mBAAmB,CAAA;gBAC3C,OAAO,eAAe,CAAA;aACvB;QACH,CAAC,CAAC,CAAA;QAEF,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAA;IAC9D,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,CAAC,CAAA;IAEnD,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/lib/use-selector.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useContext, useEffect } from 'react';
|
|
2
|
-
|
|
2
|
+
import { isReferenceEqual } from 'extra-utils';
|
|
3
|
+
export function useSelector(context, selector, isEqual = isReferenceEqual) {
|
|
3
4
|
const store = useContext(context);
|
|
4
5
|
const [[value], setBox] = useState(() => [selector(store.getState())]);
|
|
5
6
|
useEffect(() => {
|
package/lib/use-selector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-selector.js","sourceRoot":"","sources":["../src/use-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"use-selector.js","sourceRoot":"","sources":["../src/use-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,UAAU,WAAW,CACzB,OAA4B,EAC5B,QAAiC,EACjC,UAA2C,gBAAgB;IAE3D,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IACjC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAA;IAEtE,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YAC7B,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;YAEhC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;gBAC7B,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;aACnB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IAEpC,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-react-store",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@blackglory/prelude": "^0.3.3",
|
|
65
|
-
"@blackglory/structures": "^0.13.4"
|
|
65
|
+
"@blackglory/structures": "^0.13.4",
|
|
66
|
+
"extra-utils": "^5.4.0"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
69
|
"immer": "^10.0.2",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useContext } from 'react'
|
|
2
2
|
import { Draft, produce } from 'immer'
|
|
3
|
-
import { go
|
|
3
|
+
import { go } from '@blackglory/prelude'
|
|
4
|
+
import { isFunction } from 'extra-utils'
|
|
4
5
|
import { StoreContext, Updater } from './types.js'
|
|
5
6
|
|
|
6
7
|
export function usePartialUpdater<State, PartialState>(
|
package/src/use-selector.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useState, useContext, useEffect } from 'react'
|
|
2
2
|
import { StoreContext } from './types.js'
|
|
3
|
+
import { isReferenceEqual } from 'extra-utils'
|
|
3
4
|
|
|
4
5
|
export function useSelector<State, Value>(
|
|
5
6
|
context: StoreContext<State>
|
|
6
7
|
, selector: (state: State) => Value
|
|
7
|
-
, isEqual: (a: Value, b: Value) => boolean =
|
|
8
|
+
, isEqual: (a: Value, b: Value) => boolean = isReferenceEqual
|
|
8
9
|
): Value {
|
|
9
10
|
const store = useContext(context)
|
|
10
11
|
const [[value], setBox] = useState(() => [selector(store.getState())])
|