reactronic 0.22.300 → 0.22.303
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/README.md +20 -20
- package/build/dist/source/Buffer.d.ts +2 -2
- package/build/dist/source/Buffer.js +1 -1
- package/build/dist/source/Logging.d.ts +6 -6
- package/build/dist/source/Ref.d.ts +1 -1
- package/build/dist/source/Ref.js +2 -2
- package/build/dist/source/Rx.d.ts +3 -2
- package/build/dist/source/Rx.js +10 -9
- package/build/dist/source/api.d.ts +3 -3
- package/build/dist/source/api.js +6 -6
- package/build/dist/source/impl/Changeset.d.ts +60 -0
- package/build/dist/source/impl/Changeset.js +361 -0
- package/build/dist/source/impl/Data.d.ts +20 -15
- package/build/dist/source/impl/Data.js +20 -11
- package/build/dist/source/impl/Hooks.d.ts +43 -14
- package/build/dist/source/impl/Hooks.js +89 -49
- package/build/dist/source/impl/Journal.d.ts +4 -4
- package/build/dist/source/impl/Journal.js +57 -46
- package/build/dist/source/impl/Meta.d.ts +3 -3
- package/build/dist/source/impl/Meta.js +7 -7
- package/build/dist/source/impl/Monitor.d.ts +2 -2
- package/build/dist/source/impl/Monitor.js +1 -1
- package/build/dist/source/impl/Operation.d.ts +8 -8
- package/build/dist/source/impl/Operation.js +124 -123
- package/build/dist/source/impl/Transaction.d.ts +2 -2
- package/build/dist/source/impl/Transaction.js +23 -23
- package/package.json +1 -1
- package/build/dist/source/impl/Snapshot.d.ts +0 -60
- package/build/dist/source/impl/Snapshot.js +0 -353
|
@@ -1,24 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Hooks = exports.OptionsImpl = exports.
|
|
3
|
+
exports.Hooks = exports.OptionsImpl = exports.ReactiveArray = exports.ReactiveObject = void 0;
|
|
4
4
|
const Utils_1 = require("../util/Utils");
|
|
5
|
+
const Sealant_1 = require("../util/Sealant");
|
|
5
6
|
const Dbg_1 = require("../util/Dbg");
|
|
6
7
|
const Options_1 = require("../Options");
|
|
7
8
|
const Data_1 = require("./Data");
|
|
8
|
-
const
|
|
9
|
-
class
|
|
9
|
+
const Changeset_1 = require("./Changeset");
|
|
10
|
+
class ReactiveObject {
|
|
10
11
|
constructor() {
|
|
11
12
|
const proto = new.target.prototype;
|
|
12
13
|
const initial = Data_1.Meta.getFrom(proto, Data_1.Meta.Initial);
|
|
13
|
-
const h = Hooks.
|
|
14
|
+
const h = Hooks.createHandleForReactiveObject(proto, this, initial, new.target.name);
|
|
14
15
|
return h.proxy;
|
|
15
16
|
}
|
|
16
17
|
[Symbol.toStringTag]() {
|
|
17
|
-
const h = Data_1.Meta.get(this, Data_1.Meta.
|
|
18
|
-
return
|
|
18
|
+
const h = Data_1.Meta.get(this, Data_1.Meta.Handle);
|
|
19
|
+
return Changeset_1.Dump.obj(h);
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
exports.
|
|
22
|
+
exports.ReactiveObject = ReactiveObject;
|
|
23
|
+
class ReactiveArray extends ReactiveObject {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.a = new Array();
|
|
27
|
+
}
|
|
28
|
+
get length() { return this.a.length; }
|
|
29
|
+
set length(n) { this.a.length = n; }
|
|
30
|
+
get(n) { return this.a[n]; }
|
|
31
|
+
set(n, item) { this.mutable[n] = item; }
|
|
32
|
+
toString() { return this.a.toString(); }
|
|
33
|
+
toLocaleString() { return this.a.toLocaleString(); }
|
|
34
|
+
pop() { return this.mutable.pop(); }
|
|
35
|
+
push(...items) { return this.mutable.push(...items); }
|
|
36
|
+
concat(...items) { return this.a.concat(...items); }
|
|
37
|
+
join(separator) { return this.a.join(separator); }
|
|
38
|
+
reverse() { return this.mutable.reverse(); }
|
|
39
|
+
shift() { return this.mutable.shift(); }
|
|
40
|
+
slice(start, end) { return this.a.slice(start, end); }
|
|
41
|
+
sort(compareFn) { this.mutable.sort(compareFn); return this; }
|
|
42
|
+
splice(start, deleteCount, ...items) { return this.mutable.splice(start, deleteCount, ...items); }
|
|
43
|
+
unshift(...items) { return this.mutable.unshift(...items); }
|
|
44
|
+
indexOf(searchElement, fromIndex) { return this.a.indexOf(searchElement, fromIndex); }
|
|
45
|
+
lastIndexOf(searchElement, fromIndex) { return this.a.lastIndexOf(searchElement, fromIndex); }
|
|
46
|
+
every(predicate, thisArg) { return this.a.every(predicate, thisArg); }
|
|
47
|
+
some(predicate, thisArg) { return this.a.some(predicate, thisArg); }
|
|
48
|
+
forEach(callbackfn, thisArg) { return this.a.forEach(callbackfn, thisArg); }
|
|
49
|
+
map(callbackfn, thisArg) { return this.a.map(callbackfn, thisArg); }
|
|
50
|
+
filter(predicate, thisArg) { return this.a.filter(predicate, thisArg); }
|
|
51
|
+
reduce(callbackfn, initialValue) { return this.a.reduce(callbackfn, initialValue); }
|
|
52
|
+
reduceRight(callbackfn, initialValue) { return this.a.reduceRight(callbackfn, initialValue); }
|
|
53
|
+
get mutable() {
|
|
54
|
+
const createCopy = this.a[Sealant_1.Sealant.CreateCopy];
|
|
55
|
+
if (createCopy)
|
|
56
|
+
return this.a = createCopy.call(this.a);
|
|
57
|
+
return this.a;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ReactiveArray = ReactiveArray;
|
|
22
61
|
const DEFAULT_OPTIONS = Object.freeze({
|
|
23
62
|
kind: Options_1.Kind.Plain,
|
|
24
63
|
standalone: false,
|
|
@@ -60,32 +99,32 @@ class Hooks {
|
|
|
60
99
|
}
|
|
61
100
|
get(h, m, receiver) {
|
|
62
101
|
let result;
|
|
63
|
-
const
|
|
64
|
-
result =
|
|
102
|
+
const os = Changeset_1.Changeset.current().getRelevantSnapshot(h, m);
|
|
103
|
+
result = os.data[m];
|
|
65
104
|
if (result instanceof Data_1.Subscription && !result.isOperation) {
|
|
66
|
-
|
|
105
|
+
Changeset_1.Changeset.markUsed(result, os, m, h, Options_1.Kind.Plain, false);
|
|
67
106
|
result = result.content;
|
|
68
107
|
}
|
|
69
|
-
else if (m === Data_1.Meta.
|
|
108
|
+
else if (m === Data_1.Meta.Handle) {
|
|
70
109
|
}
|
|
71
110
|
else
|
|
72
111
|
result = Reflect.get(h.data, m, receiver);
|
|
73
112
|
return result;
|
|
74
113
|
}
|
|
75
114
|
set(h, m, value, receiver) {
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
let curr =
|
|
79
|
-
if (curr !== undefined || (
|
|
115
|
+
const os = Changeset_1.Changeset.edit().getEditableSnapshot(h, m, value);
|
|
116
|
+
if (os !== Changeset_1.EMPTY_SNAPSHOT) {
|
|
117
|
+
let curr = os.data[m];
|
|
118
|
+
if (curr !== undefined || (os.former.snapshot.changeset === Changeset_1.EMPTY_SNAPSHOT.changeset && (m in h.data) === false)) {
|
|
80
119
|
if (curr === undefined || curr.content !== value || Hooks.sensitivity) {
|
|
81
120
|
const existing = curr === null || curr === void 0 ? void 0 : curr.content;
|
|
82
|
-
if (
|
|
83
|
-
curr =
|
|
84
|
-
|
|
121
|
+
if (os.former.snapshot.data[m] === curr) {
|
|
122
|
+
curr = os.data[m] = new Data_1.Subscription(value);
|
|
123
|
+
Changeset_1.Changeset.markEdited(existing, value, true, os, m, h);
|
|
85
124
|
}
|
|
86
125
|
else {
|
|
87
126
|
curr.content = value;
|
|
88
|
-
|
|
127
|
+
Changeset_1.Changeset.markEdited(existing, value, true, os, m, h);
|
|
89
128
|
}
|
|
90
129
|
}
|
|
91
130
|
}
|
|
@@ -97,42 +136,42 @@ class Hooks {
|
|
|
97
136
|
return true;
|
|
98
137
|
}
|
|
99
138
|
has(h, m) {
|
|
100
|
-
const
|
|
101
|
-
return m in
|
|
139
|
+
const os = Changeset_1.Changeset.current().getRelevantSnapshot(h, m);
|
|
140
|
+
return m in os.data || m in h.data;
|
|
102
141
|
}
|
|
103
142
|
getOwnPropertyDescriptor(h, m) {
|
|
104
|
-
const
|
|
105
|
-
const pd = Reflect.getOwnPropertyDescriptor(
|
|
143
|
+
const os = Changeset_1.Changeset.current().getRelevantSnapshot(h, m);
|
|
144
|
+
const pd = Reflect.getOwnPropertyDescriptor(os.data, m);
|
|
106
145
|
if (pd)
|
|
107
146
|
pd.configurable = pd.writable = true;
|
|
108
147
|
return pd;
|
|
109
148
|
}
|
|
110
149
|
ownKeys(h) {
|
|
111
|
-
const
|
|
150
|
+
const os = Changeset_1.Changeset.current().getRelevantSnapshot(h, Data_1.Meta.Handle);
|
|
112
151
|
const result = [];
|
|
113
|
-
for (const m of Object.getOwnPropertyNames(
|
|
114
|
-
const value =
|
|
152
|
+
for (const m of Object.getOwnPropertyNames(os.data)) {
|
|
153
|
+
const value = os.data[m];
|
|
115
154
|
if (!(value instanceof Data_1.Subscription) || !value.isOperation)
|
|
116
155
|
result.push(m);
|
|
117
156
|
}
|
|
118
157
|
return result;
|
|
119
158
|
}
|
|
120
|
-
static decorateData(
|
|
121
|
-
if (
|
|
159
|
+
static decorateData(reactive, proto, m) {
|
|
160
|
+
if (reactive) {
|
|
122
161
|
const get = function () {
|
|
123
|
-
const h = Hooks.
|
|
124
|
-
return Hooks.
|
|
162
|
+
const h = Hooks.acquireHandle(this);
|
|
163
|
+
return Hooks.handler.get(h, m, this);
|
|
125
164
|
};
|
|
126
165
|
const set = function (value) {
|
|
127
|
-
const h = Hooks.
|
|
128
|
-
return Hooks.
|
|
166
|
+
const h = Hooks.acquireHandle(this);
|
|
167
|
+
return Hooks.handler.set(h, m, value, this);
|
|
129
168
|
};
|
|
130
169
|
const enumerable = true;
|
|
131
170
|
const configurable = false;
|
|
132
171
|
return Object.defineProperty(proto, m, { get, set, enumerable, configurable });
|
|
133
172
|
}
|
|
134
173
|
else
|
|
135
|
-
Data_1.Meta.acquire(proto, Data_1.Meta.Initial)[m] = Data_1.Meta.
|
|
174
|
+
Data_1.Meta.acquire(proto, Data_1.Meta.Initial)[m] = Data_1.Meta.Nonreactive;
|
|
136
175
|
}
|
|
137
176
|
static decorateOperation(implicit, decorator, options, proto, member, pd) {
|
|
138
177
|
var _a, _b, _c, _d;
|
|
@@ -143,7 +182,7 @@ class Hooks {
|
|
|
143
182
|
const opts = Hooks.rememberOperationOptions(proto, member, (_c = pd.value) !== null && _c !== void 0 ? _c : pd.get, (_d = pd.value) !== null && _d !== void 0 ? _d : pd.set, true, configurable, options, implicit);
|
|
144
183
|
if (opts.getter === opts.setter) {
|
|
145
184
|
const bootstrap = function () {
|
|
146
|
-
const h = Hooks.
|
|
185
|
+
const h = Hooks.acquireHandle(this);
|
|
147
186
|
const operation = Hooks.createOperation(h, member, opts);
|
|
148
187
|
Object.defineProperty(h.data, member, { value: operation, enumerable, configurable });
|
|
149
188
|
return operation;
|
|
@@ -152,7 +191,7 @@ class Hooks {
|
|
|
152
191
|
}
|
|
153
192
|
else if (opts.setter === Utils_1.UNDEF) {
|
|
154
193
|
const bootstrap = function () {
|
|
155
|
-
const h = Hooks.
|
|
194
|
+
const h = Hooks.acquireHandle(this);
|
|
156
195
|
const operation = Hooks.createOperation(h, member, opts);
|
|
157
196
|
Object.defineProperty(h.data, member, { get: operation, enumerable, configurable });
|
|
158
197
|
return operation.call(this);
|
|
@@ -167,23 +206,24 @@ class Hooks {
|
|
|
167
206
|
return Hooks.decorateOperation(false, decorator, options, proto, prop, pd);
|
|
168
207
|
};
|
|
169
208
|
}
|
|
170
|
-
static
|
|
171
|
-
let h = obj[Data_1.Meta.
|
|
209
|
+
static acquireHandle(obj) {
|
|
210
|
+
let h = obj[Data_1.Meta.Handle];
|
|
172
211
|
if (!h) {
|
|
173
212
|
if (obj !== Object(obj) || Array.isArray(obj))
|
|
174
213
|
throw (0, Dbg_1.misuse)('only objects can be reactive');
|
|
175
214
|
const initial = Data_1.Meta.getFrom(Object.getPrototypeOf(obj), Data_1.Meta.Initial);
|
|
176
|
-
const
|
|
177
|
-
Data_1.
|
|
178
|
-
|
|
179
|
-
Data_1.Meta.set(obj, Data_1.Meta.
|
|
215
|
+
const os = new Data_1.ObjectSnapshot(Changeset_1.EMPTY_SNAPSHOT.changeset, Changeset_1.EMPTY_SNAPSHOT, Object.assign({}, initial));
|
|
216
|
+
h = new Data_1.ObjectHandle(obj, obj, Hooks.handler, os, obj.constructor.name);
|
|
217
|
+
Data_1.Meta.set(os.data, Data_1.Meta.Handle, h);
|
|
218
|
+
Data_1.Meta.set(obj, Data_1.Meta.Handle, h);
|
|
219
|
+
Data_1.Meta.set(os.data, Data_1.Meta.Revision, new Data_1.Subscription(1));
|
|
180
220
|
}
|
|
181
221
|
return h;
|
|
182
222
|
}
|
|
183
|
-
static
|
|
184
|
-
const ctx =
|
|
185
|
-
const h = new Data_1.
|
|
186
|
-
ctx.
|
|
223
|
+
static createHandleForReactiveObject(proto, data, blank, hint) {
|
|
224
|
+
const ctx = Changeset_1.Changeset.edit();
|
|
225
|
+
const h = new Data_1.ObjectHandle(data, undefined, Hooks.handler, Changeset_1.EMPTY_SNAPSHOT, hint);
|
|
226
|
+
ctx.getEditableSnapshot(h, Data_1.Meta.Handle, blank);
|
|
187
227
|
if (!Hooks.reactionsAutoStartDisabled)
|
|
188
228
|
for (const m in Data_1.Meta.getFrom(proto, Data_1.Meta.Reactions))
|
|
189
229
|
h.proxy[m][Data_1.Meta.Controller].markObsolete();
|
|
@@ -194,13 +234,13 @@ class Hooks {
|
|
|
194
234
|
Hooks.repetitiveUsageWarningThreshold = options && options.repetitiveUsageWarningThreshold !== undefined ? options.repetitiveUsageWarningThreshold : 10;
|
|
195
235
|
Hooks.mainThreadBlockingWarningThreshold = options && options.mainThreadBlockingWarningThreshold !== undefined ? options.mainThreadBlockingWarningThreshold : 14;
|
|
196
236
|
Hooks.asyncActionDurationWarningThreshold = options && options.asyncActionDurationWarningThreshold !== undefined ? options.asyncActionDurationWarningThreshold : 300;
|
|
197
|
-
|
|
237
|
+
Changeset_1.Changeset.garbageCollectionSummaryInterval = options && options.garbageCollectionSummaryInterval !== undefined ? options.garbageCollectionSummaryInterval : 100;
|
|
198
238
|
}
|
|
199
239
|
else {
|
|
200
240
|
Hooks.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
201
241
|
Hooks.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
202
242
|
Hooks.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
203
|
-
|
|
243
|
+
Changeset_1.Changeset.garbageCollectionSummaryInterval = Number.MAX_SAFE_INTEGER;
|
|
204
244
|
}
|
|
205
245
|
}
|
|
206
246
|
static sensitive(sensitivity, func, ...args) {
|
|
@@ -215,7 +255,7 @@ class Hooks {
|
|
|
215
255
|
}
|
|
216
256
|
static setHint(obj, hint) {
|
|
217
257
|
if (hint) {
|
|
218
|
-
const h = Hooks.
|
|
258
|
+
const h = Hooks.acquireHandle(obj);
|
|
219
259
|
h.hint = hint;
|
|
220
260
|
}
|
|
221
261
|
return obj;
|
|
@@ -227,7 +267,7 @@ Hooks.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
|
227
267
|
Hooks.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
228
268
|
Hooks.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
229
269
|
Hooks.sensitivity = false;
|
|
230
|
-
Hooks.
|
|
270
|
+
Hooks.handler = new Hooks();
|
|
231
271
|
Hooks.createOperation = function (h, m, options) {
|
|
232
272
|
throw (0, Dbg_1.misuse)('createOperation should never be called');
|
|
233
273
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ReactiveObject } from './Hooks';
|
|
2
|
+
import { ObjectHandle, ObjectSnapshot, PatchSet } from './Data';
|
|
3
3
|
export declare type Saver = (patch: PatchSet) => Promise<void>;
|
|
4
|
-
export declare abstract class Journal extends
|
|
4
|
+
export declare abstract class Journal extends ReactiveObject {
|
|
5
5
|
abstract capacity: number;
|
|
6
6
|
abstract readonly edits: ReadonlyArray<PatchSet>;
|
|
7
7
|
abstract readonly unsaved: PatchSet;
|
|
@@ -28,7 +28,7 @@ export declare class JournalImpl extends Journal {
|
|
|
28
28
|
saved(patch: PatchSet): void;
|
|
29
29
|
undo(count?: number): void;
|
|
30
30
|
redo(count?: number): void;
|
|
31
|
-
static buildPatch(hint: string,
|
|
31
|
+
static buildPatch(hint: string, items: Map<ObjectHandle, ObjectSnapshot>): PatchSet;
|
|
32
32
|
static applyPatch(patch: PatchSet, undoing: boolean): void;
|
|
33
33
|
mergePatchToUnsaved(patch: PatchSet, undoing: boolean): void;
|
|
34
34
|
}
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.JournalImpl = exports.Journal = void 0;
|
|
4
4
|
const Hooks_1 = require("./Hooks");
|
|
5
5
|
const Data_1 = require("./Data");
|
|
6
|
-
const
|
|
6
|
+
const Changeset_1 = require("./Changeset");
|
|
7
7
|
const Transaction_1 = require("./Transaction");
|
|
8
8
|
const Sealant_1 = require("../util/Sealant");
|
|
9
|
-
class Journal extends Hooks_1.
|
|
9
|
+
class Journal extends Hooks_1.ReactiveObject {
|
|
10
10
|
static create() { return new JournalImpl(); }
|
|
11
11
|
}
|
|
12
12
|
exports.Journal = Journal;
|
|
@@ -15,7 +15,7 @@ class JournalImpl extends Journal {
|
|
|
15
15
|
super(...arguments);
|
|
16
16
|
this._capacity = 5;
|
|
17
17
|
this._edits = [];
|
|
18
|
-
this._unsaved = { hint: 'unsaved',
|
|
18
|
+
this._unsaved = { hint: 'unsaved', items: new Map() };
|
|
19
19
|
this._position = 0;
|
|
20
20
|
}
|
|
21
21
|
get capacity() { return this._capacity; }
|
|
@@ -39,7 +39,7 @@ class JournalImpl extends Journal {
|
|
|
39
39
|
}
|
|
40
40
|
saved(patch) {
|
|
41
41
|
if (this._unsaved === patch)
|
|
42
|
-
this._unsaved = { hint: 'unsaved',
|
|
42
|
+
this._unsaved = { hint: 'unsaved', items: new Map() };
|
|
43
43
|
else
|
|
44
44
|
throw new Error('not implemented');
|
|
45
45
|
}
|
|
@@ -67,66 +67,77 @@ class JournalImpl extends Journal {
|
|
|
67
67
|
this._position = i;
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
static buildPatch(hint,
|
|
71
|
-
const patch = { hint,
|
|
72
|
-
|
|
73
|
-
const op =
|
|
74
|
-
const former =
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
static buildPatch(hint, items) {
|
|
71
|
+
const patch = { hint, items: new Map() };
|
|
72
|
+
items.forEach((os, h) => {
|
|
73
|
+
const op = new Map();
|
|
74
|
+
const former = os.former.snapshot !== Changeset_1.EMPTY_SNAPSHOT ? os.former.snapshot.data : undefined;
|
|
75
|
+
os.changes.forEach(m => {
|
|
76
|
+
const vp = {
|
|
77
|
+
memberName: m, patchKind: 'update',
|
|
78
|
+
freshValue: unseal(os.data[m]), formerValue: undefined,
|
|
79
|
+
};
|
|
77
80
|
if (former)
|
|
78
|
-
|
|
81
|
+
vp.formerValue = unseal(former[m]);
|
|
82
|
+
op.set(m, vp);
|
|
79
83
|
});
|
|
80
84
|
if (!former) {
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
const vp = {
|
|
86
|
+
memberName: Data_1.Meta.Revision, patchKind: 'remove',
|
|
87
|
+
freshValue: Data_1.Meta.Undefined, formerValue: undefined,
|
|
88
|
+
};
|
|
89
|
+
op.set(Data_1.Meta.Revision, vp);
|
|
83
90
|
}
|
|
84
|
-
patch.
|
|
91
|
+
patch.items.set(h.proxy, op);
|
|
85
92
|
});
|
|
86
93
|
return patch;
|
|
87
94
|
}
|
|
88
95
|
static applyPatch(patch, undoing) {
|
|
89
|
-
const ctx =
|
|
90
|
-
patch.
|
|
91
|
-
const h = Data_1.Meta.get(obj, Data_1.Meta.
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
const ctx = Changeset_1.Changeset.edit();
|
|
97
|
+
patch.items.forEach((op, obj) => {
|
|
98
|
+
const h = Data_1.Meta.get(obj, Data_1.Meta.Handle);
|
|
99
|
+
const rev = op.get(Data_1.Meta.Revision);
|
|
100
|
+
const disposed = rev && (undoing ? rev.formerValue : rev.freshValue) === Data_1.Meta.Undefined;
|
|
101
|
+
if (!disposed) {
|
|
102
|
+
op.forEach((vp, m) => {
|
|
103
|
+
const value = undoing ? vp.formerValue : vp.freshValue;
|
|
104
|
+
const os = ctx.getEditableSnapshot(h, m, value);
|
|
105
|
+
if (os.changeset === ctx) {
|
|
106
|
+
os.data[m] = new Data_1.Subscription(value);
|
|
107
|
+
const existing = os.former.snapshot.data[m];
|
|
108
|
+
Changeset_1.Changeset.markEdited(existing, value, existing !== value, os, m, h);
|
|
101
109
|
}
|
|
102
|
-
}
|
|
110
|
+
});
|
|
103
111
|
}
|
|
104
112
|
else
|
|
105
|
-
|
|
113
|
+
Changeset_1.Changeset.doDispose(ctx, h);
|
|
106
114
|
});
|
|
107
115
|
}
|
|
108
116
|
mergePatchToUnsaved(patch, undoing) {
|
|
109
117
|
const unsaved = this._unsaved;
|
|
110
|
-
patch.
|
|
111
|
-
let
|
|
112
|
-
if (!
|
|
113
|
-
unsaved.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
patch.items.forEach((op, obj) => {
|
|
119
|
+
let result = unsaved.items.get(obj);
|
|
120
|
+
if (!result)
|
|
121
|
+
unsaved.items.set(obj, result = new Map());
|
|
122
|
+
op.forEach((vp, m) => {
|
|
123
|
+
let merged = result.get(m);
|
|
124
|
+
if (!merged)
|
|
125
|
+
result.set(m, merged = {
|
|
126
|
+
memberName: m, patchKind: 'update',
|
|
127
|
+
freshValue: undefined, formerValue: undefined,
|
|
128
|
+
});
|
|
129
|
+
const value = undoing ? vp.formerValue : vp.freshValue;
|
|
130
|
+
const former = undoing ? vp.freshValue : vp.formerValue;
|
|
131
|
+
if (value !== merged.formerValue) {
|
|
132
|
+
merged.freshValue = value;
|
|
133
|
+
merged.formerValue = former;
|
|
122
134
|
}
|
|
123
135
|
else {
|
|
124
|
-
delete
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
unsaved.objects.delete(obj);
|
|
136
|
+
result.delete(m);
|
|
137
|
+
if (result.size === 0)
|
|
138
|
+
unsaved.items.delete(obj);
|
|
128
139
|
}
|
|
129
|
-
}
|
|
140
|
+
});
|
|
130
141
|
});
|
|
131
142
|
}
|
|
132
143
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare abstract class Meta {
|
|
2
|
-
static readonly
|
|
2
|
+
static readonly Handle: unique symbol;
|
|
3
|
+
static readonly Revision: unique symbol;
|
|
3
4
|
static readonly Controller: unique symbol;
|
|
4
|
-
static readonly Disposed: unique symbol;
|
|
5
5
|
static readonly Initial: unique symbol;
|
|
6
6
|
static readonly Reactions: unique symbol;
|
|
7
|
-
static readonly
|
|
7
|
+
static readonly Nonreactive: unique symbol;
|
|
8
8
|
static readonly Undefined: unique symbol;
|
|
9
9
|
static get<T>(obj: any, sym: symbol): T;
|
|
10
10
|
static set(obj: any, sym: symbol, value: any): any;
|
|
@@ -24,10 +24,10 @@ class Meta {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
exports.Meta = Meta;
|
|
27
|
-
Meta.
|
|
28
|
-
Meta.
|
|
29
|
-
Meta.
|
|
30
|
-
Meta.Initial = Symbol('
|
|
31
|
-
Meta.Reactions = Symbol('
|
|
32
|
-
Meta.
|
|
33
|
-
Meta.Undefined = Symbol('
|
|
27
|
+
Meta.Handle = Symbol('rx-handle');
|
|
28
|
+
Meta.Revision = Symbol('rx-revision');
|
|
29
|
+
Meta.Controller = Symbol('rx-controller');
|
|
30
|
+
Meta.Initial = Symbol('rx-initial');
|
|
31
|
+
Meta.Reactions = Symbol('rx-reactions');
|
|
32
|
+
Meta.Nonreactive = Symbol('rx-nonreactive');
|
|
33
|
+
Meta.Undefined = Symbol('rx-undefined');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Worker } from '../Worker';
|
|
2
|
-
import {
|
|
3
|
-
export declare abstract class Monitor extends
|
|
2
|
+
import { ReactiveObject } from './Hooks';
|
|
3
|
+
export declare abstract class Monitor extends ReactiveObject {
|
|
4
4
|
abstract readonly isActive: boolean;
|
|
5
5
|
abstract readonly counter: number;
|
|
6
6
|
abstract readonly workers: ReadonlySet<Worker>;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MonitorImpl = exports.Monitor = void 0;
|
|
4
4
|
const Hooks_1 = require("./Hooks");
|
|
5
5
|
const Transaction_1 = require("./Transaction");
|
|
6
|
-
class Monitor extends Hooks_1.
|
|
6
|
+
class Monitor extends Hooks_1.ReactiveObject {
|
|
7
7
|
static create(hint, activationDelay, deactivationDelay, durationResolution) {
|
|
8
8
|
return MonitorImpl.create(hint, activationDelay, deactivationDelay, durationResolution);
|
|
9
9
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { F } from '../util/Utils';
|
|
2
2
|
import { MemberOptions } from '../Options';
|
|
3
3
|
import { Controller } from '../Controller';
|
|
4
|
-
import { MemberName,
|
|
4
|
+
import { MemberName, ObjectHandle, Subscription, Subscriber, SubscriptionInfo, AbstractChangeset } from './Data';
|
|
5
5
|
import { Transaction } from './Transaction';
|
|
6
6
|
import { OptionsImpl } from './Hooks';
|
|
7
7
|
export declare class OperationController extends Controller<any> {
|
|
8
|
-
readonly
|
|
8
|
+
readonly objectHandle: ObjectHandle;
|
|
9
9
|
readonly memberName: MemberName;
|
|
10
10
|
configure(options: Partial<MemberOptions>): MemberOptions;
|
|
11
11
|
get options(): MemberOptions;
|
|
12
|
-
get
|
|
12
|
+
get nonreactive(): any;
|
|
13
13
|
get args(): ReadonlyArray<any>;
|
|
14
14
|
get result(): any;
|
|
15
15
|
get error(): boolean;
|
|
@@ -17,7 +17,7 @@ export declare class OperationController extends Controller<any> {
|
|
|
17
17
|
get isUpToDate(): boolean;
|
|
18
18
|
markObsolete(): void;
|
|
19
19
|
pullLastResult(args?: any[]): any;
|
|
20
|
-
constructor(
|
|
20
|
+
constructor(h: ObjectHandle, m: MemberName);
|
|
21
21
|
useOrRun(weak: boolean, args: any[] | undefined): Operation;
|
|
22
22
|
static of(method: F<any>): Controller<any>;
|
|
23
23
|
static configureImpl(self: OperationController | undefined, options: Partial<MemberOptions>): MemberOptions;
|
|
@@ -28,7 +28,7 @@ export declare class OperationController extends Controller<any> {
|
|
|
28
28
|
private peek;
|
|
29
29
|
private use;
|
|
30
30
|
private edit;
|
|
31
|
-
private
|
|
31
|
+
private acquireFromSnapshot;
|
|
32
32
|
private run;
|
|
33
33
|
private static markObsolete;
|
|
34
34
|
}
|
|
@@ -39,7 +39,7 @@ declare class Operation extends Subscription implements Subscriber {
|
|
|
39
39
|
readonly margin: number;
|
|
40
40
|
readonly transaction: Transaction;
|
|
41
41
|
readonly controller: OperationController;
|
|
42
|
-
readonly
|
|
42
|
+
readonly changeset: AbstractChangeset;
|
|
43
43
|
subscriptions: Map<Subscription, SubscriptionInfo> | undefined;
|
|
44
44
|
options: OptionsImpl;
|
|
45
45
|
cause: string | undefined;
|
|
@@ -50,7 +50,7 @@ declare class Operation extends Subscription implements Subscriber {
|
|
|
50
50
|
obsoleteDueTo: string | undefined;
|
|
51
51
|
obsoleteSince: number;
|
|
52
52
|
successor: Operation | undefined;
|
|
53
|
-
constructor(controller: OperationController,
|
|
53
|
+
constructor(controller: OperationController, changeset: AbstractChangeset, former: Operation | OptionsImpl);
|
|
54
54
|
get isOperation(): boolean;
|
|
55
55
|
get originSnapshotId(): number;
|
|
56
56
|
hint(): string;
|
|
@@ -61,7 +61,7 @@ declare class Operation extends Subscription implements Subscriber {
|
|
|
61
61
|
dependencies(): string[];
|
|
62
62
|
wrap<T>(func: F<T>): F<T>;
|
|
63
63
|
run(proxy: any, args: any[] | undefined): void;
|
|
64
|
-
markObsoleteDueTo(subscription: Subscription,
|
|
64
|
+
markObsoleteDueTo(subscription: Subscription, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, reactions: Subscriber[]): void;
|
|
65
65
|
runIfNotUpToDate(now: boolean, nothrow: boolean): void;
|
|
66
66
|
isNotUpToDate(): boolean;
|
|
67
67
|
reenterOver(head: Operation): this;
|