-
-
Save FlorianRappl/ca90ef66944457772d21af6297383485 to your computer and use it in GitHub Desktop.
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
const data = {}; | |
const getDataGlobal = name => { | |
const item = data[name]; | |
return item && item.value; | |
} | |
const setDataGlobal = (owner, name, value) => { | |
const previous = data[name]; | |
if (!previous || previous.owner === owner) { | |
data[name] = { | |
owner, | |
name, | |
value, | |
}; | |
window.dispatchEvent(new CustomEvent('changed-data', { | |
detail: { | |
name, | |
previous: previous && previous.value, | |
current: value, | |
}, | |
})); | |
} | |
}; | |
microfrontends.forEach(mife => { | |
const api = { | |
getData: getDataGlobal, | |
setData(name, value) { | |
setDataGlobal(mife.name, name, value); | |
}, | |
}; | |
const script = document.createElement('script'); | |
script.src = mife.url; | |
script.onload = () => { | |
script.setup(api); | |
}; | |
document.body.appendChild(script); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment