Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert to using void as cleanup type for useFacetEffect #128

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/benchmarking/src/listMemoFacet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const ListItem = ({ item }: { item: Facet<Data> }) => {
useFacetEffect(
(health) => {
randomWork(health)
return undefined
},
[],
[health],
Expand All @@ -59,7 +58,6 @@ const ListItem = ({ item }: { item: Facet<Data> }) => {
useFacetEffect(
(name) => {
randomWork(name)
return undefined
},
[],
[name],
Expand All @@ -68,7 +66,6 @@ const ListItem = ({ item }: { item: Facet<Data> }) => {
useFacetEffect(
(name) => {
randomWork(name)
return undefined
},
[],
[name],
Expand All @@ -77,7 +74,6 @@ const ListItem = ({ item }: { item: Facet<Data> }) => {
useFacetEffect(
(name) => {
randomWork(name)
return undefined
},
[],
[name],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ it('should work with uninitialized values', () => {
useFacetEffect(
() => {
handler()
return undefined
},
[handler],
[internalDemoFacet],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ it('triggers the effect when a dependency changes', () => {
useFacetEffect(
(value) => {
callback(`${value} ${dependency}`)
return undefined
},
[dependency],
[demoFacet],
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-facet/core/src/hooks/useFacetEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { cancelScheduledTask, scheduleTask } from '../scheduler'

export const createUseFacetEffect = (useHook: typeof useEffect | typeof useLayoutEffect) => {
return function <Y extends Facet<unknown>[], T extends [...Y]>(
effect: (...args: ExtractFacetValues<T>) => undefined | Cleanup,
effect: (...args: ExtractFacetValues<T>) => void | Cleanup,
dependencies: unknown[],
facets: T,
) {
// eslint-disable-next-line react-hooks/exhaustive-deps
const effectMemoized = useCallback(effect as (...args: unknown[]) => ReturnType<typeof effect>, dependencies)

useHook(() => {
let cleanup: undefined | Cleanup
let cleanup: void | Cleanup

if (facets.length === 1) {
const unsubscribe = facets[0].observe((value) => {
Expand Down
8 changes: 0 additions & 8 deletions packages/@react-facet/core/src/hooks/useFacetMap.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ describe('multiple dependencies', () => {
useFacetEffect(
(value) => {
mock(value.name)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -148,7 +147,6 @@ describe('multiple dependencies', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -191,7 +189,6 @@ describe('multiple dependencies', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -234,7 +231,6 @@ describe('multiple dependencies', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -392,7 +388,6 @@ describe('single dependency', () => {
useFacetEffect(
(value) => {
mock(value.name)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -434,7 +429,6 @@ describe('single dependency', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -476,7 +470,6 @@ describe('single dependency', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -518,7 +511,6 @@ describe('single dependency', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down
8 changes: 0 additions & 8 deletions packages/@react-facet/core/src/hooks/useFacetMemo.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ describe('multiple dependencies', () => {
useFacetEffect(
(value) => {
mock(value.name)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -148,7 +147,6 @@ describe('multiple dependencies', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -191,7 +189,6 @@ describe('multiple dependencies', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -234,7 +231,6 @@ describe('multiple dependencies', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -392,7 +388,6 @@ describe('single dependency', () => {
useFacetEffect(
(value) => {
mock(value.name)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -434,7 +429,6 @@ describe('single dependency', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -476,7 +470,6 @@ describe('single dependency', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down Expand Up @@ -518,7 +511,6 @@ describe('single dependency', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[adaptValue],
Expand Down
1 change: 0 additions & 1 deletion packages/@react-facet/core/src/hooks/useFacetRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function useFacetRef<T>(facet: Facet<T>, defaultValue?: T): MutableRefObj
useFacetEffect(
(value) => {
ref.current = value
return undefined
},
[],
[facet],
Expand Down
4 changes: 0 additions & 4 deletions packages/@react-facet/core/src/hooks/useFacetWrap.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ it('wraps a value, updating the facet when it changes', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[facetifiedValue],
Expand All @@ -39,7 +38,6 @@ it('wraps a value, with the default equality check (preventing unnecessary updat
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[facetifiedValue],
Expand All @@ -64,7 +62,6 @@ it('forwards a facet', () => {
useFacetEffect(
(value) => {
mock(value)
return undefined
},
[],
[facetifiedValue],
Expand Down Expand Up @@ -125,7 +122,6 @@ const testEffectUpdatesOnStaticValue = (value: FacetProp<Value>, expectUpdates:
useFacetEffect(
() => {
mock()
return undefined
},
[],
[undefinedFacet],
Expand Down
Loading