Am I allowed to use the wire service in an ES module, i.e. a 'headless' utility class?
Or, must I extend LightningElement
also?
import {wire} from 'lwc';
import sapLogin from '@salesforce/apex/SAPService.login';//cachable=true
export class SapSession
{
//sessionInfo = undefined;//EDIT oops don't need to declare this
//the wire below does that
@wire(sapLogin)sessionInfo
get Cookie() {
return sessionInfo.data.Cookies;//delimited string of cookies returned
}
get Error() {
return sessionInfo.error;//wire failure returns error poperty
}
}
When I deploy the above class, there are no compilation issues. But, it also doesn't seem to be working in the consuming lwc, either, e.g.
import { LightningElement } from 'lwc';
import { SapSession } from 'c/sapSession';
export default class someUiComponent extends LightningElement {
session = undefined;
// One of the standard lifecycle callbacks you can include in an LWC
connectedCallback() {
this.session = SapSession;
}
}
someUiComponent.html
<template>
<div>
little test:
<div if:true={session}>
<div if:true={session.Cookie}> {session.Cookie}</div>
<div if:true={session.Error}> {session.Error}</div>
</div>
</div>
</template>