-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(history-service): support multiple location changes in one navig…
- Loading branch information
1 parent
5f4a3d3
commit 1352318
Showing
38 changed files
with
3,305 additions
and
1,514 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
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
54 changes: 54 additions & 0 deletions
54
packages/demos/src/advanced-routing/hello-world-feature-app.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,54 @@ | ||
import {Card, Text} from '@blueprintjs/core'; | ||
import {FeatureAppDefinition} from '@feature-hub/core'; | ||
import {ReactFeatureApp} from '@feature-hub/react'; | ||
import * as React from 'react'; | ||
import {HelloWorldServiceV1} from './hello-world-service'; | ||
|
||
interface Dependencies { | ||
readonly 'test:hello-world-service': HelloWorldServiceV1; | ||
} | ||
|
||
interface HelloWorldTextProps { | ||
readonly helloWorldService: HelloWorldServiceV1; | ||
} | ||
|
||
function HelloWorldText({helloWorldService}: HelloWorldTextProps): JSX.Element { | ||
const [name, setName] = React.useState(helloWorldService.name); | ||
|
||
React.useEffect( | ||
() => helloWorldService.listen(() => setName(helloWorldService.name)), | ||
[helloWorldService] | ||
); | ||
|
||
return ( | ||
<Text> | ||
<span id="hello-text">Hello, {name}!</span> | ||
</Text> | ||
); | ||
} | ||
|
||
const featureAppDefinition: FeatureAppDefinition< | ||
ReactFeatureApp, | ||
Dependencies | ||
> = { | ||
dependencies: { | ||
featureServices: { | ||
'test:hello-world-service': '^1.0.0' | ||
}, | ||
externals: { | ||
react: '^16.7.0' | ||
} | ||
}, | ||
|
||
create: ({featureServices}) => ({ | ||
render: () => ( | ||
<Card style={{margin: '20px'}}> | ||
<HelloWorldText | ||
helloWorldService={featureServices['test:hello-world-service']} | ||
/> | ||
</Card> | ||
) | ||
}) | ||
}; | ||
|
||
export default featureAppDefinition; |
64 changes: 64 additions & 0 deletions
64
packages/demos/src/advanced-routing/hello-world-service.ts
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,64 @@ | ||
import { | ||
FeatureServiceBinder, | ||
FeatureServiceProviderDefinition, | ||
SharedFeatureService | ||
} from '@feature-hub/core'; | ||
import {ConsumerLocation, HistoryServiceV2} from '@feature-hub/history-service'; | ||
import * as history from 'history'; | ||
|
||
export interface HelloWorldServiceV1 { | ||
name: string; | ||
listen(listener: () => void): () => void; | ||
createLocation(name: string): ConsumerLocation; | ||
} | ||
|
||
export interface SharedHelloWorldService extends SharedFeatureService { | ||
readonly '1.0.0': FeatureServiceBinder<HelloWorldServiceV1>; | ||
} | ||
|
||
export interface HelloWorldServiceDependencies { | ||
readonly 's2:history': HistoryServiceV2; | ||
} | ||
|
||
export const helloWorldServiceDefinition: FeatureServiceProviderDefinition< | ||
SharedHelloWorldService, | ||
HelloWorldServiceDependencies | ||
> = { | ||
id: 'test:hello-world-service', | ||
|
||
dependencies: { | ||
featureServices: { | ||
's2:history': '^2.0.0' | ||
} | ||
}, | ||
|
||
create: ({featureServices}) => { | ||
const historyService = featureServices['s2:history']; | ||
|
||
return { | ||
'1.0.0': () => ({ | ||
featureService: { | ||
get name(): string { | ||
return historyService.history.location.pathname.slice(1) || 'World'; | ||
}, | ||
|
||
set name(value: string) { | ||
const {location} = this.createLocation(value); | ||
historyService.history.push(location); | ||
}, | ||
|
||
listen(listener: () => void): () => void { | ||
return historyService.history.listen(listener); | ||
}, | ||
|
||
createLocation(name: string): ConsumerLocation { | ||
return { | ||
historyKey: historyService.historyKey, | ||
location: history.createLocation(`/${name}`) | ||
}; | ||
} | ||
} | ||
}) | ||
}; | ||
} | ||
}; |
Oops, something went wrong.