mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
respond to review comments
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2b08d61070
commit
97ae34bad3
@ -24,7 +24,7 @@ Further reading is available from `mobx`'s [website](https://mobx.js.org/the-gis
|
||||
|
||||
## Basic usage of mobx:
|
||||
|
||||
When using `Lens`'s extension's API, some of the provided types are marked as `observable` (or others) and are documented as such.
|
||||
When using `Lens`'s extension's API, some of the provided types are marked as `observable` and are documented as such.
|
||||
These can be used as normal types and the combination of `mobx` and `react` work to determine when a rerender should occur.
|
||||
|
||||
---
|
||||
@ -37,12 +37,15 @@ That could be achieved using roughly the following code:
|
||||
```typescript
|
||||
import { LensMainExtension, MenuRegistration } from "@k8slens/extensions";
|
||||
import observables from "./observables" // a collection of observable data
|
||||
import { IReactionDisposer } from "mobx";
|
||||
|
||||
interface MenuRegistrationWithId extends MenuRegistration {
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export default class ExtensionMain extends LensMainExtension {
|
||||
menuReactionDispose?: IReactionDisposer;
|
||||
|
||||
appMenus: MenuRegistrationWithId[] = [
|
||||
{
|
||||
parentId: "file",
|
||||
@ -53,10 +56,8 @@ export default class ExtensionMain extends LensMainExtension {
|
||||
},
|
||||
];
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
reaction(
|
||||
onActivate() {
|
||||
this.menuReactionDispose = reaction(
|
||||
() => observables.clusterIsInState,
|
||||
clusterIsInState => {
|
||||
if (clusterIsInState) {
|
||||
@ -74,5 +75,10 @@ export default class ExtensionMain extends LensMainExtension {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
onDeactivate() {
|
||||
this.menuReactionDispose?.() // always clenaup mobx disposers
|
||||
this.menuReactionDispose = undefined
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user