@dynamic-labs/store 4.9.7 → 4.9.9
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/CHANGELOG.md +19 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +3 -3
- package/src/lib/subscribeWithSelector/subscribeWithSelector.cjs +19 -5
- package/src/lib/subscribeWithSelector/subscribeWithSelector.d.ts +10 -4
- package/src/lib/subscribeWithSelector/subscribeWithSelector.js +19 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.9.9](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.8...v4.9.9) (2025-03-26)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* **global-wallet-client:** properly clean up the popup state when popup is closed ([#8379](https://github.com/dynamic-labs/dynamic-auth/issues/8379)) ([782963f](https://github.com/dynamic-labs/dynamic-auth/commit/782963f87fcb2658b921ff6cc6f22c63be9714fb))
|
|
8
|
+
* hanging promises when a starknet wallet is connected but locked ([#8376](https://github.com/dynamic-labs/dynamic-auth/issues/8376)) ([a753939](https://github.com/dynamic-labs/dynamic-auth/commit/a7539395d4653be49f000ae51d15347a176b5b6c))
|
|
9
|
+
* token balance list should respect sort from backend ([#8383](https://github.com/dynamic-labs/dynamic-auth/issues/8383)) ([1c3bef4](https://github.com/dynamic-labs/dynamic-auth/commit/1c3bef47dbfd319e2444368a4a503b0839b5ad4b))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* add message auth code to global wallet ([#8354](https://github.com/dynamic-labs/dynamic-auth/issues/8354)) ([c847bf8](https://github.com/dynamic-labs/dynamic-auth/commit/c847bf8d66db54534348622255997f30f4309542))
|
|
13
|
+
|
|
14
|
+
### [4.9.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.7...v4.9.8) (2025-03-24)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* unlink wallets when using 7702 account ([#8367](https://github.com/dynamic-labs/dynamic-auth/issues/8367)) ([f5acf05](https://github.com/dynamic-labs/dynamic-auth/commit/f5acf05ef31b8f411f3b0cd0e90e919e71f4ad50))
|
|
20
|
+
|
|
2
21
|
### [4.9.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.6...v4.9.7) (2025-03-21)
|
|
3
22
|
|
|
4
23
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/store",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.9",
|
|
4
4
|
"description": "Store ",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"./package.json": "./package.json"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/assert-package-version": "4.9.
|
|
22
|
-
"@dynamic-labs/logger": "4.9.
|
|
21
|
+
"@dynamic-labs/assert-package-version": "4.9.9",
|
|
22
|
+
"@dynamic-labs/logger": "4.9.9"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {}
|
|
25
25
|
}
|
|
@@ -7,6 +7,8 @@ var shallow = require('../shallow/shallow.cjs');
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Subscribes to a specific slice of the store state and invokes a callback whenever the slice changes.
|
|
10
|
+
* The callback can optionally return a cleanup function that will be called before the next callback invocation
|
|
11
|
+
* or when unsubscribing.
|
|
10
12
|
* @template TStore - The type of the store.
|
|
11
13
|
* @template StateSlice - The type of the selected slice of the store state.
|
|
12
14
|
* @param {StoreApi<TStore>} store - The store object.
|
|
@@ -15,24 +17,36 @@ var shallow = require('../shallow/shallow.cjs');
|
|
|
15
17
|
* @example
|
|
16
18
|
* const store = createStore<{ counter: number; }>(() => ({ counter: 0 }));
|
|
17
19
|
* const subscribeToCounter = subscribeWithSelector(
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
+
* store,
|
|
21
|
+
* (state) => state.counter,
|
|
20
22
|
* );
|
|
21
23
|
* const unsubscribe = subscribeToCounter((counter) => {
|
|
22
24
|
* console.log('Counter changed:', counter);
|
|
25
|
+
* // Optionally return a cleanup function
|
|
26
|
+
* return () => {
|
|
27
|
+
* console.log('Cleaning up before next counter change');
|
|
28
|
+
* };
|
|
23
29
|
* });
|
|
24
|
-
* // To unsubscribe, call the returned function
|
|
30
|
+
* // To unsubscribe and run the cleanup function, call the returned function
|
|
25
31
|
* unsubscribe();
|
|
26
32
|
*/
|
|
27
33
|
const subscribeWithSelector = (store, selector) => (callback) => {
|
|
28
34
|
let lastSlice = selector(store.getState());
|
|
29
|
-
|
|
35
|
+
let unsubscribeCallback = undefined;
|
|
36
|
+
// Fire callback immediately with initial state
|
|
37
|
+
unsubscribeCallback = callback(lastSlice);
|
|
38
|
+
const unsubscribe = store.subscribe((state) => {
|
|
30
39
|
const nextSlice = selector(state);
|
|
31
40
|
if (shallow.shallow(lastSlice, nextSlice) === false) {
|
|
32
41
|
lastSlice = nextSlice;
|
|
33
|
-
|
|
42
|
+
unsubscribeCallback === null || unsubscribeCallback === void 0 ? void 0 : unsubscribeCallback();
|
|
43
|
+
unsubscribeCallback = callback(nextSlice);
|
|
34
44
|
}
|
|
35
45
|
});
|
|
46
|
+
return () => {
|
|
47
|
+
unsubscribeCallback === null || unsubscribeCallback === void 0 ? void 0 : unsubscribeCallback();
|
|
48
|
+
unsubscribe();
|
|
49
|
+
};
|
|
36
50
|
};
|
|
37
51
|
|
|
38
52
|
exports.subscribeWithSelector = subscribeWithSelector;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { StoreApi } from '../types';
|
|
2
|
-
type SliceSubscription<StateSlice> = (subscription: (state: StateSlice) =>
|
|
2
|
+
type SliceSubscription<StateSlice> = (subscription: (state: StateSlice) => VoidFunction | void) => VoidFunction;
|
|
3
3
|
/**
|
|
4
4
|
* Subscribes to a specific slice of the store state and invokes a callback whenever the slice changes.
|
|
5
|
+
* The callback can optionally return a cleanup function that will be called before the next callback invocation
|
|
6
|
+
* or when unsubscribing.
|
|
5
7
|
* @template TStore - The type of the store.
|
|
6
8
|
* @template StateSlice - The type of the selected slice of the store state.
|
|
7
9
|
* @param {StoreApi<TStore>} store - The store object.
|
|
@@ -10,13 +12,17 @@ type SliceSubscription<StateSlice> = (subscription: (state: StateSlice) => void)
|
|
|
10
12
|
* @example
|
|
11
13
|
* const store = createStore<{ counter: number; }>(() => ({ counter: 0 }));
|
|
12
14
|
* const subscribeToCounter = subscribeWithSelector(
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* store,
|
|
16
|
+
* (state) => state.counter,
|
|
15
17
|
* );
|
|
16
18
|
* const unsubscribe = subscribeToCounter((counter) => {
|
|
17
19
|
* console.log('Counter changed:', counter);
|
|
20
|
+
* // Optionally return a cleanup function
|
|
21
|
+
* return () => {
|
|
22
|
+
* console.log('Cleaning up before next counter change');
|
|
23
|
+
* };
|
|
18
24
|
* });
|
|
19
|
-
* // To unsubscribe, call the returned function
|
|
25
|
+
* // To unsubscribe and run the cleanup function, call the returned function
|
|
20
26
|
* unsubscribe();
|
|
21
27
|
*/
|
|
22
28
|
export declare const subscribeWithSelector: <TStore extends object, StateSlice>(store: StoreApi<TStore>, selector: (state: TStore) => StateSlice) => SliceSubscription<StateSlice>;
|
|
@@ -3,6 +3,8 @@ import { shallow } from '../shallow/shallow.js';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Subscribes to a specific slice of the store state and invokes a callback whenever the slice changes.
|
|
6
|
+
* The callback can optionally return a cleanup function that will be called before the next callback invocation
|
|
7
|
+
* or when unsubscribing.
|
|
6
8
|
* @template TStore - The type of the store.
|
|
7
9
|
* @template StateSlice - The type of the selected slice of the store state.
|
|
8
10
|
* @param {StoreApi<TStore>} store - The store object.
|
|
@@ -11,24 +13,36 @@ import { shallow } from '../shallow/shallow.js';
|
|
|
11
13
|
* @example
|
|
12
14
|
* const store = createStore<{ counter: number; }>(() => ({ counter: 0 }));
|
|
13
15
|
* const subscribeToCounter = subscribeWithSelector(
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* store,
|
|
17
|
+
* (state) => state.counter,
|
|
16
18
|
* );
|
|
17
19
|
* const unsubscribe = subscribeToCounter((counter) => {
|
|
18
20
|
* console.log('Counter changed:', counter);
|
|
21
|
+
* // Optionally return a cleanup function
|
|
22
|
+
* return () => {
|
|
23
|
+
* console.log('Cleaning up before next counter change');
|
|
24
|
+
* };
|
|
19
25
|
* });
|
|
20
|
-
* // To unsubscribe, call the returned function
|
|
26
|
+
* // To unsubscribe and run the cleanup function, call the returned function
|
|
21
27
|
* unsubscribe();
|
|
22
28
|
*/
|
|
23
29
|
const subscribeWithSelector = (store, selector) => (callback) => {
|
|
24
30
|
let lastSlice = selector(store.getState());
|
|
25
|
-
|
|
31
|
+
let unsubscribeCallback = undefined;
|
|
32
|
+
// Fire callback immediately with initial state
|
|
33
|
+
unsubscribeCallback = callback(lastSlice);
|
|
34
|
+
const unsubscribe = store.subscribe((state) => {
|
|
26
35
|
const nextSlice = selector(state);
|
|
27
36
|
if (shallow(lastSlice, nextSlice) === false) {
|
|
28
37
|
lastSlice = nextSlice;
|
|
29
|
-
|
|
38
|
+
unsubscribeCallback === null || unsubscribeCallback === void 0 ? void 0 : unsubscribeCallback();
|
|
39
|
+
unsubscribeCallback = callback(nextSlice);
|
|
30
40
|
}
|
|
31
41
|
});
|
|
42
|
+
return () => {
|
|
43
|
+
unsubscribeCallback === null || unsubscribeCallback === void 0 ? void 0 : unsubscribeCallback();
|
|
44
|
+
unsubscribe();
|
|
45
|
+
};
|
|
32
46
|
};
|
|
33
47
|
|
|
34
48
|
export { subscribeWithSelector };
|