Skip to content

Commit e56eac1

Browse files
committed
Remove NODE_ENV branching
1 parent a394eb2 commit e56eac1

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

packages/api/src/hooks/useActivities.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,57 @@ declare const process: {
1010
};
1111
};
1212

13-
export default function useActivities(): readonly [readonly WebChatActivity[]] {
14-
const activitiesFromGraphState = useOrderedActivities();
13+
function useActivitiesForProduction(): readonly [readonly WebChatActivity[]] {
14+
return useOrderedActivities();
15+
}
16+
17+
function useActivitiesForDevelopment(): readonly [readonly WebChatActivity[]] {
18+
const activitiesFromGraphState = useActivitiesForProduction();
1519

1620
// Checks if store changed.
1721
const store = useStore();
1822
const prevStore = usePrevious(store);
1923

20-
// ASSERTION: Before we fully migrate to graph, make sure graph and Redux are the same.
21-
if (process.env.NODE_ENV !== 'production') {
22-
const [activitiesFromGraph] = activitiesFromGraphState;
24+
const [activitiesFromGraph] = activitiesFromGraphState;
25+
26+
const activitiesFromRedux = useSelector(({ activities }) => activities);
2327

24-
// Assert based on NODE_ENV.
25-
// eslint-disable-next-line react-hooks/rules-of-hooks
26-
const activitiesFromRedux = useSelector(({ activities }) => activities);
28+
// If store changed, skip one assertion turn.
29+
// This is because <GraphProvider> is using `useState()` for propagating changes.
30+
// It is always one render behind if `store` changed.
31+
if (prevStore === store) {
32+
if (activitiesFromGraph.length !== activitiesFromRedux.length) {
33+
throw new Error(
34+
`botframework-webchat-internal: Activities from graph and Redux are of different size (graph has ${activitiesFromGraph.length} activities, Redux has ${activitiesFromRedux.length} activities)`,
35+
{
36+
cause: {
37+
activitiesFromGraph,
38+
activitiesFromRedux
39+
}
40+
}
41+
);
42+
}
2743

28-
// If store changed, skip one assertion turn.
29-
// This is because <GraphProvider> is using `useState()` for propagating changes.
30-
// It is always one render behind if `store` changed.
31-
if (prevStore === store) {
32-
if (activitiesFromGraph.length !== activitiesFromRedux.length) {
44+
for (let index = 0; index < activitiesFromGraph.length; index++) {
45+
if (!Object.is(activitiesFromGraph.at(index), activitiesFromRedux.at(index))) {
3346
throw new Error(
34-
`botframework-webchat-internal: Activities from graph and Redux are of different size (graph has ${activitiesFromGraph.length} activities, Redux has ${activitiesFromRedux.length} activities)`,
47+
`botframework-webchat-internal: Activities from graph and Redux are of different at index ${index}`,
3548
{
3649
cause: {
3750
activitiesFromGraph,
38-
activitiesFromRedux
51+
activitiesFromRedux,
52+
index
3953
}
4054
}
4155
);
4256
}
43-
44-
for (let index = 0; index < activitiesFromGraph.length; index++) {
45-
if (!Object.is(activitiesFromGraph.at(index), activitiesFromRedux.at(index))) {
46-
throw new Error(
47-
`botframework-webchat-internal: Activities from graph and Redux are of different at index ${index}`,
48-
{
49-
cause: {
50-
activitiesFromGraph,
51-
activitiesFromRedux,
52-
index
53-
}
54-
}
55-
);
56-
}
57-
}
5857
}
5958
}
6059

6160
return activitiesFromGraphState;
6261
}
62+
63+
const useActivities: () => readonly [readonly WebChatActivity[]] =
64+
process.env.NODE_ENV === 'production' ? useActivitiesForProduction : useActivitiesForDevelopment;
65+
66+
export default useActivities;

0 commit comments

Comments
 (0)