mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract runtime options manager initializer
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createRuntimeOptionsManagerRuntimeService } from "./runtime-options-manager-runtime-service";
|
||||
|
||||
test("createRuntimeOptionsManagerRuntimeService wires patch + options changed callbacks", () => {
|
||||
const patches: unknown[] = [];
|
||||
const changedSnapshots: unknown[] = [];
|
||||
const manager = createRuntimeOptionsManagerRuntimeService({
|
||||
getAnkiConfig: () => ({
|
||||
behavior: { autoUpdateNewCards: true },
|
||||
isKiku: { fieldGrouping: "manual" },
|
||||
}),
|
||||
applyAnkiPatch: (patch) => {
|
||||
patches.push(patch);
|
||||
},
|
||||
onOptionsChanged: (options) => {
|
||||
changedSnapshots.push(options);
|
||||
},
|
||||
});
|
||||
|
||||
const result = manager.setOptionValue("anki.autoUpdateNewCards", false);
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(patches.length > 0, true);
|
||||
assert.equal(changedSnapshots.length > 0, true);
|
||||
});
|
||||
17
src/core/services/runtime-options-manager-runtime-service.ts
Normal file
17
src/core/services/runtime-options-manager-runtime-service.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { RuntimeOptionsManager } from "../../runtime-options";
|
||||
import { AnkiConnectConfig, RuntimeOptionState } from "../../types";
|
||||
|
||||
export interface RuntimeOptionsManagerRuntimeDeps {
|
||||
getAnkiConfig: () => AnkiConnectConfig;
|
||||
applyAnkiPatch: (patch: Partial<AnkiConnectConfig>) => void;
|
||||
onOptionsChanged: (options: RuntimeOptionState[]) => void;
|
||||
}
|
||||
|
||||
export function createRuntimeOptionsManagerRuntimeService(
|
||||
deps: RuntimeOptionsManagerRuntimeDeps,
|
||||
): RuntimeOptionsManager {
|
||||
return new RuntimeOptionsManager(deps.getAnkiConfig, {
|
||||
applyAnkiPatch: deps.applyAnkiPatch,
|
||||
onOptionsChanged: deps.onOptionsChanged,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user