@knocklabs/react-core 0.5.0-rc.0 → 0.5.0-rc.2.0
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 +2 -2
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js +1 -1
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js.map +1 -1
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs +11 -7
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs.map +1 -1
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +15 -9
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/modules/feed/hooks/useNotificationStore.ts +32 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("zustand");function n(e,t){const o=i.useStore(e.store);return u=>{const r=u??t;return r?r(o):o}}function s(e,t){return n(e,t)}exports.default=s;exports.useCreateNotificationStore=n;
|
|
2
2
|
//# sourceMappingURL=useNotificationStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotificationStore.js","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\n\n// A hook designed to create a `UseBoundStore` instance.\n//
|
|
1
|
+
{"version":3,"file":"useNotificationStore.js","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\n// A hook designed to create a `UseBoundStore` instance.\n// https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\nfunction useCreateNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector: (state: FeedStoreState) => U,\n): U;\n/**\n * Access a Bounded Store instance\n * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore\n * We'll favor the the one passed later outside of useCreateNotificationStore instantiation\n */\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector?: (state: FeedStoreState) => U,\n) {\n const store = useStore(feedClient.store);\n\n return (selector?: (state: FeedStoreState) => U) => {\n const innerSelector = selector ?? externalSelector;\n return innerSelector ? innerSelector(store) : store;\n };\n}\n\n/**\n * A hook used to access content within the notification store.\n *\n * A selector can be used to access a subset of the store state.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient, (state) => ({\n * items: state.items,\n * metadata: state.metadata,\n * }));\n * ```\n */\nfunction useNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector: (state: FeedStoreState) => T,\n): T;\nfunction useNotificationStore<T, U = T>(\n feedClient: Feed,\n selector?: (state: FeedStoreState) => U,\n) {\n return useCreateNotificationStore(feedClient, selector!);\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","externalSelector","store","useStore","selector","innerSelector","useNotificationStore"],"mappings":"uIAiBA,SAASA,EACPC,EACAC,EACA,CACMC,MAAAA,EAAQC,EAAAA,SAASH,EAAWE,KAAK,EAEvC,OAAQE,GAA4C,CAClD,MAAMC,EAAgBD,GAAYH,EAC3BI,OAAAA,EAAgBA,EAAcH,CAAK,EAAIA,CAChD,CACF,CAuBA,SAASI,EACPN,EACAI,EACA,CACOL,OAAAA,EAA2BC,EAAYI,CAAS,CACzD"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
return t.store;
|
|
3
|
-
}
|
|
1
|
+
import { useStore as i } from "zustand";
|
|
4
2
|
function u(t, e) {
|
|
5
|
-
const o =
|
|
6
|
-
return
|
|
3
|
+
const o = i(t.store);
|
|
4
|
+
return (n) => {
|
|
5
|
+
const r = n ?? e;
|
|
6
|
+
return r ? r(o) : o;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function c(t, e) {
|
|
10
|
+
return u(t, e);
|
|
7
11
|
}
|
|
8
12
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
c as default,
|
|
14
|
+
u as useCreateNotificationStore
|
|
11
15
|
};
|
|
12
16
|
//# sourceMappingURL=useNotificationStore.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotificationStore.mjs","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\n\n// A hook designed to create a `UseBoundStore` instance.\n//
|
|
1
|
+
{"version":3,"file":"useNotificationStore.mjs","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\n// A hook designed to create a `UseBoundStore` instance.\n// https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\nfunction useCreateNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector: (state: FeedStoreState) => U,\n): U;\n/**\n * Access a Bounded Store instance\n * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore\n * We'll favor the the one passed later outside of useCreateNotificationStore instantiation\n */\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector?: (state: FeedStoreState) => U,\n) {\n const store = useStore(feedClient.store);\n\n return (selector?: (state: FeedStoreState) => U) => {\n const innerSelector = selector ?? externalSelector;\n return innerSelector ? innerSelector(store) : store;\n };\n}\n\n/**\n * A hook used to access content within the notification store.\n *\n * A selector can be used to access a subset of the store state.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient, (state) => ({\n * items: state.items,\n * metadata: state.metadata,\n * }));\n * ```\n */\nfunction useNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector: (state: FeedStoreState) => T,\n): T;\nfunction useNotificationStore<T, U = T>(\n feedClient: Feed,\n selector?: (state: FeedStoreState) => U,\n) {\n return useCreateNotificationStore(feedClient, selector!);\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","externalSelector","store","useStore","selector","innerSelector","useNotificationStore"],"mappings":";AAiBA,SAASA,EACPC,GACAC,GACA;AACMC,QAAAA,IAAQC,EAASH,EAAWE,KAAK;AAEvC,SAAO,CAACE,MAA4C;AAClD,UAAMC,IAAgBD,KAAYH;AAC3BI,WAAAA,IAAgBA,EAAcH,CAAK,IAAIA;AAAAA,EAChD;AACF;AAuBA,SAASI,EACPN,GACAI,GACA;AACOL,SAAAA,EAA2BC,GAAYI,CAAS;AACzD;"}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { Feed, FeedStoreState } from '@knocklabs/client';
|
|
2
|
-
|
|
2
|
+
import { StoreApi, UseBoundStore } from 'zustand';
|
|
3
|
+
declare function useCreateNotificationStore(feedClient: Feed): UseBoundStore<StoreApi<FeedStoreState>>;
|
|
4
|
+
declare function useCreateNotificationStore<T, U = T>(feedClient: Feed, externalSelector: (state: FeedStoreState) => U): U;
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
5
|
-
* the return type will be the type returned by the selector.
|
|
6
|
+
* A hook used to access content within the notification store.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
* return type of the selector.
|
|
8
|
+
* A selector can be used to access a subset of the store state.
|
|
9
9
|
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const { items, metadata } = useNotificationStore(feedClient, (state) => ({
|
|
14
|
+
* items: state.items,
|
|
15
|
+
* metadata: state.metadata,
|
|
16
|
+
* }));
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare function useNotificationStore(feedClient: Feed): FeedStoreState;
|
|
14
|
-
declare function useNotificationStore<T>(feedClient: Feed, selector: FeedStoreStateSelector<T>): T;
|
|
19
|
+
declare function useNotificationStore(feedClient: Feed): UseBoundStore<StoreApi<FeedStoreState>>;
|
|
20
|
+
declare function useNotificationStore<T>(feedClient: Feed, selector: (state: FeedStoreState) => T): T;
|
|
15
21
|
export { useCreateNotificationStore };
|
|
16
22
|
export default useNotificationStore;
|
|
17
23
|
//# sourceMappingURL=useNotificationStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotificationStore.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"useNotificationStore.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAY,MAAM,SAAS,CAAC;AAItE,iBAAS,0BAA0B,CACjC,UAAU,EAAE,IAAI,GACf,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;AAC3C,iBAAS,0BAA0B,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAC1C,UAAU,EAAE,IAAI,EAChB,gBAAgB,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,GAC7C,CAAC,CAAC;AAkBL;;;;;;;;;;;;;GAaG;AACH,iBAAS,oBAAoB,CAC3B,UAAU,EAAE,IAAI,GACf,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;AAC3C,iBAAS,oBAAoB,CAAC,CAAC,EAC7B,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,GACrC,CAAC,CAAC;AAQL,OAAO,EAAE,0BAA0B,EAAE,CAAC;AACtC,eAAe,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@knocklabs/react-core",
|
|
3
3
|
"description": "A set of React components to build notification experiences powered by Knock",
|
|
4
4
|
"author": "@knocklabs",
|
|
5
|
-
"version": "0.5.0-rc.0",
|
|
5
|
+
"version": "0.5.0-rc.2.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@knocklabs/client": "^0.12.0-rc.0",
|
|
52
|
+
"@knocklabs/client": "^0.12.0-rc.2.0",
|
|
53
53
|
"date-fns": "^4.0.0",
|
|
54
54
|
"swr": "^2.3.2",
|
|
55
55
|
"zustand": "^4.5.6"
|
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
import { Feed, type FeedStoreState } from "@knocklabs/client";
|
|
2
|
+
import { type StoreApi, type UseBoundStore, useStore } from "zustand";
|
|
2
3
|
|
|
3
4
|
// A hook designed to create a `UseBoundStore` instance.
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
// https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
|
|
6
|
+
function useCreateNotificationStore(
|
|
7
|
+
feedClient: Feed,
|
|
8
|
+
): UseBoundStore<StoreApi<FeedStoreState>>;
|
|
9
|
+
function useCreateNotificationStore<T, U = T>(
|
|
10
|
+
feedClient: Feed,
|
|
11
|
+
externalSelector: (state: FeedStoreState) => U,
|
|
12
|
+
): U;
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* This is important because the store state type is not always the same as the
|
|
16
|
-
* return type of the selector.
|
|
17
|
-
*
|
|
14
|
+
* Access a Bounded Store instance
|
|
15
|
+
* Allow passing a selector down from useCreateNotificationStore OR useNotificationStore
|
|
16
|
+
* We'll favor the the one passed later outside of useCreateNotificationStore instantiation
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
type StateSelector<T, U> = (state: T) => U;
|
|
21
|
-
type FeedStoreStateSelector<T> = StateSelector<FeedStoreState, T>;
|
|
22
|
-
|
|
23
|
-
// Function overload for when no selector is provided
|
|
24
|
-
function useNotificationStore(feedClient: Feed): FeedStoreState;
|
|
25
|
-
|
|
26
|
-
// Function overload for when a selector is provided
|
|
27
|
-
function useNotificationStore<T>(
|
|
18
|
+
function useCreateNotificationStore<T, U = T>(
|
|
28
19
|
feedClient: Feed,
|
|
29
|
-
|
|
30
|
-
)
|
|
20
|
+
externalSelector?: (state: FeedStoreState) => U,
|
|
21
|
+
) {
|
|
22
|
+
const store = useStore(feedClient.store);
|
|
23
|
+
|
|
24
|
+
return (selector?: (state: FeedStoreState) => U) => {
|
|
25
|
+
const innerSelector = selector ?? externalSelector;
|
|
26
|
+
return innerSelector ? innerSelector(store) : store;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* A hook used to access content within the notification store.
|
|
@@ -43,13 +41,18 @@ function useNotificationStore<T>(
|
|
|
43
41
|
* }));
|
|
44
42
|
* ```
|
|
45
43
|
*/
|
|
44
|
+
function useNotificationStore(
|
|
45
|
+
feedClient: Feed,
|
|
46
|
+
): UseBoundStore<StoreApi<FeedStoreState>>;
|
|
46
47
|
function useNotificationStore<T>(
|
|
47
48
|
feedClient: Feed,
|
|
48
|
-
selector
|
|
49
|
-
): T
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
selector: (state: FeedStoreState) => T,
|
|
50
|
+
): T;
|
|
51
|
+
function useNotificationStore<T, U = T>(
|
|
52
|
+
feedClient: Feed,
|
|
53
|
+
selector?: (state: FeedStoreState) => U,
|
|
54
|
+
) {
|
|
55
|
+
return useCreateNotificationStore(feedClient, selector!);
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
export { useCreateNotificationStore };
|