Last active
October 16, 2022 19:04
-
-
Save firthous-dev/59d697d742869282fcf9ad58fb917da4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <script> | |
| import {publish, subscribe} from './pubsub' | |
| import {onMessageEvent} from './project-events' | |
| import {onMount} from 'svelte' | |
| let message; | |
| //Listen the event onMount and unscubscribe when return. | |
| onMount(()=>{ | |
| let onMsg = subscribe(onMessageEvent, (msg)=>{ | |
| console.log('Received:', msg); }); | |
| return()=>{ onMsg.unsubscribe(); } | |
| }); | |
| //Send message using publish event | |
| const onSend = ()=>{ | |
| publish(new onMessageEvent({message})); | |
| }; | |
| </script> | |
| <input bind:value={message}/> | |
| <button on:click={onSend}>Send</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment