Last active
June 19, 2020 20:18
-
-
Save justin-lyon/0a2968654b4b38eff96580ea32694a4b to your computer and use it in GitHub Desktop.
Trying to get the LMS demo working in a scratch
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
<template> | |
<div> | |
<button onclick={subscribeMC}>Subscribe</button> | |
</div> | |
<div> | |
<button onclick={unsubscribeMC}>Unsubscribe</button> | |
</div> | |
</template> |
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
import { LightningElement, wire } from 'lwc' | |
import { APPLICATION_SCOPE, subscribe, unsubscribe, MessageContext } from 'lightning/messageService' | |
import SAMPLEMC from '@salesforce/messageChannel/SampleMessageChannel__c' | |
export default class ExpSubscriber extends LightningElement { | |
@wire(MessageContext) | |
messageContext | |
subscription = null | |
subscribeMC () { | |
if (this.subscription) return | |
console.log('begin sub to', this.messageContext) | |
this.subscription = subscribe( | |
this.messageContext, | |
SAMPLEMC, | |
this.handleMessage, | |
{ scope: APPLICATION_SCOPE }) | |
console.log('subscribed', this.subscription) | |
} | |
unsubscribeMC () { | |
console.log('begin unsub', this.subscription) | |
unsubscribe(this.subscription) | |
this.subscription = null | |
console.log('unsubscribed', this.subscription) | |
} | |
handleMessage (message) { | |
console.log('sub message', JSON.parse(JSON.stringify(message))) | |
} | |
} |
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
<template> | |
<div> | |
<c-exp-publisher></c-exp-publisher> | |
<c-exp-subscriber></c-exp-subscriber> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment