@pushwoosh/spa-context 1.1.5 → 1.1.7
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/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +1 -1
- package/types.d.ts +1 -0
- package/useMemoryKey.d.ts +2 -0
- package/useMemoryKey.js +6 -2
package/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SimpleEventEmitter } from './SimpleEventEmitter';
|
|
2
2
|
import type { SPAContextType } from './types';
|
|
3
3
|
import { UniversalKeyValueStore } from './UniversalKeyValueStore';
|
|
4
|
-
import { useMemoryKey } from './useMemoryKey';
|
|
4
|
+
import { useMemoryKey, useMemoryKeySlim } from './useMemoryKey';
|
|
5
5
|
import { useSession } from './useSession';
|
|
6
6
|
import { useSPAContext } from './useSPAContext';
|
|
7
7
|
export type { SPAContextType };
|
|
8
|
-
export { useSPAContext, useSession, useMemoryKey, SimpleEventEmitter, UniversalKeyValueStore, };
|
|
8
|
+
export { useSPAContext, useSession, useMemoryKey, useMemoryKeySlim, SimpleEventEmitter, UniversalKeyValueStore, };
|
|
9
9
|
export declare const SPAContextProvider: import("react").Provider<SPAContextType | undefined>;
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SPAContext } from './context';
|
|
2
2
|
import { SimpleEventEmitter } from './SimpleEventEmitter';
|
|
3
3
|
import { UniversalKeyValueStore } from './UniversalKeyValueStore';
|
|
4
|
-
import { useMemoryKey } from './useMemoryKey';
|
|
4
|
+
import { useMemoryKey, useMemoryKeySlim } from './useMemoryKey';
|
|
5
5
|
import { useSession } from './useSession';
|
|
6
6
|
import { useSPAContext } from './useSPAContext';
|
|
7
|
-
export { useSPAContext, useSession, useMemoryKey, SimpleEventEmitter, UniversalKeyValueStore };
|
|
7
|
+
export { useSPAContext, useSession, useMemoryKey, useMemoryKeySlim, SimpleEventEmitter, UniversalKeyValueStore };
|
|
8
8
|
export const SPAContextProvider = SPAContext.Provider;
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
package/useMemoryKey.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type SPAContextType } from './types';
|
|
1
2
|
type Initializer<V> = V | (() => V);
|
|
3
|
+
export declare function useMemoryKeySlim<V = unknown>(spaContext: SPAContextType, key: IDBValidKey, init: Initializer<V>): [V, (value: V) => void];
|
|
2
4
|
export declare function useMemoryKey<V = unknown>(key: IDBValidKey, init: Initializer<V>): [V, (value: V) => void];
|
|
3
5
|
export {};
|
package/useMemoryKey.js
CHANGED
|
@@ -3,10 +3,10 @@ import { useSPAContext } from './useSPAContext';
|
|
|
3
3
|
function resolveInit(init) {
|
|
4
4
|
return typeof init === 'function' ? init() : init;
|
|
5
5
|
}
|
|
6
|
-
export function
|
|
6
|
+
export function useMemoryKeySlim(spaContext, key, init) {
|
|
7
7
|
const {
|
|
8
8
|
keyValueStorage
|
|
9
|
-
} =
|
|
9
|
+
} = spaContext;
|
|
10
10
|
const [state, setState] = useState(() => {
|
|
11
11
|
const stored = keyValueStorage.getMemory(key);
|
|
12
12
|
return stored !== undefined ? stored : resolveInit(init);
|
|
@@ -22,4 +22,8 @@ export function useMemoryKey(key, init) {
|
|
|
22
22
|
keyValueStorage.set(key, value);
|
|
23
23
|
}, [keyValueStorage, key]);
|
|
24
24
|
return [state, setValue];
|
|
25
|
+
}
|
|
26
|
+
export function useMemoryKey(key, init) {
|
|
27
|
+
const spaContext = useSPAContext();
|
|
28
|
+
return useMemoryKeySlim(spaContext, key, init);
|
|
25
29
|
}
|