lit-mobx
Mixin and base class that allow easy usage of mobx observables with
lit-element
.
The mixin implementation is based heavily on the work of Alexander Weiss in his
mobx-lit-element
implementation. This has been rewritten to
support multiple forms of usage (mixin, or base class) as well as to be based on typescript to get type definitions.
Installation
npm install
Demo
npm run demo
Usage
import { LitElement, html, TemplateResult, customElement } from 'lit-element';
import { observable, action } from 'mobx';
import { MobxLitElement } from 'lit-mobx';
class Counter {
@observable
public count = 0;
@action
public increment() {
this.count++;
}
}
@customElement('my-element')
export class MyElement extends MobxLitElement {
private counter = new Counter();
public render(): TemplateResult {
return html`
Count is ${this.counter.count}
<br />
<button @click=${this.incrementCount}>Add</button>
`;
}
private incrementCount() {
this.counter.increment();
}
}
For further examples see the demo folder.
Contributing
Contributions are welcomed! Read the Contributing Guide for more information.
Licensing
This project is licensed under the Apache V2 License. See LICENSE for more information.