@difizen/libro-shared-model 0.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/es/api.d.ts +639 -0
- package/es/api.d.ts.map +1 -0
- package/es/api.js +91 -0
- package/es/index.d.ts +4 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +3 -0
- package/es/utils.d.ts +18 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +41 -0
- package/es/ymodels.d.ts +656 -0
- package/es/ymodels.d.ts.map +1 -0
- package/es/ymodels.js +1778 -0
- package/package.json +57 -0
- package/src/api.ts +743 -0
- package/src/index.ts +3 -0
- package/src/utils.ts +46 -0
- package/src/ymodels.ts +1603 -0
package/src/index.ts
ADDED
package/src/utils.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type * as Y from 'yjs';
|
|
2
|
+
|
|
3
|
+
import type * as models from './api.js';
|
|
4
|
+
|
|
5
|
+
export function convertYMapEventToMapChange(
|
|
6
|
+
yMapEvent: Y.YMapEvent<any>,
|
|
7
|
+
): models.MapChange {
|
|
8
|
+
const changes = new Map();
|
|
9
|
+
yMapEvent.changes.keys.forEach((event, key) => {
|
|
10
|
+
changes.set(key, {
|
|
11
|
+
action: event.action,
|
|
12
|
+
oldValue: event.oldValue,
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
newValue: this.ymeta.get(key),
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
return changes;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a mutual exclude function with the following property:
|
|
23
|
+
*
|
|
24
|
+
* ```js
|
|
25
|
+
* const mutex = createMutex()
|
|
26
|
+
* mutex(() => {
|
|
27
|
+
* // This function is immediately executed
|
|
28
|
+
* mutex(() => {
|
|
29
|
+
* // This function is not executed, as the mutex is already active.
|
|
30
|
+
* })
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const createMutex = (): ((f: () => void) => void) => {
|
|
35
|
+
let token = true;
|
|
36
|
+
return (f: any): void => {
|
|
37
|
+
if (token) {
|
|
38
|
+
token = false;
|
|
39
|
+
try {
|
|
40
|
+
f();
|
|
41
|
+
} finally {
|
|
42
|
+
token = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|