1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Use disposer. Fix style.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2022-11-17 15:25:49 +02:00
parent 2846f04e96
commit 7a8c3effd0

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import type { IReactionDisposer } from "mobx";
import { reaction, runInAction } from "mobx"; import { reaction, runInAction } from "mobx";
import { disposer } from "../../../common/utils/disposer";
import type { LensExtension } from "../../lens-extension"; import type { LensExtension } from "../../lens-extension";
import { extensionRegistratorInjectionToken } from "../extension-registrator-injection-token"; import { extensionRegistratorInjectionToken } from "../extension-registrator-injection-token";
@ -22,14 +22,14 @@ const extensionInjectable = getInjectable({
instantiate: (childDi) => { instantiate: (childDi) => {
const extensionRegistrators = childDi.injectMany(extensionRegistratorInjectionToken); const extensionRegistrators = childDi.injectMany(extensionRegistratorInjectionToken);
const disposers: IReactionDisposer[] = []; const reactionDisposer = disposer();
return { return {
register: () => { register: () => {
extensionRegistrators.forEach((getInjectablesOfExtension) => { extensionRegistrators.forEach((getInjectablesOfExtension) => {
const injectables = getInjectablesOfExtension(instance); const injectables = getInjectablesOfExtension(instance);
disposers.push( reactionDisposer.push(
// injectables is either an array or a computed array, in which case // injectables is either an array or a computed array, in which case
// we need to update the registered injectables with a reaction every time they change // we need to update the registered injectables with a reaction every time they change
reaction( reaction(
@ -49,11 +49,7 @@ const extensionInjectable = getInjectable({
}, },
deregister: () => { deregister: () => {
disposers.forEach(dispose => { reactionDisposer();
dispose();
});
disposers.length = 0;
runInAction(() => { runInAction(() => {
parentDi.deregister(extensionInjectable); parentDi.deregister(extensionInjectable);
@ -71,7 +67,7 @@ const extensionInjectable = getInjectable({
}, },
lifecycle: lifecycleEnum.keyedSingleton({ lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (_di, instance: LensExtension) => instance, getInstanceKey: (di, instance: LensExtension) => instance,
}), }),
}); });