-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demos): add state serialization to async-ssr-manager demo (#291)
- Loading branch information
1 parent
938c8bc
commit bdbcdb1
Showing
13 changed files
with
199 additions
and
35 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
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 was deleted.
Oops, something went wrong.
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,66 @@ | ||
import {FeatureAppManager, FeatureServiceRegistry} from '@feature-hub/core'; | ||
import {defineExternals, loadAmdModule} from '@feature-hub/module-loader-amd'; | ||
import {FeatureAppLoader} from '@feature-hub/react'; | ||
import { | ||
SerializedStateManagerV0, | ||
serializedStateManagerDefinition | ||
} from '@feature-hub/serialized-state-manager'; | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import '../blueprint-css'; | ||
|
||
const featureAppUrl = 'feature-app.umd.js'; | ||
|
||
function getSerializedStatesFromDom(): string | undefined { | ||
const scriptElement = document.querySelector( | ||
'script[type="x-feature-hub/serialized-states"]' | ||
); | ||
|
||
return (scriptElement && scriptElement.textContent) || undefined; | ||
} | ||
|
||
(async () => { | ||
const integratorDefinition = { | ||
id: 'test:integrator', | ||
dependencies: { | ||
[serializedStateManagerDefinition.id]: '^0.1' | ||
} | ||
}; | ||
|
||
const featureServiceRegistry = new FeatureServiceRegistry(); | ||
|
||
featureServiceRegistry.registerFeatureServices( | ||
[serializedStateManagerDefinition], | ||
integratorDefinition.id | ||
); | ||
|
||
const {featureServices} = featureServiceRegistry.bindFeatureServices( | ||
integratorDefinition | ||
); | ||
|
||
const featureAppManager = new FeatureAppManager(featureServiceRegistry, { | ||
moduleLoader: loadAmdModule | ||
}); | ||
|
||
defineExternals({react: React}); | ||
|
||
await featureAppManager.preloadFeatureApp(featureAppUrl); | ||
|
||
const serializedStateManager = featureServices[ | ||
serializedStateManagerDefinition.id | ||
] as SerializedStateManagerV0; | ||
|
||
const serializedStates = getSerializedStatesFromDom(); | ||
|
||
if (serializedStates) { | ||
serializedStateManager.setSerializedStates(serializedStates); | ||
} | ||
|
||
ReactDOM.hydrate( | ||
<FeatureAppLoader | ||
featureAppManager={featureAppManager} | ||
src={featureAppUrl} | ||
/>, | ||
document.querySelector('main') | ||
); | ||
})().catch(console.error); |
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
Oops, something went wrong.