yummies 4.11.1 → 4.12.1
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/mobx/deep-observable-struct.d.ts +7 -0
- package/mobx/deep-observable-struct.d.ts.map +1 -0
- package/mobx/deep-observable-struct.js +57 -0
- package/mobx/get-mobx-administration.d.ts +4 -0
- package/mobx/get-mobx-administration.d.ts.map +1 -0
- package/mobx/get-mobx-administration.js +2 -0
- package/mobx/index.d.ts +4 -0
- package/mobx/index.d.ts.map +1 -0
- package/mobx/index.js +3 -0
- package/mobx/lazy-observe.d.ts +8 -0
- package/mobx/lazy-observe.d.ts.map +1 -0
- package/mobx/lazy-observe.js +43 -0
- package/package.json +34 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-observable-struct.d.ts","sourceRoot":"","sources":["../../src/mobx/deep-observable-struct.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBAAa,oBAAoB,CAAC,KAAK,SAAS,SAAS;IACvD,IAAI,EAAE,KAAK,CAAC;gBAEA,IAAI,EAAE,KAAK;IASvB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;CAoD5B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
+
import { typeGuard } from '../type-guard/index.js';
|
|
3
|
+
export class DeepObservableStruct {
|
|
4
|
+
data;
|
|
5
|
+
constructor(data) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
makeObservable(this, {
|
|
8
|
+
data: observable.deep,
|
|
9
|
+
set: action,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
set(newData) {
|
|
13
|
+
const stack = Object.keys(this.data).map((key) => [
|
|
14
|
+
key,
|
|
15
|
+
this.data,
|
|
16
|
+
newData,
|
|
17
|
+
]);
|
|
18
|
+
let currentIndex = 0;
|
|
19
|
+
let stackLength = stack.length;
|
|
20
|
+
while (currentIndex < stackLength) {
|
|
21
|
+
const [key, currObservableData, newData] = stack[currentIndex];
|
|
22
|
+
const newValue = newData[key];
|
|
23
|
+
const currValue = currObservableData[key];
|
|
24
|
+
currentIndex++;
|
|
25
|
+
if (key in newData) {
|
|
26
|
+
if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {
|
|
27
|
+
const newValueKeys = Object.keys(newValue);
|
|
28
|
+
Object.keys(currValue).forEach((childKey) => {
|
|
29
|
+
if (!(childKey in newValue)) {
|
|
30
|
+
delete currObservableData[key][childKey];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
newValueKeys.forEach((childKey) => {
|
|
34
|
+
const length = stack.push([
|
|
35
|
+
childKey,
|
|
36
|
+
currObservableData[key],
|
|
37
|
+
newValue,
|
|
38
|
+
]);
|
|
39
|
+
stackLength = length;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else if (newValue !== currValue) {
|
|
43
|
+
currObservableData[key] = newValue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
delete currObservableData[key];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
Object.keys(newData).forEach((newDataKey) => {
|
|
51
|
+
if (!this.data[newDataKey]) {
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
this.data[newDataKey] = newData[newDataKey];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ObservableObjectAdministration } from 'mobx/dist/internal.js';
|
|
2
|
+
import type { AnyObject } from '../utils/types.js';
|
|
3
|
+
export declare const getMobxAdministration: (context: AnyObject) => ObservableObjectAdministration;
|
|
4
|
+
//# sourceMappingURL=get-mobx-administration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-mobx-administration.d.ts","sourceRoot":"","sources":["../../src/mobx/get-mobx-administration.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,eAAO,MAAM,qBAAqB,GAChC,SAAS,SAAS,KACjB,8BAAgD,CAAC"}
|
package/mobx/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mobx/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC"}
|
package/mobx/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const lazyObserve: <TMetaData = void>({ context, property, onStart, onEnd, endDelay, }: {
|
|
2
|
+
context?: any;
|
|
3
|
+
property: any | any[];
|
|
4
|
+
onStart: () => TMetaData;
|
|
5
|
+
onEnd: (metaData: TMetaData, cleanupFn: VoidFunction) => void;
|
|
6
|
+
endDelay?: number;
|
|
7
|
+
}) => () => void;
|
|
8
|
+
//# sourceMappingURL=lazy-observe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-observe.d.ts","sourceRoot":"","sources":["../../src/mobx/lazy-observe.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,GAAI,SAAS,GAAG,IAAI,EAAE,kDAM3C;IACD,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,SAAS,CAAC;IACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,KAAK,IAAI,CAAC;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,eA4CA,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { onBecomeObserved, onBecomeUnobserved } from 'mobx';
|
|
2
|
+
export const lazyObserve = ({ context, property, onStart, onEnd, endDelay = 0, }) => {
|
|
3
|
+
let timeoutId;
|
|
4
|
+
let metaData;
|
|
5
|
+
const properties = Array.isArray(property) ? property : [property];
|
|
6
|
+
let isObserving = false;
|
|
7
|
+
const start = () => {
|
|
8
|
+
if (isObserving) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
isObserving = true;
|
|
12
|
+
if (timeoutId) {
|
|
13
|
+
clearTimeout(timeoutId);
|
|
14
|
+
timeoutId = undefined;
|
|
15
|
+
}
|
|
16
|
+
metaData = onStart();
|
|
17
|
+
};
|
|
18
|
+
const cleanup = () => {
|
|
19
|
+
if (!isObserving) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (timeoutId) {
|
|
23
|
+
clearTimeout(timeoutId);
|
|
24
|
+
timeoutId = undefined;
|
|
25
|
+
}
|
|
26
|
+
timeoutId = setTimeout(() => {
|
|
27
|
+
onEnd(metaData, cleanup);
|
|
28
|
+
timeoutId = undefined;
|
|
29
|
+
metaData = undefined;
|
|
30
|
+
}, endDelay);
|
|
31
|
+
};
|
|
32
|
+
properties.forEach((property) => {
|
|
33
|
+
if (context) {
|
|
34
|
+
onBecomeObserved(context, property, start);
|
|
35
|
+
onBecomeUnobserved(context, property, cleanup);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
onBecomeObserved(property, start);
|
|
39
|
+
onBecomeUnobserved(property, cleanup);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return cleanup;
|
|
43
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yummies",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.1",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": "js2me",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,6 +14,14 @@
|
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git://github.com/js2me/yummies"
|
|
16
16
|
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"mobx": "^6.12.4"
|
|
19
|
+
},
|
|
20
|
+
"peerDependenciesMeta": {
|
|
21
|
+
"mobx": {
|
|
22
|
+
"optional": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
17
25
|
"dependencies": {
|
|
18
26
|
"@types/insane": "^1.0.0",
|
|
19
27
|
"class-variance-authority": "^0.7.1",
|
|
@@ -186,6 +194,31 @@
|
|
|
186
194
|
"default": "./media.js",
|
|
187
195
|
"types": "./media.d.ts"
|
|
188
196
|
},
|
|
197
|
+
"./mobx/deep-observable-struct.test": {
|
|
198
|
+
"import": "./mobx/deep-observable-struct.test.js",
|
|
199
|
+
"default": "./mobx/deep-observable-struct.test.js",
|
|
200
|
+
"types": "./mobx/deep-observable-struct.test.d.ts"
|
|
201
|
+
},
|
|
202
|
+
"./mobx/deep-observable-struct": {
|
|
203
|
+
"import": "./mobx/deep-observable-struct.js",
|
|
204
|
+
"default": "./mobx/deep-observable-struct.js",
|
|
205
|
+
"types": "./mobx/deep-observable-struct.d.ts"
|
|
206
|
+
},
|
|
207
|
+
"./mobx/get-mobx-administration": {
|
|
208
|
+
"import": "./mobx/get-mobx-administration.js",
|
|
209
|
+
"default": "./mobx/get-mobx-administration.js",
|
|
210
|
+
"types": "./mobx/get-mobx-administration.d.ts"
|
|
211
|
+
},
|
|
212
|
+
"./mobx": {
|
|
213
|
+
"import": "./mobx/index.js",
|
|
214
|
+
"default": "./mobx/index.js",
|
|
215
|
+
"types": "./mobx/index.d.ts"
|
|
216
|
+
},
|
|
217
|
+
"./mobx/lazy-observe": {
|
|
218
|
+
"import": "./mobx/lazy-observe.js",
|
|
219
|
+
"default": "./mobx/lazy-observe.js",
|
|
220
|
+
"types": "./mobx/lazy-observe.d.ts"
|
|
221
|
+
},
|
|
189
222
|
"./ms": {
|
|
190
223
|
"import": "./ms.js",
|
|
191
224
|
"default": "./ms.js",
|