Skip to content

Commit

Permalink
[keep it simple] do not inject merge to cell -- just use the global m…
Browse files Browse the repository at this point in the history
…erge

- 也许用多线程的 C 实现时,cell 才应该有自己的局部 merge 函数
  • Loading branch information
xieyuheng committed Jun 24, 2024
1 parent 3d1f8b7 commit 08fefb7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
14 changes: 1 addition & 13 deletions src/cell/Cell.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import { merge } from "../merge/index.js"
import type { Propagator } from "../propagator/index.js"
import { nothing, type Nothing } from "./Nothing.js"

export type Merge<T> = (content: T | Nothing, increment: any) => T | Nothing

export type Cell<T> = {
"@type": "Cell"
content: T | Nothing
propagators: Array<Propagator>
merge: Merge<T>
}

export function Cell<T>(
content?: T,
options: {
merge: Merge<T>
} = {
merge,
},
): Cell<T> {
export function Cell<T>(content?: T): Cell<T> {
return {
"@type": "Cell",
content: content || nothing,
propagators: [],
merge: options.merge,
}
}
4 changes: 2 additions & 2 deletions src/cell/put.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { detectMergeConflict } from "../merge/index.js"
import { detectMergeConflict, merge } from "../merge/index.js"
import { schedule } from "../scheduler/index.js"
import { type Cell } from "./Cell.js"

export function put<T>(cell: Cell<T>, increment?: T): void {
const newContent = cell.merge(cell.content, increment)
const newContent = merge(cell.content, increment)
if (newContent === cell.content) {
return
}
Expand Down

0 comments on commit 08fefb7

Please sign in to comment.