-
Notifications
You must be signed in to change notification settings - Fork 451
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
receive op data had split more times with not local? #396
Comments
Could you please elaborate on your use case? Why is it important to have these delivered as a single object? |
i use sharedb with draft js,when the op is split and setState,will not work,ex |
i have solve it,i solution is set the uuid and op_size to op model,when receive by other side,i get uuid and op_size to merge the ops and do one setState,it work!any best solution? |
Glad to hear you solved it. Honestly off the top of my head I'm not sure there's any (easy) way around it. If you're interested, here's the code that's responsible for that behaviour: Lines 584 to 620 in c711cfc
You'll see it performs this check: if (!source && this.type === types.defaultType && op.op.length > 1) and then "shatters" the op. So one potential way around this would be to register second You could also try switching to the The final thing — which I think is what you've landed on? — is to buffer incoming ops and batch them together. Of course you could always raise a pull request to disable this behaviour using some sort of config flag! |
thx |
This change adds two events: - `before op batch` - fired once before any set of ops is applied. - `op batch` - fired once after any set of ops is applied. This may follow multiple `op` events if the op had multiple `json0` components This is a non-breaking change that should allow clients to process ops in their entirety. There has already been some discussion around this: - #129 - #396 This is a much simpler approach than the existing pull request. Here we try not to change existing behaviour, and only add new, non-breaking events. Motivation for such an event would include clients applying some form of validation logic, which doesn't make sense if an op is shattered. For example, consider a client that wants to ensure a field `mustBePresent` is always populated: ```js doc.on('op', () => { if (!doc.data.mustBePresent) throw new Error('invalid'); }); remoteDoc.submitOp([ {p: ['mustBePresent', 0], sd: 'existing value'}, {p: ['mustBePresent', 0], si: 'new value'}, ]); ``` In the above example, the submitted op is clearly attempting to perform a replacement. However, the receiving `doc` only receives this replacement in parts, so it looks like the document reaches an invalid state, when actually the submitted op is perfectly valid. In this case we `throw`, but we could have also attempted to populate with a default value, which could interfere with the desired value. This change fixes the above issue, because now we can just listen for the `op batch` event, and consider the document once all the components of a given op have been applied.
This change adds two events: - `before op batch` - fired once before any set of ops is applied. - `op batch` - fired once after any set of ops is applied. This may follow multiple `op` events if the op had multiple `json0` components This is a non-breaking change that should allow clients to process ops in their entirety. There has already been some discussion around this: - #129 - #396 This is a much simpler approach than the existing pull request. Here we try not to change existing behaviour, and only add new, non-breaking events. Motivation for such an event would include clients applying some form of validation logic, which doesn't make sense if an op is shattered. For example, consider a client that wants to ensure a field `mustBePresent` is always populated: ```js doc.on('op', () => { if (!doc.data.mustBePresent) throw new Error('invalid'); }); remoteDoc.submitOp([ {p: ['mustBePresent', 0], sd: 'existing value'}, {p: ['mustBePresent', 0], si: 'new value'}, ]); ``` In the above example, the submitted op is clearly attempting to perform a replacement. However, the receiving `doc` only receives this replacement in parts, so it looks like the document reaches an invalid state, when actually the submitted op is perfectly valid. In this case we `throw`, but we could have also attempted to populate with a default value, which could interfere with the desired value. This change fixes the above issue, because now we can just listen for the `op batch` event, and consider the document once all the components of a given op have been applied.
@aeroyu this should now be fixed in |
thx , great help to me |
i submit op like
[
{
"sd": "checkable-list-item",
"p": [
"blocks",
0,
"type",
0
]
},
{
"si": "unstyled",
"p": [
"blocks",
0,
"type",
0
]
}
]
and local receive op event op is the same with send data,
but with other client receive op,has split two time,[
{
"sd": "checkable-list-item",
"p": [
"blocks",
0,
"type",
0
]
}] and [{
"si": "unstyled",
"p": [
"blocks",
0,
"type",
0
]
}
]
how can i receive op normal
The text was updated successfully, but these errors were encountered: