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,9 +13,13 @@ const discoveredUpdateVersionInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||
|
||||
return createSyncBox<{ version: string; updateChannel: UpdateChannel } | null>(
|
||||
"discovered-update-version",
|
||||
);
|
||||
return createSyncBox<
|
||||
| { version: string; updateChannel: UpdateChannel }
|
||||
| null
|
||||
>(
|
||||
"discovered-update-version",
|
||||
null,
|
||||
);
|
||||
},
|
||||
|
||||
injectionToken: syncBoxInjectionToken,
|
||||
|
||||
@ -12,7 +12,7 @@ const progressOfUpdateDownloadInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||
|
||||
return createSyncBox<number>("progress-of-update-download");
|
||||
return createSyncBox("progress-of-update-download", 0);
|
||||
},
|
||||
|
||||
injectionToken: syncBoxInjectionToken,
|
||||
|
||||
@ -12,7 +12,7 @@ const updateIsBeingDownloadedInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||
|
||||
return createSyncBox<boolean>("update-is-being-downloaded");
|
||||
return createSyncBox("update-is-being-downloaded", false);
|
||||
},
|
||||
|
||||
injectionToken: syncBoxInjectionToken,
|
||||
|
||||
@ -12,7 +12,7 @@ const updatesAreBeingDiscoveredInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const createSyncBox = di.inject(createSyncBoxInjectable);
|
||||
|
||||
return createSyncBox<boolean>("updates-are-being-discovered");
|
||||
return createSyncBox("updates-are-being-discovered", false);
|
||||
},
|
||||
|
||||
injectionToken: syncBoxInjectionToken,
|
||||
|
||||
@ -17,9 +17,11 @@ const createSyncBoxInjectable = getInjectable({
|
||||
const sendToChannel = di.inject(sendToChannelInjectionToken);
|
||||
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);
|
||||
|
||||
state.set(initialValue);
|
||||
|
||||
return {
|
||||
id,
|
||||
|
||||
|
||||
@ -126,12 +126,12 @@ describe("sync-box", () => {
|
||||
}, true);
|
||||
});
|
||||
|
||||
it("does not know initial value in main", () => {
|
||||
expect(valueInMain).toBeUndefined();
|
||||
it("knows initial value in main", () => {
|
||||
expect(valueInMain).toBe("some-initial-value");
|
||||
});
|
||||
|
||||
it("does not know initial value in renderer", () => {
|
||||
expect(valueInRenderer).toBeUndefined();
|
||||
it("knows initial value in renderer", () => {
|
||||
expect(valueInRenderer).toBe("some-initial-value");
|
||||
});
|
||||
|
||||
describe("when value is set from main", () => {
|
||||
@ -174,6 +174,6 @@ const someInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
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