diff --git a/campaign/src/main.ts b/campaign/src/main.ts index 11d383641bcae30dec320cea577c64408ac56b8d..74f651ffa11678edc975f08a363707d902eb0252 100644 --- a/campaign/src/main.ts +++ b/campaign/src/main.ts @@ -29,10 +29,14 @@ const mountFunction = () => { if (window.mount == null) { window.mount = { - Campaign: mountFunction + Campaign: { + mount: mountFunction + } }; } else { - window.mount.Campaign = mountFunction; + window.mount.Campaign = { + mount: mountFunction + }; } \ No newline at end of file diff --git a/campaign/src/polyfills.ts b/campaign/src/polyfills.ts index 97e54994bfe9bda39b6aed7c8b894d5a6ca04286..caccca42d8cf3f0f32dc1687795df09165b081bc 100644 --- a/campaign/src/polyfills.ts +++ b/campaign/src/polyfills.ts @@ -60,8 +60,12 @@ import 'zone.js/dist/zone'; // Included with Angular CLI. declare global { + interface MountDefinition { + mount: () => void; + } + interface MountObject { - Campaign: () => void; + Campaign: MountDefinition; } interface Window { diff --git a/portal/src/App.jsx b/portal/src/App.jsx index 0df27a4dcf4e10770b7ef5a8e401b09ed86fa707..761152686a78aadaab6ac91bbc6ae06615e6fdf8 100644 --- a/portal/src/App.jsx +++ b/portal/src/App.jsx @@ -25,6 +25,9 @@ function App() { +
+ +
); } diff --git a/portal/src/MicroFrontend.jsx b/portal/src/MicroFrontend.jsx index a2b5a460a153b43e51e5711a27a854b1c9c31a8e..534a14ec6fd02ba47e7a7b075199e7a24068b9ad 100644 --- a/portal/src/MicroFrontend.jsx +++ b/portal/src/MicroFrontend.jsx @@ -9,11 +9,12 @@ export default ({ name, path }) => { useEffect(() => { // add cache control here (maybe expire date) - const mountFunction = window.mount[name]; + const mountFunction = window.mount[name] && window.mount[name].mount; + const unmountFunction = () => window.mount[name].unmount if (mountFunction) { mountFunction(); - return; + return unmountFunction; } fetch(`${path}/asset-manifest.json`) @@ -22,6 +23,8 @@ export default ({ name, path }) => { loadScripts(manifest, name, setDone); }) .catch(e => console.log(e)); + + return unmountFunction; }); return ( @@ -60,7 +63,7 @@ function loadScripts(manifest, name, setDone) { count--; if (count === 0) { console.log('mounting', name) - window.mount[name](); + window.mount[name].mount(); setDone(true); } } diff --git a/proxy/proxy.7z b/proxy/proxy.7z new file mode 100644 index 0000000000000000000000000000000000000000..023e95e69d4be3d2effe30eae90c4143952296ed Binary files /dev/null and b/proxy/proxy.7z differ diff --git a/sale/content/sale/main.js b/sale/content/sale/main.js index 9e574f0b35974e519d8fca8a6ae8a1a6facb4608..3c65f03b41839d962eac894652c88cd03f0a89d7 100644 --- a/sale/content/sale/main.js +++ b/sale/content/sale/main.js @@ -13,7 +13,7 @@ class Sale extends HTMLElement { `; } -} +} window.customElements.define('sale-component', Sale); @@ -22,9 +22,11 @@ if (!window.mount) { window.mount = {}; } -window.mount.Sale = () => { - document.querySelector('#Sale-container').innerHTML = - ''; +window.mount.Sale = { + mount: () => { + document.querySelector('#Sale-container').innerHTML = + ''; + } } diff --git a/search/src/App.jsx b/search/src/App.jsx index a677483a3c27c6f68b211344b4ff471a9ed65823..388544d78e6c8cad47e7e37f2584dac22addb8bc 100644 --- a/search/src/App.jsx +++ b/search/src/App.jsx @@ -1,10 +1,17 @@ import React, {useState} from 'react'; import './App.css'; -function App() { +function App({ setSaveAction }) { const [query, setQuery] = useState(''); + setSaveAction( + () => { + console.log('save clicked!') + } + ); + + const handleChange = e => { const newValue = e.target.value; if (newValue.length <= 20) { diff --git a/search/src/index.js b/search/src/index.js index d661ebe523063b228ebb63e81a85bef487964372..10971d100896d16fe2f117c408b3fb6aa2bae10a 100644 --- a/search/src/index.js +++ b/search/src/index.js @@ -4,7 +4,32 @@ import './index.css'; import App from './App'; -window.mount.Search = () => { - const MyComponent = 'App' - ReactDOM.render(, document.getElementById('Search-container')); -}; +class Mount { + + constructor() { + this.mount = this.mount.bind(this) + this.setSaveAction = this.setSaveAction.bind(this) + + this.container = document.getElementById('Search-container'); + } + + setSaveAction(action) { + this.save = action; + } + + mount(props = {}) { + console.log('mounting React component...') + + ReactDOM.render( + , + this.container + ); + } + + unmount() { + ReactDOM.unmountComponentAtNode(this.container); + } + +} + +window.mount.Search = new Mount();