mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-13 00:10:47 +08:00
feat: support per-bot workspace switching
This commit is contained in:
parent
adcace3512
commit
44dd50216a
64 changed files with 3878 additions and 712 deletions
28
plugin-src/client/workspace-snapshot-fence.js
Normal file
28
plugin-src/client/workspace-snapshot-fence.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import * as React from 'react';
|
||||
|
||||
/** Keep every full-snapshot response ordered behind the latest client mutation. */
|
||||
export function useWorkspaceSnapshotFence() {
|
||||
const state = React.useRef({ version: 0, pendingMutations: 0 });
|
||||
return React.useMemo(() => Object.freeze({
|
||||
beginStatus() {
|
||||
return state.current.pendingMutations === 0 ? state.current.version : null;
|
||||
},
|
||||
canCommitStatus(version) {
|
||||
return version !== null
|
||||
&& state.current.pendingMutations === 0
|
||||
&& state.current.version === version;
|
||||
},
|
||||
beginMutation() {
|
||||
state.current.pendingMutations += 1;
|
||||
state.current.version += 1;
|
||||
return state.current.version;
|
||||
},
|
||||
canCommitMutation(version) {
|
||||
return state.current.version === version;
|
||||
},
|
||||
endMutation() {
|
||||
state.current.pendingMutations = Math.max(0, state.current.pendingMutations - 1);
|
||||
return state.current.pendingMutations === 0;
|
||||
},
|
||||
}), []);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue