@knocklabs/react-core 0.4.0 → 0.5.0-rc.1.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 +11 -0
- package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useStableOptions.js +1 -1
- package/dist/cjs/modules/core/hooks/useStableOptions.js.map +1 -1
- package/dist/cjs/modules/core/utils.js.map +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useFeedSettings.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js +1 -1
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useNotifications.js.map +1 -1
- package/dist/cjs/modules/i18n/context/KnockI18nProvider.js.map +1 -1
- package/dist/cjs/modules/i18n/hooks/useTranslations.js.map +1 -1
- package/dist/cjs/modules/ms-teams/context/KnockMsTeamsProvider.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useConnectedMsTeamsChannels.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsAuth.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsChannels.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsConnectionStatus.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsTeams.js.map +1 -1
- package/dist/cjs/modules/slack/context/KnockSlackProvider.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useConnectedSlackChannels.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackAuth.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackChannels.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackConnectionStatus.js.map +1 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useStableOptions.mjs +1 -1
- package/dist/esm/modules/core/hooks/useStableOptions.mjs.map +1 -1
- package/dist/esm/modules/core/utils.mjs.map +1 -1
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +1 -1
- package/dist/esm/modules/feed/hooks/useFeedSettings.mjs.map +1 -1
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs +11 -13
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs.map +1 -1
- package/dist/esm/modules/feed/hooks/useNotifications.mjs.map +1 -1
- package/dist/esm/modules/i18n/context/KnockI18nProvider.mjs.map +1 -1
- package/dist/esm/modules/i18n/hooks/useTranslations.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/context/KnockMsTeamsProvider.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useConnectedMsTeamsChannels.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsAuth.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsChannels.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsConnectionStatus.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsTeams.mjs.map +1 -1
- package/dist/esm/modules/slack/context/KnockSlackProvider.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useConnectedSlackChannels.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackChannels.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackConnectionStatus.mjs.map +1 -1
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts +2 -2
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -1
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +19 -3
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/modules/core/hooks/useStableOptions.ts +1 -1
- package/src/modules/feed/context/KnockFeedProvider.tsx +2 -2
- package/src/modules/feed/hooks/useNotificationStore.ts +48 -34
|
@@ -1,44 +1,58 @@
|
|
|
1
|
-
import { Feed, FeedStoreState } from "@knocklabs/client";
|
|
2
|
-
import
|
|
3
|
-
import type { DispatchWithoutAction } from "react";
|
|
4
|
-
import create, { StateSelector } from "zustand";
|
|
1
|
+
import { Feed, type FeedStoreState } from "@knocklabs/client";
|
|
2
|
+
import { type StoreApi, type UseBoundStore, useStore } from "zustand";
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const unsubscribe = feedClient.store.subscribe(rerender);
|
|
26
|
-
|
|
27
|
-
rerender();
|
|
28
|
-
|
|
29
|
-
return unsubscribe;
|
|
30
|
-
}, [feedClient]);
|
|
4
|
+
// A hook designed to create a `UseBoundStore` instance.
|
|
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;
|
|
13
|
+
/**
|
|
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
|
|
17
|
+
*/
|
|
18
|
+
function useCreateNotificationStore<T, U = T>(
|
|
19
|
+
feedClient: Feed,
|
|
20
|
+
externalSelector?: (state: FeedStoreState) => U,
|
|
21
|
+
) {
|
|
22
|
+
const store = useStore(feedClient.store);
|
|
31
23
|
|
|
32
|
-
return
|
|
24
|
+
return (selector?: (state: FeedStoreState) => U) => {
|
|
25
|
+
const innerSelector = selector ?? externalSelector;
|
|
26
|
+
return innerSelector ? innerSelector(store) : store;
|
|
27
|
+
};
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
/**
|
|
31
|
+
* A hook used to access content within the notification store.
|
|
32
|
+
*
|
|
33
|
+
* A selector can be used to access a subset of the store state.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* const { items, metadata } = useNotificationStore(feedClient, (state) => ({
|
|
39
|
+
* items: state.items,
|
|
40
|
+
* metadata: state.metadata,
|
|
41
|
+
* }));
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
36
44
|
function useNotificationStore(
|
|
37
45
|
feedClient: Feed,
|
|
38
|
-
|
|
46
|
+
): UseBoundStore<StoreApi<FeedStoreState>>;
|
|
47
|
+
function useNotificationStore<T>(
|
|
48
|
+
feedClient: Feed,
|
|
49
|
+
selector: (state: FeedStoreState) => T,
|
|
50
|
+
): T;
|
|
51
|
+
function useNotificationStore<T, U = T>(
|
|
52
|
+
feedClient: Feed,
|
|
53
|
+
selector?: (state: FeedStoreState) => U,
|
|
39
54
|
) {
|
|
40
|
-
|
|
41
|
-
return useStore<FeedStoreState>(selector || feedClient.store.getState);
|
|
55
|
+
return useCreateNotificationStore(feedClient, selector!);
|
|
42
56
|
}
|
|
43
57
|
|
|
44
58
|
export { useCreateNotificationStore };
|