-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3374957
commit 25907c8
Showing
26 changed files
with
2,772 additions
and
437 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@web-apps/fed", | ||
"version": "0.0.0", | ||
"private": true, | ||
"devDependencies": { | ||
"@babel/core": "7.10.2", | ||
"@babel/preset-react": "7.10.1", | ||
"babel-loader": "8.1.0", | ||
"serve": "11.3.0", | ||
"webpack": "^5.0.0-beta.17", | ||
"webpack-cli": "3.3.11", | ||
"webpack-dev-server": "3.11.0" | ||
}, | ||
"scripts": { | ||
"start": "webpack-dev-server" | ||
}, | ||
"dependencies": { | ||
"react": "^16.13.0", | ||
"react-dom": "^16.13.0", | ||
"moment": "^2.24.0" | ||
} | ||
} |
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,16 @@ | ||
import React from 'react'; | ||
import moment from 'moment'; | ||
|
||
export default ({foo}) => ( | ||
<div | ||
style={{ | ||
borderRadius: '4px', | ||
padding: '2em', | ||
backgroundColor: 'red', | ||
color: 'white', | ||
}} | ||
> | ||
<h2>App 2 Widget: {foo}</h2> | ||
<p>{moment().format('MMMM Do YYYY, h:mm:ss a')}</p> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import App from './App'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
export default node => { | ||
ReactDOM.render(<App foo={node.getAttribute('foo')} />, node); | ||
return () => ReactDOM.unmountComponentAtNode(node); | ||
}; |
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,47 @@ | ||
const {ModuleFederationPlugin} = require('webpack').container; | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
entry: './src/index', | ||
mode: 'development', | ||
devServer: { | ||
contentBase: path.join(__dirname, 'dist'), | ||
port: process.env.REACT_APP_FED_PORT, | ||
}, | ||
output: { | ||
publicPath: `http://localhost:${process.env.REACT_APP_FED_PORT}/`, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx?$/, | ||
loader: 'babel-loader', | ||
exclude: /node_modules/, | ||
options: { | ||
presets: ['@babel/preset-react'], | ||
}, | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new ModuleFederationPlugin({ | ||
name: 'web_app_federation', | ||
library: {type: 'var', name: 'web_app_federation'}, | ||
filename: 'remoteEntry.js', | ||
exposes: { | ||
'./App': './src/App', | ||
'./index': './src/index', | ||
}, | ||
shared: { | ||
'react-dom': 'react-dom', | ||
moment: '^2.24.0', | ||
react: { | ||
import: 'react', // the "react" package will be used a provided and fallback module | ||
shareKey: 'react', // under this name the shared module will be placed in the share scope | ||
shareScope: 'default', // share scope with this name will be used | ||
singleton: true, // only a single version of the shared module is allowed | ||
}, | ||
}, | ||
}), | ||
], | ||
}; |
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,15 @@ | ||
import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter'; | ||
import '@webcomponents/webcomponentsjs'; | ||
import React from 'react'; | ||
import {render} from 'react-dom'; | ||
import Router from './Router'; | ||
|
||
import 'bootstrap/dist/css/bootstrap.css'; | ||
import '@ringcentral/web-apps-host-css/styles.css'; | ||
import './index.css'; | ||
|
||
const rootEl = document.getElementById('app'); | ||
|
||
render(<Router />, rootEl); | ||
|
||
if (module.hot) module.hot.accept(); |
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 @@ | ||
import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter'; | ||
import '@webcomponents/webcomponentsjs'; | ||
import React from 'react'; | ||
import {render} from 'react-dom'; | ||
import Router from './Router'; | ||
|
||
import 'bootstrap/dist/css/bootstrap.css'; | ||
import '@ringcentral/web-apps-host-css/styles.css'; | ||
import './index.css'; | ||
|
||
const rootEl = document.getElementById('app'); | ||
|
||
render(<Router />, rootEl); | ||
|
||
if (module.hot) module.hot.accept(); | ||
import('./bootstrap'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, {memo, useEffect, useState} from 'react'; | ||
import {appRegistry} from '../lib/registry'; | ||
import {useApplication, useListenerEffect, eventType} from '@ringcentral/web-apps-host-react'; | ||
|
||
const id = 'federation'; | ||
|
||
export const FederationApp = memo(({logout}) => { | ||
const [url, setUrl] = useState(null); | ||
|
||
useEffect(() => { | ||
let mounted = true; | ||
appRegistry[id].getUrl().then(url => mounted && setUrl(url)); | ||
return () => (mounted = false); | ||
}, []); | ||
|
||
const {error, loading, Component, node} = useApplication({ | ||
id, | ||
type: appRegistry[id].type, | ||
url, | ||
options: appRegistry[id].options, | ||
}); | ||
|
||
useListenerEffect(node, eventType.message, e => e.detail.logout && logout()); | ||
|
||
let render; | ||
if (!url) render = <>Loading federation app...</>; | ||
else if (error) render = <>Error in federation: {error.toString()}</>; | ||
else if (loading) render = <>Loading federation app...</>; | ||
|
||
return ( | ||
<div className="navbar-container"> | ||
{render && ( | ||
<nav className="navbar navbar-expand-lg navbar-light bg-light" style={{justifyContent: 'center'}}> | ||
<span className="navbar-text">{render}</span> | ||
</nav> | ||
)} | ||
<Component foo="bar" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, {memo, useEffect, useState} from 'react'; | ||
import {appRegistry} from '../lib/registry'; | ||
import {useApplication, useListenerEffect, eventType} from '@ringcentral/web-apps-host-react'; | ||
|
||
const id = 'federationDirect'; | ||
|
||
export const FederationDirectApp = memo(({logout}) => { | ||
const [url, setUrl] = useState(null); | ||
|
||
useEffect(() => { | ||
let mounted = true; | ||
appRegistry[id].getUrl().then(url => mounted && setUrl(url)); | ||
return () => (mounted = false); | ||
}, []); | ||
|
||
const {error, loading, Component, node} = useApplication({ | ||
id, | ||
type: appRegistry[id].type, | ||
url, | ||
options: appRegistry[id].options, | ||
}); | ||
|
||
useListenerEffect(node, eventType.message, e => e.detail.logout && logout()); | ||
|
||
let render; | ||
if (!url) render = <>Loading federation app...</>; | ||
else if (error) render = <>Error in federation: {error.toString()}</>; | ||
else if (loading) render = <>Loading federation app...</>; | ||
|
||
return ( | ||
<div className="navbar-container"> | ||
{render && ( | ||
<nav className="navbar navbar-expand-lg navbar-light bg-light" style={{justifyContent: 'center'}}> | ||
<span className="navbar-text">{render}</span> | ||
</nav> | ||
)} | ||
<Component direct foo="bar" /> | ||
</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
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.