Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
@adobe/lit-mobx
Advanced tools
Mixin and base class that allow easy usage of mobx observables with
lit
.
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.
As a dependency:
npm install --save @adobe/lit-mobx lit mobx
This library has been updated to the latest version of Lit which we highly recommend you update to. However if you wish to continue using LitMobx with LitElement 2.0 then install the 1.0 major version:
npm install --save @adobe/lit-mobx@^1.0.0
We will backport any security patches (though don't expect there to be any) in this major version as necessary.
npm install
npm run demo
See the JavaScript and TypeScript example projects on StackBlitz. See this example for a demonstration of usage with Mobx v6 in Typescript without the use of decorators.
import { html, TemplateResult } from 'lit';
import { customElement, LitElement } from 'lit/decorators.js';
import { observable, action } from 'mobx';
import { MobxLitElement } from '@adobe/lit-mobx';
// create a mobx observable
class Counter {
@observable
public count = 0;
@action
public increment() {
this.count++;
}
}
// create instance that can be shared across components
const counter = new Counter();
// create a new custom element, and use the base MobxLitElement class
// alternatively you can use the MobxReactionUpdate mixin, e.g. `class MyElement extends MobxReactionUpdate(LitElement)`
@customElement('my-element')
export class MyElement extends MobxLitElement {
private counter = counter;
// any observables accessed in the render method will now trigger an update
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.
NOTE: observables are only hooked for updating the render function if those observables are directly used within the render function. The implementation of this library is such that we essential wrap the render function in an autorun
block to hook these observables for re-running render. If you wish to response to an observable property to calculate some other result that then itself is used in the render function, then you need to use the regular MobX methods for observability in a property changed callback or some other lifecycle function to setup that observation and the write to a property in your component that is appropriately decorated to drive Lit's regular update cycle.
In some rare cases applications may need to have multiple different major versions of Mobx within a single app. This can lead to issues where the version of mobx used in various places needs to be specifically imported from aliased versions of mobx, e.g. aliasing mobx 6.x
to mobx6
.
To help support these cases lit-mobx provides the custom implementation of the MobxReactionUpdate mixin, MobxReactionUpdateCustom
, that supports taking the Reaction
constructor as a second argument. This allows the user to define which version of mobx to pass, and ensures that no side effects are caused by lit-mobx importing mobx
directly.
Example usage:
import { MobxReactionUpdateCustom } from '@adobe/lit-mobx/lib/mixin-custom.js';
// import your specific mobx version
import { Reaction } from 'mobx6';
// and pass it to the mixin to create your own mobx lit element base class
class Mobx6LitElement extends MobxReactionUpdateCustom(LitElement, Reaction) {}
Contributions are welcomed! Read the Contributing Guide for more information.
This project is licensed under the Apache V2 License. See LICENSE for more information.
FAQs
Integrating mobx with lit-element!
The npm package @adobe/lit-mobx receives a total of 6,317 weekly downloads. As such, @adobe/lit-mobx popularity was classified as popular.
We found that @adobe/lit-mobx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 22 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.