-
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): improve service and bundle lifecycle handling
- Loading branch information
Showing
5 changed files
with
92 additions
and
41 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,15 +1,30 @@ | ||
import type { FC } from 'react'; | ||
import { useState } from 'react'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
import { OBJECTCLASS } from '@pandino/pandino-api'; | ||
import { ComponentProxy } from '@pandino/react-hooks'; | ||
import { ComponentProxy, useTrackService } from '@pandino/react-hooks'; | ||
import { CUSTOM_COMPONENT_INTERFACE_KEY } from '@react-systemjs/component-api'; | ||
import { SOME_SERVICE_INTERFACE_KEY, SomeService } from './service'; | ||
|
||
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> | ||
</ComponentProxy> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const SOME_SERVICE_INTERFACE_KEY = 'SomeService'; | ||
|
||
export interface SomeService { | ||
someMethod(): string; | ||
} | ||
|
||
export class SomeServiceImpl implements SomeService { | ||
someMethod(): string { | ||
return "some fine service"; | ||
} | ||
} |
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