I've gotten this to work before, but for some reason after fireEvent the listener is never reached.
js where fireEvent happens:
import { LightningElement, track, api, wire } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { fireEvent } from 'c/pubSub';
import { CurrentPageReference } from 'lightning/navigation';
export default class MissionEdit extends LightningElement {
@api recordId;
@wire(CurrentPageReference) pageRef;
onSaveSuccess(event) {
console.log('++++++++++++++++++++++++++++++++onSaveSuccess'); //it makes it here
fireEvent(this.pageRef, "changedMission");
const toast = new ShowToastEvent({
title: 'Mission Updated!',
message: 'Mission successfully modified',
variant: 'success',
mode: 'dismissable'
});
this.dispatchEvent(toast);
fireEvent(this.pageRef, "changedMission");
}
}
js listener:
import { LightningElement, api, track, wire } from 'lwc';
import Utility from 'c/utility';
import { CurrentPageReference } from 'lightning/navigation';
import { registerListener, unregisterAllListeners } from 'c/pubSub';
export default class MissionDetailHeaderInfo extends Utility {
@api recordId;
@wire(CurrentPageReference) pageRef;
connectedCallback(){
console.log('RrosMissionDetailsPage----connectedCallback');
registerListener("changedMission", this.handleChanged, this);
}
disconnectedCallback() {
console.log('disconnectedCallback');
unregisterAllListeners(this);
}
handleChanged(event) {
console.log('header refreshed +++++++++++++++++++++++++++++++++++++');//doesn't reach here
this.renderMissionHeaderDetails();
}
}
Any idea what I'm doing wrong?