mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Implement initial values for sync-boxes
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
8217ca8883
commit
c5809d3d0a
@ -13,8 +13,12 @@ const discoveredUpdateVersionInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||||
|
|
||||||
return createSyncBox<{ version: string; updateChannel: UpdateChannel } | null>(
|
return createSyncBox<
|
||||||
|
| { version: string; updateChannel: UpdateChannel }
|
||||||
|
| null
|
||||||
|
>(
|
||||||
"discovered-update-version",
|
"discovered-update-version",
|
||||||
|
null,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ const progressOfUpdateDownloadInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||||
|
|
||||||
return createSyncBox<number>("progress-of-update-download");
|
return createSyncBox("progress-of-update-download", 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
injectionToken: syncBoxInjectionToken,
|
injectionToken: syncBoxInjectionToken,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ const updateIsBeingDownloadedInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||||
|
|
||||||
return createSyncBox<boolean>("update-is-being-downloaded");
|
return createSyncBox("update-is-being-downloaded", false);
|
||||||
},
|
},
|
||||||
|
|
||||||
injectionToken: syncBoxInjectionToken,
|
injectionToken: syncBoxInjectionToken,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ const updatesAreBeingDiscoveredInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||||
|
|
||||||
return createSyncBox<boolean>("updates-are-being-discovered");
|
return createSyncBox("updates-are-being-discovered", false);
|
||||||
},
|
},
|
||||||
|
|
||||||
injectionToken: syncBoxInjectionToken,
|
injectionToken: syncBoxInjectionToken,
|
||||||
|
|||||||
@ -17,9 +17,11 @@ const createSyncBoxInjectable = getInjectable({
|
|||||||
const sendToChannel = di.inject(sendToChannelInjectionToken);
|
const sendToChannel = di.inject(sendToChannelInjectionToken);
|
||||||
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
||||||
|
|
||||||
return <TData>(id: string): SyncBox<TData> => {
|
return <TData>(id: string, initialValue: TData): SyncBox<TData> => {
|
||||||
const state = getSyncBoxState(id);
|
const state = getSyncBoxState(id);
|
||||||
|
|
||||||
|
state.set(initialValue);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
|
|
||||||
|
|||||||
@ -126,12 +126,12 @@ describe("sync-box", () => {
|
|||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not know initial value in main", () => {
|
it("knows initial value in main", () => {
|
||||||
expect(valueInMain).toBeUndefined();
|
expect(valueInMain).toBe("some-initial-value");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not know initial value in renderer", () => {
|
it("knows initial value in renderer", () => {
|
||||||
expect(valueInRenderer).toBeUndefined();
|
expect(valueInRenderer).toBe("some-initial-value");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when value is set from main", () => {
|
describe("when value is set from main", () => {
|
||||||
@ -174,6 +174,6 @@ const someInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||||
|
|
||||||
return createSyncBox<string>("some-state");
|
return createSyncBox("some-sync-box", "some-initial-value");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user