-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react-hooks): add missing service listener cleanup
- Loading branch information
Showing
3 changed files
with
29 additions
and
16 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,30 +1,18 @@ | ||
import type { FC } from 'react'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
import { useState } from 'react'; | ||
import { OBJECTCLASS } from '@pandino/pandino-api'; | ||
import { ComponentProxy, useTrackService } from '@pandino/react-hooks'; | ||
import { ComponentProxy } from '@pandino/react-hooks'; | ||
import { CUSTOM_COMPONENT_INTERFACE_KEY } from '@react-systemjs/component-api'; | ||
import { SOME_SERVICE_INTERFACE_KEY, SomeService } from './service'; | ||
import { FallbackComponent } from './FallbackComponent'; | ||
|
||
export const App: FC = () => { | ||
const [firstName] = useState<string>('John'); | ||
const { service: someService } = useTrackService<SomeService>(`(${OBJECTCLASS}=${SOME_SERVICE_INTERFACE_KEY})`); | ||
const text = useMemo<string | undefined>(() => someService?.someMethod(), [someService]); | ||
|
||
console.count('Rendering App.'); | ||
|
||
useEffect(() => { | ||
console.info(`SomeService implementation: ${someService}`); | ||
}, [someService]); | ||
|
||
useEffect(() => { | ||
console.info(`text: ${text}`); | ||
}, [text]); | ||
|
||
return ( | ||
<ComponentProxy filter={`(${OBJECTCLASS}=${CUSTOM_COMPONENT_INTERFACE_KEY})`} firstName={firstName}> | ||
<div className={'fallback'}>fallback for: {firstName}</div> | ||
<div className={'service'}>SomeService test: {someService?.someMethod()}</div> | ||
<div className={'text'}>Text: {text}</div> | ||
<FallbackComponent firstName={firstName} /> | ||
</ComponentProxy> | ||
); | ||
}; |
21 changes: 21 additions & 0 deletions
21
examples/react-systemjs/packages/app/src/FallbackComponent.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,21 @@ | ||
import { useMemo } from 'react'; | ||
import { OBJECTCLASS } from '@pandino/pandino-api'; | ||
import { useTrackService } from '@pandino/react-hooks'; | ||
import type { CustomComponent } from '@react-systemjs/component-api'; | ||
import { SOME_SERVICE_INTERFACE_KEY, SomeService } from './service'; | ||
|
||
export const FallbackComponent: CustomComponent = (props) => { | ||
const { service: someService } = useTrackService<SomeService>(`(${OBJECTCLASS}=${SOME_SERVICE_INTERFACE_KEY})`); | ||
const text = useMemo<string | undefined>(() => someService?.someMethod(), [someService]); | ||
|
||
console.count('Rendering FallbackComponent.'); | ||
console.info(`SomeService implementation: ${someService}`); | ||
|
||
return ( | ||
<div> | ||
<div className={'fallback'}>fallback for: {props.firstName}</div> | ||
<div className={'service'}>SomeService test: {someService?.someMethod()}</div> | ||
<div className={'text'}>Text: {text}</div> | ||
</div> | ||
); | ||
}; |
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