mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
17 files changed
+358
-3
No files matched your search
@@ -1,3 +1,4 @@
|
||||
export { getFeature } from "./src/feature";
|
||||
export { registerFeature } from "./src/register-feature";
|
||||
export { registerFeature, featureInjectionToken } from "./src/register-feature";
|
||||
export type { FeatureAsd } from "./src/register-feature";
|
||||
export type { Feature, GetFeatureArgs } from "./src/feature";
|
||||
@@ -31,7 +31,8 @@
|
||||
"lint:fix": "lens-lint --fix"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@ogre-tools/injectable": "^16.1.0"
|
||||
"@ogre-tools/injectable": "^16.1.0",
|
||||
"mobx": "^6.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@k8slens/eslint-config": "^6.5.0-alpha.3",
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Feature } from "./feature";
|
||||
import { featureContextMapInjectable, featureContextMapInjectionToken } from "./feature-context-map-injectable";
|
||||
import { action, IComputedValue } from "mobx";
|
||||
import { computed, observable } from "mobx";
|
||||
|
||||
export type FeatureAsd = {
|
||||
id: string;
|
||||
enabled: IComputedValue<boolean>;
|
||||
toggle: () => void;
|
||||
};
|
||||
|
||||
export const featureInjectionToken = getInjectionToken<FeatureAsd>({
|
||||
id: "feature-injection-token",
|
||||
});
|
||||
|
||||
const createFeatureContext = (feature: Feature, di: DiContainer) => {
|
||||
const featureContextInjectable = getInjectable({
|
||||
@@ -26,6 +38,40 @@ const createFeatureContext = (feature: Feature, di: DiContainer) => {
|
||||
|
||||
di.register(featureContextInjectable);
|
||||
|
||||
const featureAsdInjectable = getInjectable({
|
||||
id: `${feature.id}-feature`,
|
||||
|
||||
instantiate: (di) => {
|
||||
const enabled = observable.box(true);
|
||||
|
||||
const featureContext = di.inject(featureContextInjectable);
|
||||
|
||||
return {
|
||||
id: feature.id,
|
||||
|
||||
enabled: computed(() => {
|
||||
return enabled.get();
|
||||
}),
|
||||
|
||||
toggle: action(() => {
|
||||
console.log("mikko", enabled.get());
|
||||
|
||||
if (enabled.get()) {
|
||||
enabled.set(false);
|
||||
featureContext.deregister();
|
||||
} else {
|
||||
enabled.set(true);
|
||||
featureContext.register();
|
||||
}
|
||||
}),
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: featureInjectionToken,
|
||||
});
|
||||
|
||||
di.register(featureAsdInjectable);
|
||||
|
||||
const featureContextMap = di.inject(featureContextMapInjectable);
|
||||
const featureContext = di.inject(featureContextInjectable);
|
||||
|
||||
|
||||
Reference in new issue
Block a user