up bootstrap
This commit is contained in:
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
@@ -1,23 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDom from 'react-dom';
|
||||
|
||||
export default () => (<div>Наше приложение1</div>);
|
||||
|
||||
|
||||
|
||||
export const mount = (Сomponent) => {
|
||||
// console.log('component', component);
|
||||
ReactDom.render(
|
||||
<Сomponent/>,
|
||||
document.getElementById('app')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export const unmount = () => {
|
||||
ReactDom.unmountComponentAtNode(document.getElementById('app'))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDom from 'react-dom';
|
||||
|
||||
export default () => (<div>Наше приложение2</div>);
|
||||
|
||||
export const mount = (Сomponent) => {
|
||||
ReactDom.render(
|
||||
<Сomponent/>,
|
||||
document.getElementById('app')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export const unmount = () => {
|
||||
ReactDom.unmountComponentAtNode(document.getElementById('app'))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
const sysytemJs = require("systemjs/dist/system");
|
||||
|
||||
module.export = ({ apps, navigations, config }) => {
|
||||
console.log("apps", apps);
|
||||
|
||||
sysytemJs.import("./main/index.js");
|
||||
};
|
||||
46
src/main.ts
Normal file
46
src/main.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import "systemjs/dist/s";
|
||||
import "systemjs/dist/extras/amd";
|
||||
import "systemjs/dist/extras/named-register";
|
||||
import "systemjs/dist/extras/named-exports";
|
||||
import "systemjs/dist/extras/transform";
|
||||
import { createBrowserHistory } from 'history'
|
||||
|
||||
declare var System: {
|
||||
import(string): Promise<any>
|
||||
}
|
||||
|
||||
const systemJSImport = async (requestUrl: string) => {
|
||||
const { default: component, mount, unmount } = await System.import(
|
||||
requestUrl
|
||||
)
|
||||
return { component, mount, unmount }
|
||||
}
|
||||
|
||||
const getApp = (apps, path) => {
|
||||
const searchKey = path.substr(1)
|
||||
return `./${searchKey}/${apps[searchKey].version}/index.js`
|
||||
}
|
||||
|
||||
export default async ({ apps, navigations, config }) => {
|
||||
|
||||
const history = createBrowserHistory()
|
||||
|
||||
let prevPathname = window.location.pathname
|
||||
|
||||
/* tslint:disable-next-line */
|
||||
__webpack_public_path__ = `/static${__webpack_public_path__}`
|
||||
|
||||
const app = getApp(apps, history.location.pathname)
|
||||
|
||||
const { component, mount, unmount } = await systemJSImport(app);
|
||||
|
||||
mount(component.default);
|
||||
|
||||
|
||||
history.listen((location) => {
|
||||
if (location.pathname !== prevPathname) {
|
||||
prevPathname = location.pathname
|
||||
unmount()
|
||||
}
|
||||
})
|
||||
};
|
||||
50
src/main.tsx
50
src/main.tsx
@@ -1,50 +0,0 @@
|
||||
import React from 'react';
|
||||
import ReactDom from 'react-dom';
|
||||
import { loadApp } from './utils';
|
||||
|
||||
class Bootstrap extends React.PureComponent <any, any> {
|
||||
App: any;
|
||||
currentBundle: string = '';
|
||||
|
||||
async downloader(bundleName: string) {
|
||||
let _bundleName = bundleName;
|
||||
this.currentBundle = bundleName;
|
||||
this.App = await loadApp(_bundleName);
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
mountApp = async(nameApp) => {
|
||||
await this.downloader(nameApp);
|
||||
this.App.mount(this.App.default)
|
||||
}
|
||||
|
||||
unmountApp = () => {
|
||||
this.App.unmount();
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div>
|
||||
<button onClick={() => this.mountApp('pl')}>
|
||||
загрузить приложение news
|
||||
</button>
|
||||
<button onClick={() => this.mountApp('uds-sections')}>
|
||||
загрузить приложение uds-sections
|
||||
</button>
|
||||
<button onClick={() => this.mountApp('orgApp')}>
|
||||
загрузить приложение org
|
||||
</button>
|
||||
<button onClick={() => this.unmountApp()}>
|
||||
выгрузить приложение 2
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ReactDom.render(
|
||||
<Bootstrap/>,
|
||||
document.getElementById('bootstrap')
|
||||
);
|
||||
|
||||
|
||||
10
src/utils.ts
10
src/utils.ts
@@ -1,10 +0,0 @@
|
||||
export async function loadApp(bundleName) {
|
||||
return await System.import(`./${bundleName}.js`)
|
||||
.then(result => {
|
||||
return result.default;
|
||||
})
|
||||
.catch(error => {
|
||||
console.info(`Загрузить ${bundleName} не удалось!`);
|
||||
console.info(`error in ${bundleName}`, error);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user