Skip to content

Instantly share code, notes, and snippets.

// ...
import worky from 'worky';
window.worky = worky;
// ...
let said = [];
export function say(message) {
console.log({ message, said });
said.push(message)
// This postMessage communicates with everyone listening to this worker
postMessage(message);
}
const { worky } = window;
function App() {
const handleSubmit = (e) => {
e.preventDefault();
const { target: form } = e;
const input = form?.elements?.something;
worky.say(input.value);
const { worky } = window;
function App() {
const [messages, setMessages] = useState([]);
const handleNewMessage = (message) => {
if (message.data.type) {
return;
}
import { Observable } from 'windowed-observable';
const observable = new Observable('messages');
function App() {
const handleSubmit = (e) => {
e.preventDefault();
const { target: form } = e;
const input = form?.elements?.something;
import { Observable } from 'windowed-observable';
const observable = new Observable('messages');
function App() {
const [messages, setMessages] = useState([]);
const handleNewMessage = (newMessage) => {
setMessages((currentMessages) => currentMessages.concat(newMessage));
import { Observable } from 'windowed-observable';
// Define a specific context namespace
const observable = new Observable('cart-items');
const observer = (item) => console.log(item);
// Add an observer subscribing to new events on this observable
observable.subscribe(observer)
function App({ onNewMessage }) {
const handleSubmit = (e) => {
e.preventDefault();
const { target: form } = e;
const input = form?.elements?.something;
onNewMessage(input.value);
form.reset();
}
function App({ messages = [] }) {
return (
<div className="MF">
<h3>Microfrontend 1️⃣</h3>
<p>New messages will be displayed below 👇</p>
<div className="MF__messages">
{messages.map((something, i) => <p key={something + i}>{something}</p>)}
</div>
</div>
);
const App = ({ microfrontends }) => {
const [messages, setMessages] = useState([]);
const handleNewMessage = (message) => {
setMessages((currentMessages) => currentMessages.concat(message));
};
return (
<main className="App">
<div className="App__header">