@exmg/lit-base
Version:
Lit Base Elements for ExMachina
37 lines • 1.26 kB
JavaScript
import { getConnectedStore } from './connect';
import { LitElement } from 'lit';
export class ConnectedClass extends LitElement {
}
/**
* This mixin will connect the element to the redux store
* @param baseElement The base element to extend
* @returns
*/
export const connectedMixin = (baseElement) => {
class Connected extends baseElement {
constructor() {
super(...arguments);
this.routeDebug = false;
this.isPage = false;
}
getStore() {
return getConnectedStore();
}
connectedCallback() {
super.connectedCallback();
this.storeUnsubscribe = this.getStore().subscribe(() => {
this.stateChanged(this.getStore().getState());
this._stateChanged && this._stateChanged(this.getStore().getState());
});
this.stateChanged(this.getStore().getState());
this._stateChanged && this._stateChanged(this.getStore().getState());
}
disconnectedCallback() {
this.storeUnsubscribe && this.storeUnsubscribe();
super.disconnectedCallback();
}
stateChanged(_) { }
}
return Connected;
};
//# sourceMappingURL=connect-mixin.js.map