MCPcopy Index your code
hub / github.com/ether/etherpad / makeChangesetTracker

Function makeChangesetTracker

src/static/js/changesettracker.ts:31–203  ·  view source on GitHub ↗
(scheduler, apool, aceCallbacksProvider)

Source from the content-addressed store, hash-verified

29import {MergingOpAssembler} from "./MergingOpAssembler";
30
31const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
32 // latest official text from server
33 let baseAText = makeAText('\n');
34 // changes applied to baseText that have been submitted
35 let submittedChangeset = null;
36 // changes applied to submittedChangeset since it was prepared
37 let userChangeset = identity(1);
38 // is the changesetTracker enabled
39 let tracking = false;
40 // stack state flag so that when we change the rep we don't
41 // handle the notification recursively. When setting, always
42 // unset in a "finally" block. When set to true, the setter
43 // takes change of userChangeset.
44 let applyingNonUserChanges = false;
45
46 let changeCallback = null;
47
48 let changeCallbackTimeout = null;
49
50 const setChangeCallbackTimeout = () => {
51 // can call this multiple times per call-stack, because
52 // we only schedule a call to changeCallback if it exists
53 // and if there isn't a timeout already scheduled.
54 if (changeCallback && changeCallbackTimeout == null) {
55 changeCallbackTimeout = scheduler.setTimeout(() => {
56 try {
57 changeCallback();
58 } catch (pseudoError) {
59 // as empty as my soul
60 } finally {
61 changeCallbackTimeout = null;
62 }
63 }, 0);
64 }
65 };
66
67 let self;
68 return self = {
69 isTracking: () => tracking,
70 setBaseText: (text) => {
71 self.setBaseAttributedText(makeAText(text), null);
72 },
73 setBaseAttributedText: (atext, apoolJsonObj) => {
74 aceCallbacksProvider.withCallbacks('setBaseText', (callbacks) => {
75 tracking = true;
76 baseAText = cloneAText(atext);
77 if (apoolJsonObj) {
78 const wireApool = (new AttributePool()).fromJsonable(apoolJsonObj);
79 baseAText.attribs = moveOpsToNewPool(baseAText.attribs, wireApool, apool);
80 }
81 submittedChangeset = null;
82 userChangeset = identity(atext.text.length);
83 applyingNonUserChanges = true;
84 try {
85 callbacks.setDocumentAttributedText(atext);
86 } finally {
87 applyingNonUserChanges = false;
88 }

Callers 1

Ace2InnerFunction · 0.85

Calls 15

makeATextFunction · 0.90
identityFunction · 0.90
cloneATextFunction · 0.90
moveOpsToNewPoolFunction · 0.90
isIdentityFunction · 0.90
composeFunction · 0.90
applyToATextFunction · 0.90
followFunction · 0.90
unpackFunction · 0.90
packFunction · 0.90
checkRepFunction · 0.90
newLenFunction · 0.90

Tested by

no test coverage detected