mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import { beforeFrameStartsInjectionToken } from "../before-frame-starts/before-frame-starts-injection-token";
|
|
import syncBoxInitialValueChannelInjectable from "../../common/sync-box/sync-box-initial-value-channel.injectable";
|
|
import syncBoxStateInjectable from "../../common/sync-box/sync-box-state.injectable";
|
|
import { requestFromChannelInjectionToken } from "../../common/channel/request-from-channel-injection-token";
|
|
|
|
const provideInitialValuesForSyncBoxesInjectable = getInjectable({
|
|
id: "provide-initial-values-for-sync-boxes",
|
|
|
|
instantiate: (di) => {
|
|
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
|
|
const syncBoxInitialValueChannel = di.inject(syncBoxInitialValueChannelInjectable);
|
|
const setSyncBoxState = (id: string, state: any) => di.inject(syncBoxStateInjectable, id).set(state);
|
|
|
|
return {
|
|
run: async () => {
|
|
const initialValues = await requestFromChannel(syncBoxInitialValueChannel);
|
|
|
|
initialValues.forEach(({ id, value }) => {
|
|
setSyncBoxState(id, value);
|
|
});
|
|
},
|
|
};
|
|
},
|
|
|
|
injectionToken: beforeFrameStartsInjectionToken,
|
|
});
|
|
|
|
export default provideInitialValuesForSyncBoxesInjectable;
|