-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LiveList.set #147
LiveList.set #147
Changes from all commits
c71bec2
5b3d2e6
ff7527d
f2693e9
5c2ce41
70a0b22
12543c1
99ad3c8
4202337
92f021c
e4ad97b
b69aa07
df40589
50de49e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Op, OpType, SerializedCrdt } from "./live"; | ||
import { CreateOp, Op, OpType, SerializedCrdt } from "./live"; | ||
import { StorageUpdate } from "./types"; | ||
|
||
export type ApplyResult = | ||
|
@@ -12,6 +12,11 @@ export interface Doc { | |
getItem: (id: string) => AbstractCrdt | undefined; | ||
addItem: (id: string, item: AbstractCrdt) => void; | ||
deleteItem: (id: string) => void; | ||
/** | ||
* - Send ops to WebSocket servers | ||
* - Add reverse operations to the undo/redo stack | ||
* - Send updates to room subscribers | ||
*/ | ||
dispatch: ( | ||
ops: Op[], | ||
reverseOps: Op[], | ||
|
@@ -103,13 +108,7 @@ export abstract class AbstractCrdt { | |
/** | ||
* @internal | ||
*/ | ||
abstract _attachChild( | ||
id: string, | ||
key: string, | ||
crdt: AbstractCrdt, | ||
opId: string, | ||
isLocal: boolean | ||
): ApplyResult; | ||
abstract _attachChild(op: CreateOp, isLocal: boolean): ApplyResult; | ||
|
||
/** | ||
* @internal | ||
|
@@ -130,7 +129,12 @@ export abstract class AbstractCrdt { | |
/** | ||
* @internal | ||
*/ | ||
abstract _serialize(parentId: string, parentKey: string, doc?: Doc): Op[]; | ||
abstract _serialize( | ||
parentId: string, | ||
parentKey: string, | ||
doc?: Doc, | ||
intent?: "set" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably still just my lack of understanding, but I don't have a good intuition yet for why you would have to provide the intent during serialization (more or less as a "mode"). So why do you have to specify the intent at the moment you invoke “serialize”? Does the default "create" op mean to "create and insert", and "create with set intent" mean to "create and replace"? If so, could there be long term maintainability benefits to using different named ops for these actions instead of adding a "mode" to the existing create op? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a great question :) As discussed yesterday, storage operations would be easier to reason about if they were always associated with a specific LiveStructure type. For example,
We could have different operations for each of these methods. The more I think about it, the more I think we should go in that direction despite the issues above. Especially after introducing the "set intent". But since these operations are internal messages, I would wait to have more operations and data structures (LiveText, LiveBlob, etc) to refactor to a more unified solution. I just want more examples to be sure that this refactoring is really the way to go. So I share your feeling :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, perfect! Then I think we're on the same page here. We can use this API for now, and refactor this later when we have more data points and a better understanding of how to structure this 👍 Thanks for the context. |
||
): Op[]; | ||
|
||
/** | ||
* @internal | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR directly, but what does
isLocal
signify?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isLocal = true
means the operation has been created locally by the current client (via undo, redo or re-applying offline ops).isLocal = false
means the operation has been created by another client and received from the server.