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
// ... | |
import worky from 'worky'; | |
window.worky = worky; | |
// ... |
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
let said = []; | |
export function say(message) { | |
console.log({ message, said }); | |
said.push(message) | |
// This postMessage communicates with everyone listening to this worker | |
postMessage(message); | |
} |
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 { worky } = window; | |
function App() { | |
const handleSubmit = (e) => { | |
e.preventDefault(); | |
const { target: form } = e; | |
const input = form?.elements?.something; | |
worky.say(input.value); |
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 { worky } = window; | |
function App() { | |
const [messages, setMessages] = useState([]); | |
const handleNewMessage = (message) => { | |
if (message.data.type) { | |
return; | |
} |
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
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; |
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
import { Observable } from 'windowed-observable'; | |
const observable = new Observable('messages'); | |
function App() { | |
const [messages, setMessages] = useState([]); | |
const handleNewMessage = (newMessage) => { | |
setMessages((currentMessages) => currentMessages.concat(newMessage)); |
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
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) |
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
function App({ onNewMessage }) { | |
const handleSubmit = (e) => { | |
e.preventDefault(); | |
const { target: form } = e; | |
const input = form?.elements?.something; | |
onNewMessage(input.value); | |
form.reset(); | |
} |
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
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> | |
); |
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 App = ({ microfrontends }) => { | |
const [messages, setMessages] = useState([]); | |
const handleNewMessage = (message) => { | |
setMessages((currentMessages) => currentMessages.concat(message)); | |
}; | |
return ( | |
<main className="App"> | |
<div className="App__header"> |
NewerOlder