diff --git a/typescript/packages/common-runner/src/doc.ts b/typescript/packages/common-runner/src/doc.ts index af31a9956..f1e68068d 100644 --- a/typescript/packages/common-runner/src/doc.ts +++ b/typescript/packages/common-runner/src/doc.ts @@ -104,14 +104,6 @@ export type DocImpl = { */ updates(callback: (value: T, path: PropertyKey[]) => void): Cancel; - /** - * Add callback for updates. Will call immediately with current value. - * - * @param callback - Callback to call on updates. - * @returns Cancel function. - */ - sink(callback: (value: T, path: PropertyKey[]) => void): Cancel; - /** * Freeze cell, making it read-only. * @@ -263,11 +255,6 @@ export function getDoc(value?: T, cause?: any, space?: Space): DocImpl { callbacks.add(callback); return () => callbacks.delete(callback); }, - sink: (callback: (value: T, path: PropertyKey[]) => void) => { - callback(value as T, []); - callbacks.add(callback); - return () => callbacks.delete(callback); - }, getAtPath: (path: PropertyKey[]) => getValueAtPath(value, path), setAtPath: (path: PropertyKey[], newValue: any, log?: ReactivityLog) => { if (readOnly) throw new Error("Cell is read-only"); diff --git a/typescript/packages/common-runner/src/reactivity.ts b/typescript/packages/common-runner/src/reactivity.ts index d42eaf70f..3c5ddeae7 100644 --- a/typescript/packages/common-runner/src/reactivity.ts +++ b/typescript/packages/common-runner/src/reactivity.ts @@ -1,6 +1,5 @@ import { Cancel, isCancel, noOp } from "./cancel.js"; import { Cell, isCell } from "./cell.js"; -import { DocImpl, isDoc } from "./doc.js"; /** * Effect that runs a callback when the value changes. The callback is also @@ -12,12 +11,10 @@ import { DocImpl, isDoc } from "./doc.js"; * @returns {function} - A function to cancel the effect. */ export const effect = ( - value: Cell | DocImpl | T, + value: Cell | T, callback: (value: T) => Cancel | undefined | void, ): Cancel => { - if (isDoc(value)) value = value.asCell(); - - if (isCell(value) || isDoc(value)) { + if (isCell(value)) { return value.sink(callback); } else { const cancel = callback(value as T); diff --git a/typescript/packages/common-runner/test/cell.test.ts b/typescript/packages/common-runner/test/cell.test.ts index d20a2e26f..becbacdfd 100644 --- a/typescript/packages/common-runner/test/cell.test.ts +++ b/typescript/packages/common-runner/test/cell.test.ts @@ -45,16 +45,16 @@ describe("Cell", () => { expect(c.get()).toEqual({ a: { b: { c: 100 } } }); }); - it("should sink changes", () => { + it("should call updates callback when value changes", () => { const c = getDoc(0); const values: number[] = []; - const unsink = c.sink((value) => values.push(value)); + const unsink = c.updates((value) => values.push(value)); c.send(1); c.send(2); c.send(3); unsink(); c.send(4); - expect(values).toEqual([0, 1, 2, 3]); + expect(values).toEqual([1, 2, 3]); }); });