-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major(nova-react-test-utils): rewrite EventingProvider to be Eventing…
…Interceptor (#131) * use interceptor instead of eventing * Change files * fix stories --------- Co-authored-by: Stanislaw Wilczynski <[email protected]>
- Loading branch information
1 parent
a8ccff2
commit 6dfd060
Showing
10 changed files
with
96 additions
and
66 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@nova-examples-c53a2cfc-e80c-4b74-9fb5-7d5f0817ff39.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "use interceptor instead of eventing", | ||
"packageName": "@nova/examples", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@nova-react-test-utils-8f99fd8f-e132-4ff4-8ae4-0ef1480bd148.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "major", | ||
"comment": "rewrite evetingprovider to eventinginterceptor", | ||
"packageName": "@nova/react-test-utils", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/nova-react-test-utils/src/shared/eventing-interceptor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { NovaEventingInterceptor } from "@nova/react"; | ||
import type { EventWrapper, NovaEvent, Source } from "@nova/types"; | ||
import * as React from "react"; | ||
|
||
type EventCreatorMap = Record<string, (...args: any[]) => NovaEvent<unknown>>; | ||
type EventMap<T extends EventCreatorMap> = { | ||
[Property in keyof T]?: (eventWrapper: { | ||
event: ReturnType<T[Property]>; | ||
source: Source; | ||
}) => Promise<undefined | EventWrapper>; | ||
}; | ||
|
||
export const EventingInterceptor = <T extends EventCreatorMap>({ | ||
eventMap, | ||
children, | ||
}: { | ||
eventMap: EventMap<T>; | ||
children: React.ReactNode; | ||
}) => { | ||
const interceptor = (eventWrapper: EventWrapper) => { | ||
const eventType = eventWrapper.event.type; | ||
const customEventHandler = eventMap[eventType]; | ||
if (customEventHandler) { | ||
return customEventHandler( | ||
// As the key was in the map we now the type is correct | ||
eventWrapper as unknown as { | ||
event: ReturnType<T[keyof T]>; | ||
source: Source; | ||
}, | ||
); | ||
} else { | ||
return Promise.resolve(eventWrapper); | ||
} | ||
}; | ||
|
||
return ( | ||
<NovaEventingInterceptor interceptor={interceptor}> | ||
{children} | ||
</NovaEventingInterceptor> | ||
); | ||
}; |
40 changes: 0 additions & 40 deletions
40
packages/nova-react-test-utils/src/shared/eventing-provider.tsx
This file was deleted.
Oops, something went wrong.