Аргументы для функции фильтрации
Содержит метаданные сообщения и патч для проверки условий фильтра.
import { ReactionRegistry, createReactionsChain } from "../index"import type { Update, ExtractValues } from "../../context/index.t"import { test, expect } from "bun:test"import type { JsonPatch, MetaDataMessage } from "../../message"type Ctx = { value: { type: "number"; required: true } name: { type: "string"; required: true } isActive: { type: "boolean"; required: true } tags: { type: "array"; required: true }}type State = "idle" | "active" | "error"test("Создание уникальных реакций", () => { const registry = new ReactionRegistry<Ctx, State>((reaction) => [ [ ["idle", "active"], reaction({ title: "inc" }) .filter({ tag: "test", op: "replace", path: "/context", value: 1, }) .equal(({ update, context }) => update({ value: context.value + 1 })), ], [ ["error"], reaction({ title: "reset" }) .filter({ tag: "any" }) .equal(({ update }) => update({ value: 0 })), ], ]) const all = registry.getAllReactions() expect(all?.length, "уникальные реакции").toBe(2) expect(all?.[0]?.title, "первая реакция").toBe("inc") expect(all?.[1]?.title, "вторая реакция").toBe("reset")}) Copy
import { ReactionRegistry, createReactionsChain } from "../index"import type { Update, ExtractValues } from "../../context/index.t"import { test, expect } from "bun:test"import type { JsonPatch, MetaDataMessage } from "../../message"type Ctx = { value: { type: "number"; required: true } name: { type: "string"; required: true } isActive: { type: "boolean"; required: true } tags: { type: "array"; required: true }}type State = "idle" | "active" | "error"test("Создание уникальных реакций", () => { const registry = new ReactionRegistry<Ctx, State>((reaction) => [ [ ["idle", "active"], reaction({ title: "inc" }) .filter({ tag: "test", op: "replace", path: "/context", value: 1, }) .equal(({ update, context }) => update({ value: context.value + 1 })), ], [ ["error"], reaction({ title: "reset" }) .filter({ tag: "any" }) .equal(({ update }) => update({ value: 0 })), ], ]) const all = registry.getAllReactions() expect(all?.length, "уникальные реакции").toBe(2) expect(all?.[0]?.title, "первая реакция").toBe("inc") expect(all?.[1]?.title, "вторая реакция").toBe("reset")})
Метаданные сообщения (тег, индекс, временная метка)
JSON Patch с операцией, путем и значением
Аргументы для функции фильтрации
Содержит метаданные сообщения и патч для проверки условий фильтра.
Example