-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement Dependencies feature
- Loading branch information
1 parent
45f7176
commit 53dbc14
Showing
20 changed files
with
337 additions
and
98 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
apps/web/src/core/file-system/events.ts → apps/web/src/core/file-system/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { AppReducer } from "@/store/reducer"; | ||
import * as Option from "@effect/data/Option"; | ||
|
||
function toggleDependencies(): AppReducer { | ||
return function (event, state) { | ||
if ( | ||
event.action === "toggle_circular" || | ||
event.action === "toggle_builtin" || | ||
event.action === "toggle_thirdparty" | ||
) { | ||
const target = event.action.split("_")[1]; | ||
|
||
return Option.some({ | ||
data: state.data, | ||
ui: { | ||
...state.ui, | ||
network: { | ||
dependencies: { | ||
...state.ui.network.dependencies, | ||
[target]: { | ||
active: event.payload.enabled, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
return Option.none(); | ||
}; | ||
} | ||
|
||
export const networkReducers = [toggleDependencies()]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { AppState, storeDefaultValue } from "@/store/state"; | ||
import { AppStore } from "@/store/store"; | ||
import { BehaviorSubject } from "rxjs"; | ||
import { describe, expect, test } from "vitest"; | ||
import { toggleDependencies } from "./toggle-dependencies"; | ||
import { toPromise } from "../utils"; | ||
import { networkReducers } from "./reducers"; | ||
|
||
describe("When interacting with network dependencies", () => { | ||
describe.each([ | ||
{ target: "circular" }, | ||
{ target: "builtin" }, | ||
{ target: "thirdparty" }, | ||
] as const)("When enabling $target dependencies", ({ target }) => { | ||
test(`Should register the activated state for ${target} deps`, async () => { | ||
const appStore = new AppStore( | ||
new BehaviorSubject<AppState>(storeDefaultValue), | ||
networkReducers | ||
); | ||
|
||
const emittedEvents: string[] = []; | ||
const subscription = appStore.events$.subscribe((events) => { | ||
emittedEvents.push(events.action); | ||
}); | ||
const dispatchAction = toggleDependencies(appStore); | ||
|
||
dispatchAction({ target }); | ||
|
||
const { ui: uiState1 } = await toPromise(appStore.store$); | ||
|
||
expect(uiState1).toEqual({ | ||
...storeDefaultValue.ui, | ||
network: { | ||
dependencies: { | ||
...storeDefaultValue.ui.network.dependencies, | ||
[target]: { | ||
active: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
dispatchAction({ target }); | ||
|
||
const { ui: uiState2 } = await toPromise(appStore.store$); | ||
|
||
expect(uiState2).toEqual({ | ||
...storeDefaultValue.ui, | ||
network: { | ||
dependencies: { | ||
...storeDefaultValue.ui.network.dependencies, | ||
[target]: { | ||
active: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const appEvent = `toggle_${target}`; | ||
expect(emittedEvents).toEqual([appEvent, appEvent]); | ||
|
||
subscription.unsubscribe(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { AppStore } from "@/store/store"; | ||
|
||
export function toggleDependencies(appStore: AppStore) { | ||
return function (params: { target: "circular" | "builtin" | "thirdparty" }) { | ||
const networkDependency = | ||
appStore.getState().ui.network.dependencies[params.target]; | ||
|
||
appStore.dispatch( | ||
{ | ||
action: `toggle_${params.target}`, | ||
payload: { | ||
enabled: !networkDependency.active, | ||
}, | ||
}, | ||
{ notify: true } | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Observable } from "rxjs"; | ||
|
||
export function toPromise<T>(observable: Observable<T>): Promise<T> { | ||
return new Promise((resolve) => { | ||
const subscription = observable.subscribe((data) => { | ||
resolve(data); | ||
setTimeout(() => { | ||
subscription.unsubscribe(); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.