reactronic 0.22.301 → 0.22.304
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 +1 -1
- package/package.json +1 -1
- package/build/dist/source/Buffer.d.ts +0 -8
- package/build/dist/source/Buffer.js +0 -8
- package/build/dist/source/Controller.d.ts +0 -12
- package/build/dist/source/Controller.js +0 -6
- package/build/dist/source/Logging.d.ts +0 -38
- package/build/dist/source/Logging.js +0 -113
- package/build/dist/source/Options.d.ts +0 -38
- package/build/dist/source/Options.js +0 -21
- package/build/dist/source/Ref.d.ts +0 -34
- package/build/dist/source/Ref.js +0 -90
- package/build/dist/source/Rx.d.ts +0 -26
- package/build/dist/source/Rx.js +0 -57
- package/build/dist/source/Worker.d.ts +0 -8
- package/build/dist/source/Worker.js +0 -2
- package/build/dist/source/api.d.ts +0 -14
- package/build/dist/source/api.js +0 -40
- package/build/dist/source/impl/Data.d.ts +0 -58
- package/build/dist/source/impl/Data.js +0 -42
- package/build/dist/source/impl/Hooks.d.ts +0 -50
- package/build/dist/source/impl/Hooks.js +0 -241
- package/build/dist/source/impl/Journal.d.ts +0 -34
- package/build/dist/source/impl/Journal.js +0 -138
- package/build/dist/source/impl/Meta.d.ts +0 -13
- package/build/dist/source/impl/Meta.js +0 -33
- package/build/dist/source/impl/Monitor.d.ts +0 -32
- package/build/dist/source/impl/Monitor.js +0 -97
- package/build/dist/source/impl/Operation.d.ts +0 -93
- package/build/dist/source/impl/Operation.js +0 -721
- package/build/dist/source/impl/Snapshot.d.ts +0 -60
- package/build/dist/source/impl/Snapshot.js +0 -353
- package/build/dist/source/impl/Transaction.d.ts +0 -30
- package/build/dist/source/impl/Transaction.js +0 -313
- package/build/dist/source/util/Dbg.d.ts +0 -15
- package/build/dist/source/util/Dbg.js +0 -96
- package/build/dist/source/util/Sealant.d.ts +0 -14
- package/build/dist/source/util/Sealant.js +0 -30
- package/build/dist/source/util/SealedArray.d.ts +0 -16
- package/build/dist/source/util/SealedArray.js +0 -28
- package/build/dist/source/util/SealedMap.d.ts +0 -13
- package/build/dist/source/util/SealedMap.js +0 -21
- package/build/dist/source/util/SealedSet.d.ts +0 -13
- package/build/dist/source/util/SealedSet.js +0 -21
- package/build/dist/source/util/Utils.d.ts +0 -9
- package/build/dist/source/util/Utils.js +0 -62
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { F } from '../util/Utils';
|
|
2
|
-
import { MemberOptions, Kind, Reentrance } from '../Options';
|
|
3
|
-
import { LoggingOptions, ProfilingOptions } from '../Logging';
|
|
4
|
-
import { MemberName, DataHolder, StandaloneMode } from './Data';
|
|
5
|
-
import { Journal } from './Journal';
|
|
6
|
-
import { Monitor } from './Monitor';
|
|
7
|
-
export declare abstract class ReactiveObject {
|
|
8
|
-
constructor();
|
|
9
|
-
[Symbol.toStringTag](): string;
|
|
10
|
-
}
|
|
11
|
-
export declare class OptionsImpl implements MemberOptions {
|
|
12
|
-
readonly getter: Function;
|
|
13
|
-
readonly setter: Function;
|
|
14
|
-
readonly kind: Kind;
|
|
15
|
-
readonly standalone: StandaloneMode;
|
|
16
|
-
readonly order: number;
|
|
17
|
-
readonly noSideEffects: boolean;
|
|
18
|
-
readonly triggeringArgs: boolean;
|
|
19
|
-
readonly throttling: number;
|
|
20
|
-
readonly reentrance: Reentrance;
|
|
21
|
-
readonly journal: Journal | undefined;
|
|
22
|
-
readonly monitor: Monitor | null;
|
|
23
|
-
readonly logging?: Partial<LoggingOptions>;
|
|
24
|
-
static readonly INITIAL: Readonly<OptionsImpl>;
|
|
25
|
-
constructor(getter: Function | undefined, setter: Function | undefined, existing: OptionsImpl, patch: Partial<OptionsImpl>, implicit: boolean);
|
|
26
|
-
}
|
|
27
|
-
export declare class Hooks implements ProxyHandler<DataHolder> {
|
|
28
|
-
static reactionsAutoStartDisabled: boolean;
|
|
29
|
-
static repetitiveUsageWarningThreshold: number;
|
|
30
|
-
static mainThreadBlockingWarningThreshold: number;
|
|
31
|
-
static asyncActionDurationWarningThreshold: number;
|
|
32
|
-
static sensitivity: boolean;
|
|
33
|
-
static readonly proxy: Hooks;
|
|
34
|
-
getPrototypeOf(h: DataHolder): object | null;
|
|
35
|
-
get(h: DataHolder, m: MemberName, receiver: any): any;
|
|
36
|
-
set(h: DataHolder, m: MemberName, value: any, receiver: any): boolean;
|
|
37
|
-
has(h: DataHolder, m: MemberName): boolean;
|
|
38
|
-
getOwnPropertyDescriptor(h: DataHolder, m: MemberName): PropertyDescriptor | undefined;
|
|
39
|
-
ownKeys(h: DataHolder): Array<string | symbol>;
|
|
40
|
-
static decorateData(reactive: boolean, proto: any, m: MemberName): any;
|
|
41
|
-
static decorateOperation(implicit: boolean, decorator: Function, options: Partial<MemberOptions>, proto: any, member: MemberName, pd: PropertyDescriptor | undefined): any;
|
|
42
|
-
static decorateOperationParametrized(decorator: Function, options: Partial<MemberOptions>): F<any>;
|
|
43
|
-
static acquireDataHolder(obj: any): DataHolder;
|
|
44
|
-
static createDataHolderForReactiveObject(proto: any, data: any, blank: any, hint: string): DataHolder;
|
|
45
|
-
static setProfilingMode(isOn: boolean, options?: Partial<ProfilingOptions>): void;
|
|
46
|
-
static sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
|
|
47
|
-
static setHint<T>(obj: T, hint: string | undefined): T;
|
|
48
|
-
static createOperation: (h: DataHolder, m: MemberName, options: OptionsImpl) => F<any>;
|
|
49
|
-
static rememberOperationOptions: (proto: any, m: MemberName, getter: Function | undefined, setter: Function | undefined, enumerable: boolean, configurable: boolean, options: Partial<MemberOptions>, implicit: boolean) => OptionsImpl;
|
|
50
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Hooks = exports.OptionsImpl = exports.ReactiveObject = void 0;
|
|
4
|
-
const Utils_1 = require("../util/Utils");
|
|
5
|
-
const Dbg_1 = require("../util/Dbg");
|
|
6
|
-
const Options_1 = require("../Options");
|
|
7
|
-
const Data_1 = require("./Data");
|
|
8
|
-
const Snapshot_1 = require("./Snapshot");
|
|
9
|
-
class ReactiveObject {
|
|
10
|
-
constructor() {
|
|
11
|
-
const proto = new.target.prototype;
|
|
12
|
-
const initial = Data_1.Meta.getFrom(proto, Data_1.Meta.Initial);
|
|
13
|
-
const h = Hooks.createDataHolderForReactiveObject(proto, this, initial, new.target.name);
|
|
14
|
-
return h.proxy;
|
|
15
|
-
}
|
|
16
|
-
[Symbol.toStringTag]() {
|
|
17
|
-
const h = Data_1.Meta.get(this, Data_1.Meta.Holder);
|
|
18
|
-
return Snapshot_1.Dump.obj(h);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.ReactiveObject = ReactiveObject;
|
|
22
|
-
const DEFAULT_OPTIONS = Object.freeze({
|
|
23
|
-
kind: Options_1.Kind.Plain,
|
|
24
|
-
standalone: false,
|
|
25
|
-
order: 0,
|
|
26
|
-
noSideEffects: false,
|
|
27
|
-
triggeringArgs: false,
|
|
28
|
-
throttling: Number.MAX_SAFE_INTEGER,
|
|
29
|
-
reentrance: Options_1.Reentrance.PreventWithError,
|
|
30
|
-
journal: undefined,
|
|
31
|
-
monitor: null,
|
|
32
|
-
logging: undefined,
|
|
33
|
-
});
|
|
34
|
-
class OptionsImpl {
|
|
35
|
-
constructor(getter, setter, existing, patch, implicit) {
|
|
36
|
-
this.getter = getter !== undefined ? getter : existing.getter;
|
|
37
|
-
this.setter = setter !== undefined ? setter : existing.setter;
|
|
38
|
-
this.kind = merge(DEFAULT_OPTIONS.kind, existing.kind, patch.kind, implicit);
|
|
39
|
-
this.standalone = merge(DEFAULT_OPTIONS.standalone, existing.standalone, patch.standalone, implicit);
|
|
40
|
-
this.order = merge(DEFAULT_OPTIONS.order, existing.order, patch.order, implicit);
|
|
41
|
-
this.noSideEffects = merge(DEFAULT_OPTIONS.noSideEffects, existing.noSideEffects, patch.noSideEffects, implicit);
|
|
42
|
-
this.triggeringArgs = merge(DEFAULT_OPTIONS.triggeringArgs, existing.triggeringArgs, patch.triggeringArgs, implicit);
|
|
43
|
-
this.throttling = merge(DEFAULT_OPTIONS.throttling, existing.throttling, patch.throttling, implicit);
|
|
44
|
-
this.reentrance = merge(DEFAULT_OPTIONS.reentrance, existing.reentrance, patch.reentrance, implicit);
|
|
45
|
-
this.journal = merge(DEFAULT_OPTIONS.journal, existing.journal, patch.journal, implicit);
|
|
46
|
-
this.monitor = merge(DEFAULT_OPTIONS.monitor, existing.monitor, patch.monitor, implicit);
|
|
47
|
-
this.logging = merge(DEFAULT_OPTIONS.logging, existing.logging, patch.logging, implicit);
|
|
48
|
-
if (Dbg_1.Log.isOn)
|
|
49
|
-
Object.freeze(this);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.OptionsImpl = OptionsImpl;
|
|
53
|
-
OptionsImpl.INITIAL = Object.freeze(new OptionsImpl(Utils_1.UNDEF, Utils_1.UNDEF, Object.assign({ getter: Utils_1.UNDEF, setter: Utils_1.UNDEF }, DEFAULT_OPTIONS), {}, false));
|
|
54
|
-
function merge(def, existing, patch, implicit) {
|
|
55
|
-
return patch !== undefined && (existing === def || !implicit) ? patch : existing;
|
|
56
|
-
}
|
|
57
|
-
class Hooks {
|
|
58
|
-
getPrototypeOf(h) {
|
|
59
|
-
return Reflect.getPrototypeOf(h.data);
|
|
60
|
-
}
|
|
61
|
-
get(h, m, receiver) {
|
|
62
|
-
let result;
|
|
63
|
-
const r = Snapshot_1.Snapshot.current().getCurrentRevision(h, m);
|
|
64
|
-
result = r.data[m];
|
|
65
|
-
if (result instanceof Data_1.Subscription && !result.isOperation) {
|
|
66
|
-
Snapshot_1.Snapshot.markUsed(result, r, m, h, Options_1.Kind.Plain, false);
|
|
67
|
-
result = result.content;
|
|
68
|
-
}
|
|
69
|
-
else if (m === Data_1.Meta.Holder) {
|
|
70
|
-
}
|
|
71
|
-
else
|
|
72
|
-
result = Reflect.get(h.data, m, receiver);
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
set(h, m, value, receiver) {
|
|
76
|
-
const r = Snapshot_1.Snapshot.edit().getEditableRevision(h, m, value);
|
|
77
|
-
if (r !== Snapshot_1.ROOT_REV) {
|
|
78
|
-
let curr = r.data[m];
|
|
79
|
-
if (curr !== undefined || (r.former.revision.snapshot === Snapshot_1.ROOT_REV.snapshot && (m in h.data) === false)) {
|
|
80
|
-
if (curr === undefined || curr.content !== value || Hooks.sensitivity) {
|
|
81
|
-
const existing = curr === null || curr === void 0 ? void 0 : curr.content;
|
|
82
|
-
if (r.former.revision.data[m] === curr) {
|
|
83
|
-
curr = r.data[m] = new Data_1.Subscription(value);
|
|
84
|
-
Snapshot_1.Snapshot.markEdited(existing, value, true, r, m, h);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
curr.content = value;
|
|
88
|
-
Snapshot_1.Snapshot.markEdited(existing, value, true, r, m, h);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else
|
|
93
|
-
Reflect.set(h.data, m, value, receiver);
|
|
94
|
-
}
|
|
95
|
-
else
|
|
96
|
-
h.data[m] = value;
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
has(h, m) {
|
|
100
|
-
const r = Snapshot_1.Snapshot.current().getCurrentRevision(h, m);
|
|
101
|
-
return m in r.data || m in h.data;
|
|
102
|
-
}
|
|
103
|
-
getOwnPropertyDescriptor(h, m) {
|
|
104
|
-
const r = Snapshot_1.Snapshot.current().getCurrentRevision(h, m);
|
|
105
|
-
const pd = Reflect.getOwnPropertyDescriptor(r.data, m);
|
|
106
|
-
if (pd)
|
|
107
|
-
pd.configurable = pd.writable = true;
|
|
108
|
-
return pd;
|
|
109
|
-
}
|
|
110
|
-
ownKeys(h) {
|
|
111
|
-
const r = Snapshot_1.Snapshot.current().getCurrentRevision(h, Data_1.Meta.Holder);
|
|
112
|
-
const result = [];
|
|
113
|
-
for (const m of Object.getOwnPropertyNames(r.data)) {
|
|
114
|
-
const value = r.data[m];
|
|
115
|
-
if (!(value instanceof Data_1.Subscription) || !value.isOperation)
|
|
116
|
-
result.push(m);
|
|
117
|
-
}
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
static decorateData(reactive, proto, m) {
|
|
121
|
-
if (reactive) {
|
|
122
|
-
const get = function () {
|
|
123
|
-
const h = Hooks.acquireDataHolder(this);
|
|
124
|
-
return Hooks.proxy.get(h, m, this);
|
|
125
|
-
};
|
|
126
|
-
const set = function (value) {
|
|
127
|
-
const h = Hooks.acquireDataHolder(this);
|
|
128
|
-
return Hooks.proxy.set(h, m, value, this);
|
|
129
|
-
};
|
|
130
|
-
const enumerable = true;
|
|
131
|
-
const configurable = false;
|
|
132
|
-
return Object.defineProperty(proto, m, { get, set, enumerable, configurable });
|
|
133
|
-
}
|
|
134
|
-
else
|
|
135
|
-
Data_1.Meta.acquire(proto, Data_1.Meta.Initial)[m] = Data_1.Meta.Nonreactive;
|
|
136
|
-
}
|
|
137
|
-
static decorateOperation(implicit, decorator, options, proto, member, pd) {
|
|
138
|
-
var _a, _b, _c, _d;
|
|
139
|
-
if (pd === undefined || pd === proto)
|
|
140
|
-
pd = EMPTY_PROP_DESCRIPTOR;
|
|
141
|
-
const enumerable = (_a = pd.enumerable) !== null && _a !== void 0 ? _a : true;
|
|
142
|
-
const configurable = (_b = pd.configurable) !== null && _b !== void 0 ? _b : true;
|
|
143
|
-
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
|
-
if (opts.getter === opts.setter) {
|
|
145
|
-
const bootstrap = function () {
|
|
146
|
-
const h = Hooks.acquireDataHolder(this);
|
|
147
|
-
const operation = Hooks.createOperation(h, member, opts);
|
|
148
|
-
Object.defineProperty(h.data, member, { value: operation, enumerable, configurable });
|
|
149
|
-
return operation;
|
|
150
|
-
};
|
|
151
|
-
return Object.defineProperty(proto, member, { get: bootstrap, enumerable, configurable: true });
|
|
152
|
-
}
|
|
153
|
-
else if (opts.setter === Utils_1.UNDEF) {
|
|
154
|
-
const bootstrap = function () {
|
|
155
|
-
const h = Hooks.acquireDataHolder(this);
|
|
156
|
-
const operation = Hooks.createOperation(h, member, opts);
|
|
157
|
-
Object.defineProperty(h.data, member, { get: operation, enumerable, configurable });
|
|
158
|
-
return operation.call(this);
|
|
159
|
-
};
|
|
160
|
-
return Object.defineProperty(proto, member, { get: bootstrap, enumerable, configurable: true });
|
|
161
|
-
}
|
|
162
|
-
else
|
|
163
|
-
throw (0, Dbg_1.misuse)(`${proto.constructor.name}.${member.toString()} has setter and cannot be decorated with @${decorator.name}`);
|
|
164
|
-
}
|
|
165
|
-
static decorateOperationParametrized(decorator, options) {
|
|
166
|
-
return function (proto, prop, pd) {
|
|
167
|
-
return Hooks.decorateOperation(false, decorator, options, proto, prop, pd);
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
static acquireDataHolder(obj) {
|
|
171
|
-
let h = obj[Data_1.Meta.Holder];
|
|
172
|
-
if (!h) {
|
|
173
|
-
if (obj !== Object(obj) || Array.isArray(obj))
|
|
174
|
-
throw (0, Dbg_1.misuse)('only objects can be reactive');
|
|
175
|
-
const initial = Data_1.Meta.getFrom(Object.getPrototypeOf(obj), Data_1.Meta.Initial);
|
|
176
|
-
const rev = new Data_1.DataRevision(Snapshot_1.ROOT_REV.snapshot, Snapshot_1.ROOT_REV, Object.assign({}, initial));
|
|
177
|
-
Data_1.Meta.set(rev.data, Data_1.Meta.Holder, h);
|
|
178
|
-
h = new Data_1.DataHolder(obj, obj, Hooks.proxy, rev, obj.constructor.name);
|
|
179
|
-
Data_1.Meta.set(obj, Data_1.Meta.Holder, h);
|
|
180
|
-
}
|
|
181
|
-
return h;
|
|
182
|
-
}
|
|
183
|
-
static createDataHolderForReactiveObject(proto, data, blank, hint) {
|
|
184
|
-
const ctx = Snapshot_1.Snapshot.edit();
|
|
185
|
-
const h = new Data_1.DataHolder(data, undefined, Hooks.proxy, Snapshot_1.ROOT_REV, hint);
|
|
186
|
-
ctx.getEditableRevision(h, Data_1.Meta.Holder, blank);
|
|
187
|
-
if (!Hooks.reactionsAutoStartDisabled)
|
|
188
|
-
for (const m in Data_1.Meta.getFrom(proto, Data_1.Meta.Reactions))
|
|
189
|
-
h.proxy[m][Data_1.Meta.Controller].markObsolete();
|
|
190
|
-
return h;
|
|
191
|
-
}
|
|
192
|
-
static setProfilingMode(isOn, options) {
|
|
193
|
-
if (isOn) {
|
|
194
|
-
Hooks.repetitiveUsageWarningThreshold = options && options.repetitiveUsageWarningThreshold !== undefined ? options.repetitiveUsageWarningThreshold : 10;
|
|
195
|
-
Hooks.mainThreadBlockingWarningThreshold = options && options.mainThreadBlockingWarningThreshold !== undefined ? options.mainThreadBlockingWarningThreshold : 14;
|
|
196
|
-
Hooks.asyncActionDurationWarningThreshold = options && options.asyncActionDurationWarningThreshold !== undefined ? options.asyncActionDurationWarningThreshold : 300;
|
|
197
|
-
Snapshot_1.Snapshot.garbageCollectionSummaryInterval = options && options.garbageCollectionSummaryInterval !== undefined ? options.garbageCollectionSummaryInterval : 100;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
Hooks.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
201
|
-
Hooks.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
202
|
-
Hooks.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
203
|
-
Snapshot_1.Snapshot.garbageCollectionSummaryInterval = Number.MAX_SAFE_INTEGER;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
static sensitive(sensitivity, func, ...args) {
|
|
207
|
-
const restore = Hooks.sensitivity;
|
|
208
|
-
Hooks.sensitivity = sensitivity;
|
|
209
|
-
try {
|
|
210
|
-
return func(...args);
|
|
211
|
-
}
|
|
212
|
-
finally {
|
|
213
|
-
Hooks.sensitivity = restore;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
static setHint(obj, hint) {
|
|
217
|
-
if (hint) {
|
|
218
|
-
const h = Hooks.acquireDataHolder(obj);
|
|
219
|
-
h.hint = hint;
|
|
220
|
-
}
|
|
221
|
-
return obj;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
exports.Hooks = Hooks;
|
|
225
|
-
Hooks.reactionsAutoStartDisabled = false;
|
|
226
|
-
Hooks.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
227
|
-
Hooks.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
228
|
-
Hooks.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
229
|
-
Hooks.sensitivity = false;
|
|
230
|
-
Hooks.proxy = new Hooks();
|
|
231
|
-
Hooks.createOperation = function (h, m, options) {
|
|
232
|
-
throw (0, Dbg_1.misuse)('createOperation should never be called');
|
|
233
|
-
};
|
|
234
|
-
Hooks.rememberOperationOptions = function (proto, m, getter, setter, enumerable, configurable, options, implicit) {
|
|
235
|
-
throw (0, Dbg_1.misuse)('rememberOperationOptions should never be called');
|
|
236
|
-
};
|
|
237
|
-
const EMPTY_PROP_DESCRIPTOR = {
|
|
238
|
-
configurable: true,
|
|
239
|
-
enumerable: true,
|
|
240
|
-
value: undefined,
|
|
241
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ReactiveObject } from './Hooks';
|
|
2
|
-
import { DataHolder, DataRevision, PatchSet } from './Data';
|
|
3
|
-
export declare type Saver = (patch: PatchSet) => Promise<void>;
|
|
4
|
-
export declare abstract class Journal extends ReactiveObject {
|
|
5
|
-
abstract capacity: number;
|
|
6
|
-
abstract readonly edits: ReadonlyArray<PatchSet>;
|
|
7
|
-
abstract readonly unsaved: PatchSet;
|
|
8
|
-
abstract readonly canUndo: boolean;
|
|
9
|
-
abstract readonly canRedo: boolean;
|
|
10
|
-
abstract edited(patch: PatchSet): void;
|
|
11
|
-
abstract saved(patch: PatchSet): void;
|
|
12
|
-
abstract undo(count?: number): void;
|
|
13
|
-
abstract redo(count?: number): void;
|
|
14
|
-
static create(): Journal;
|
|
15
|
-
}
|
|
16
|
-
export declare class JournalImpl extends Journal {
|
|
17
|
-
private _capacity;
|
|
18
|
-
private _edits;
|
|
19
|
-
private _unsaved;
|
|
20
|
-
private _position;
|
|
21
|
-
get capacity(): number;
|
|
22
|
-
set capacity(value: number);
|
|
23
|
-
get edits(): ReadonlyArray<PatchSet>;
|
|
24
|
-
get unsaved(): PatchSet;
|
|
25
|
-
get canUndo(): boolean;
|
|
26
|
-
get canRedo(): boolean;
|
|
27
|
-
edited(p: PatchSet): void;
|
|
28
|
-
saved(patch: PatchSet): void;
|
|
29
|
-
undo(count?: number): void;
|
|
30
|
-
redo(count?: number): void;
|
|
31
|
-
static buildPatch(hint: string, changeset: Map<DataHolder, DataRevision>): PatchSet;
|
|
32
|
-
static applyPatch(patch: PatchSet, undoing: boolean): void;
|
|
33
|
-
mergePatchToUnsaved(patch: PatchSet, undoing: boolean): void;
|
|
34
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JournalImpl = exports.Journal = void 0;
|
|
4
|
-
const Hooks_1 = require("./Hooks");
|
|
5
|
-
const Data_1 = require("./Data");
|
|
6
|
-
const Snapshot_1 = require("./Snapshot");
|
|
7
|
-
const Transaction_1 = require("./Transaction");
|
|
8
|
-
const Sealant_1 = require("../util/Sealant");
|
|
9
|
-
class Journal extends Hooks_1.ReactiveObject {
|
|
10
|
-
static create() { return new JournalImpl(); }
|
|
11
|
-
}
|
|
12
|
-
exports.Journal = Journal;
|
|
13
|
-
class JournalImpl extends Journal {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this._capacity = 5;
|
|
17
|
-
this._edits = [];
|
|
18
|
-
this._unsaved = { hint: 'unsaved', objects: new Map() };
|
|
19
|
-
this._position = 0;
|
|
20
|
-
}
|
|
21
|
-
get capacity() { return this._capacity; }
|
|
22
|
-
set capacity(value) { this._capacity = value; if (value < this._edits.length)
|
|
23
|
-
this._edits.splice(0, this._edits.length - value); }
|
|
24
|
-
get edits() { return this._edits; }
|
|
25
|
-
get unsaved() { return this._unsaved; }
|
|
26
|
-
get canUndo() { return this._edits.length > 0 && this._position > 0; }
|
|
27
|
-
get canRedo() { return this._position < this._edits.length; }
|
|
28
|
-
edited(p) {
|
|
29
|
-
Transaction_1.Transaction.run({ hint: 'EditJournal.edited', standalone: 'isolated' }, () => {
|
|
30
|
-
const items = this._edits = this._edits.toMutable();
|
|
31
|
-
if (items.length >= this._capacity)
|
|
32
|
-
items.shift();
|
|
33
|
-
else
|
|
34
|
-
items.splice(this._position);
|
|
35
|
-
this.mergePatchToUnsaved(p, false);
|
|
36
|
-
items.push(p);
|
|
37
|
-
this._position = items.length;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
saved(patch) {
|
|
41
|
-
if (this._unsaved === patch)
|
|
42
|
-
this._unsaved = { hint: 'unsaved', objects: new Map() };
|
|
43
|
-
else
|
|
44
|
-
throw new Error('not implemented');
|
|
45
|
-
}
|
|
46
|
-
undo(count = 1) {
|
|
47
|
-
Transaction_1.Transaction.run({ hint: 'Journal.undo', standalone: 'isolated' }, () => {
|
|
48
|
-
let i = this._position - 1;
|
|
49
|
-
while (i >= 0 && count > 0) {
|
|
50
|
-
const patch = this._edits[i];
|
|
51
|
-
JournalImpl.applyPatch(patch, true);
|
|
52
|
-
this.mergePatchToUnsaved(patch, true);
|
|
53
|
-
i--, count--;
|
|
54
|
-
}
|
|
55
|
-
this._position = i + 1;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
redo(count = 1) {
|
|
59
|
-
Transaction_1.Transaction.run({ hint: 'Journal.redo', standalone: 'isolated' }, () => {
|
|
60
|
-
let i = this._position;
|
|
61
|
-
while (i < this._edits.length && count > 0) {
|
|
62
|
-
const patch = this._edits[i];
|
|
63
|
-
JournalImpl.applyPatch(patch, false);
|
|
64
|
-
this.mergePatchToUnsaved(patch, false);
|
|
65
|
-
i++, count--;
|
|
66
|
-
}
|
|
67
|
-
this._position = i;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
static buildPatch(hint, changeset) {
|
|
71
|
-
const patch = { hint, objects: new Map() };
|
|
72
|
-
changeset.forEach((r, h) => {
|
|
73
|
-
const op = { data: {}, former: {} };
|
|
74
|
-
const former = r.former.revision !== Snapshot_1.ROOT_REV ? r.former.revision.data : undefined;
|
|
75
|
-
r.changes.forEach(m => {
|
|
76
|
-
op.data[m] = unseal(r.data[m]);
|
|
77
|
-
if (former)
|
|
78
|
-
op.former[m] = unseal(former[m]);
|
|
79
|
-
});
|
|
80
|
-
if (!former) {
|
|
81
|
-
delete op.data[Data_1.Meta.Disposed];
|
|
82
|
-
op.former[Data_1.Meta.Disposed] = Data_1.Meta.Disposed;
|
|
83
|
-
}
|
|
84
|
-
patch.objects.set(h.proxy, op);
|
|
85
|
-
});
|
|
86
|
-
return patch;
|
|
87
|
-
}
|
|
88
|
-
static applyPatch(patch, undoing) {
|
|
89
|
-
const ctx = Snapshot_1.Snapshot.edit();
|
|
90
|
-
patch.objects.forEach((dp, obj) => {
|
|
91
|
-
const h = Data_1.Meta.get(obj, Data_1.Meta.Holder);
|
|
92
|
-
const data = undoing ? dp.former : dp.data;
|
|
93
|
-
if (data[Data_1.Meta.Disposed] === undefined) {
|
|
94
|
-
for (const m in data) {
|
|
95
|
-
const value = data[m];
|
|
96
|
-
const r = ctx.getEditableRevision(h, m, value);
|
|
97
|
-
if (r.snapshot === ctx) {
|
|
98
|
-
r.data[m] = new Data_1.Subscription(value);
|
|
99
|
-
const existing = r.former.revision.data[m];
|
|
100
|
-
Snapshot_1.Snapshot.markEdited(existing, value, existing !== value, r, m, h);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else
|
|
105
|
-
Snapshot_1.Snapshot.doDispose(ctx, h);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
mergePatchToUnsaved(patch, undoing) {
|
|
109
|
-
const unsaved = this._unsaved;
|
|
110
|
-
patch.objects.forEach((dp, obj) => {
|
|
111
|
-
let merged = unsaved.objects.get(obj);
|
|
112
|
-
if (!merged)
|
|
113
|
-
unsaved.objects.set(obj, merged = { data: {}, former: {} });
|
|
114
|
-
const data = undoing ? dp.former : dp.data;
|
|
115
|
-
const former = undoing ? dp.data : dp.former;
|
|
116
|
-
for (const m in data) {
|
|
117
|
-
const value = data[m];
|
|
118
|
-
if (value !== merged.former[m]) {
|
|
119
|
-
merged.data[m] = value;
|
|
120
|
-
if (m in merged.former === false)
|
|
121
|
-
merged.former[m] = former[m];
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
delete merged.data[m];
|
|
125
|
-
delete merged.former[m];
|
|
126
|
-
if (Object.keys(merged.data).length === 0)
|
|
127
|
-
unsaved.objects.delete(obj);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
exports.JournalImpl = JournalImpl;
|
|
134
|
-
function unseal(subscription) {
|
|
135
|
-
const result = subscription.content;
|
|
136
|
-
const createCopy = result === null || result === void 0 ? void 0 : result[Sealant_1.Sealant.CreateCopy];
|
|
137
|
-
return createCopy !== undefined ? createCopy.call(result) : result;
|
|
138
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare abstract class Meta {
|
|
2
|
-
static readonly Holder: unique symbol;
|
|
3
|
-
static readonly Controller: unique symbol;
|
|
4
|
-
static readonly Disposed: unique symbol;
|
|
5
|
-
static readonly Initial: unique symbol;
|
|
6
|
-
static readonly Reactions: unique symbol;
|
|
7
|
-
static readonly Nonreactive: unique symbol;
|
|
8
|
-
static readonly Undefined: unique symbol;
|
|
9
|
-
static get<T>(obj: any, sym: symbol): T;
|
|
10
|
-
static set(obj: any, sym: symbol, value: any): any;
|
|
11
|
-
static acquire(proto: any, sym: symbol): any;
|
|
12
|
-
static getFrom<T = any>(proto: any, sym: symbol): T;
|
|
13
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Meta = void 0;
|
|
4
|
-
const EMPTY_META = Object.freeze({});
|
|
5
|
-
class Meta {
|
|
6
|
-
static get(obj, sym) {
|
|
7
|
-
return obj[sym];
|
|
8
|
-
}
|
|
9
|
-
static set(obj, sym, value) {
|
|
10
|
-
Object.defineProperty(obj, sym, { value, configurable: false, enumerable: false });
|
|
11
|
-
return obj;
|
|
12
|
-
}
|
|
13
|
-
static acquire(proto, sym) {
|
|
14
|
-
let meta = proto[sym];
|
|
15
|
-
if (!proto.hasOwnProperty(sym)) {
|
|
16
|
-
meta = Object.assign({}, meta);
|
|
17
|
-
Meta.set(proto, sym, meta);
|
|
18
|
-
}
|
|
19
|
-
return meta;
|
|
20
|
-
}
|
|
21
|
-
static getFrom(proto, sym) {
|
|
22
|
-
var _a;
|
|
23
|
-
return (_a = proto[sym]) !== null && _a !== void 0 ? _a : EMPTY_META;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.Meta = Meta;
|
|
27
|
-
Meta.Holder = Symbol('rxHolder');
|
|
28
|
-
Meta.Controller = Symbol('rxController');
|
|
29
|
-
Meta.Disposed = Symbol('rxDisposed');
|
|
30
|
-
Meta.Initial = Symbol('rxInitial');
|
|
31
|
-
Meta.Reactions = Symbol('rxReactions');
|
|
32
|
-
Meta.Nonreactive = Symbol('rxNonreactive');
|
|
33
|
-
Meta.Undefined = Symbol('rxUndefined');
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Worker } from '../Worker';
|
|
2
|
-
import { ReactiveObject } from './Hooks';
|
|
3
|
-
export declare abstract class Monitor extends ReactiveObject {
|
|
4
|
-
abstract readonly isActive: boolean;
|
|
5
|
-
abstract readonly counter: number;
|
|
6
|
-
abstract readonly workers: ReadonlySet<Worker>;
|
|
7
|
-
abstract readonly duration: number;
|
|
8
|
-
static create(hint: string, activationDelay: number, deactivationDelay: number, durationResolution: number): Monitor;
|
|
9
|
-
}
|
|
10
|
-
export declare class MonitorImpl extends Monitor {
|
|
11
|
-
isActive: boolean;
|
|
12
|
-
counter: number;
|
|
13
|
-
workers: Set<Worker>;
|
|
14
|
-
duration: number;
|
|
15
|
-
internals: {
|
|
16
|
-
started: number;
|
|
17
|
-
activationDelay: number;
|
|
18
|
-
activationTimeout: undefined;
|
|
19
|
-
deactivationDelay: number;
|
|
20
|
-
deactivationTimeout: undefined;
|
|
21
|
-
durationResolution: number;
|
|
22
|
-
};
|
|
23
|
-
enter(worker: Worker): void;
|
|
24
|
-
leave(worker: Worker): void;
|
|
25
|
-
static create(hint: string, activationDelay: number, deactivationDelay: number, durationResolution: number): MonitorImpl;
|
|
26
|
-
static enter(mon: MonitorImpl, worker: Worker): void;
|
|
27
|
-
static leave(mon: MonitorImpl, worker: Worker): void;
|
|
28
|
-
private static doCreate;
|
|
29
|
-
private static activate;
|
|
30
|
-
private static deactivate;
|
|
31
|
-
private static tick;
|
|
32
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MonitorImpl = exports.Monitor = void 0;
|
|
4
|
-
const Hooks_1 = require("./Hooks");
|
|
5
|
-
const Transaction_1 = require("./Transaction");
|
|
6
|
-
class Monitor extends Hooks_1.ReactiveObject {
|
|
7
|
-
static create(hint, activationDelay, deactivationDelay, durationResolution) {
|
|
8
|
-
return MonitorImpl.create(hint, activationDelay, deactivationDelay, durationResolution);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.Monitor = Monitor;
|
|
12
|
-
class MonitorImpl extends Monitor {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
this.isActive = false;
|
|
16
|
-
this.counter = 0;
|
|
17
|
-
this.workers = new Set();
|
|
18
|
-
this.duration = 0;
|
|
19
|
-
this.internals = {
|
|
20
|
-
started: 0,
|
|
21
|
-
activationDelay: -1,
|
|
22
|
-
activationTimeout: undefined,
|
|
23
|
-
deactivationDelay: -1,
|
|
24
|
-
deactivationTimeout: undefined,
|
|
25
|
-
durationResolution: 1,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
enter(worker) {
|
|
29
|
-
this.counter++;
|
|
30
|
-
const workers = this.workers = this.workers.toMutable();
|
|
31
|
-
workers.add(worker);
|
|
32
|
-
MonitorImpl.activate(this, this.internals.activationDelay);
|
|
33
|
-
}
|
|
34
|
-
leave(worker) {
|
|
35
|
-
this.counter--;
|
|
36
|
-
const workers = this.workers = this.workers.toMutable();
|
|
37
|
-
workers.delete(worker);
|
|
38
|
-
MonitorImpl.deactivate(this, this.internals.deactivationDelay);
|
|
39
|
-
}
|
|
40
|
-
static create(hint, activationDelay, deactivationDelay, durationResolution) {
|
|
41
|
-
return Transaction_1.Transaction.run({ hint: 'Monitor.create' }, MonitorImpl.doCreate, hint, activationDelay, deactivationDelay, durationResolution);
|
|
42
|
-
}
|
|
43
|
-
static enter(mon, worker) {
|
|
44
|
-
mon.enter(worker);
|
|
45
|
-
}
|
|
46
|
-
static leave(mon, worker) {
|
|
47
|
-
mon.leave(worker);
|
|
48
|
-
}
|
|
49
|
-
static doCreate(hint, activationDelay, deactivationDelay, durationResolution) {
|
|
50
|
-
const m = new MonitorImpl();
|
|
51
|
-
Hooks_1.Hooks.setHint(m, hint);
|
|
52
|
-
m.internals.activationDelay = activationDelay;
|
|
53
|
-
m.internals.deactivationDelay = deactivationDelay;
|
|
54
|
-
m.internals.durationResolution = durationResolution;
|
|
55
|
-
return m;
|
|
56
|
-
}
|
|
57
|
-
static activate(mon, delay) {
|
|
58
|
-
if (mon.internals.started === 0) {
|
|
59
|
-
mon.duration = 0;
|
|
60
|
-
mon.internals.started = performance.now();
|
|
61
|
-
MonitorImpl.tick(mon);
|
|
62
|
-
}
|
|
63
|
-
if (delay >= 0) {
|
|
64
|
-
if (mon.internals.activationTimeout === undefined)
|
|
65
|
-
mon.internals.activationTimeout = setTimeout(() => Transaction_1.Transaction.run({ hint: 'Monitor.activate', standalone: 'isolated' }, MonitorImpl.activate, mon, -1), delay);
|
|
66
|
-
}
|
|
67
|
-
else if (mon.counter > 0)
|
|
68
|
-
mon.isActive = true;
|
|
69
|
-
}
|
|
70
|
-
static deactivate(mon, delay) {
|
|
71
|
-
if (delay >= 0) {
|
|
72
|
-
clearTimeout(mon.internals.deactivationTimeout);
|
|
73
|
-
mon.internals.deactivationTimeout = setTimeout(() => Transaction_1.Transaction.run({ hint: 'Monitor.deactivate', standalone: 'isolated' }, MonitorImpl.deactivate, mon, -1), delay);
|
|
74
|
-
}
|
|
75
|
-
else if (mon.counter <= 0) {
|
|
76
|
-
mon.isActive = false;
|
|
77
|
-
mon.internals.activationTimeout = undefined;
|
|
78
|
-
}
|
|
79
|
-
if (mon.counter === 0 && mon.internals.started !== 0) {
|
|
80
|
-
const resolution = mon.internals.durationResolution;
|
|
81
|
-
mon.duration = Math.round(resolution * (performance.now() - mon.internals.started)) / resolution;
|
|
82
|
-
mon.internals.started = 0;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
static tick(mon) {
|
|
86
|
-
if (mon.internals.started !== 0) {
|
|
87
|
-
Transaction_1.Transaction.run(null, () => {
|
|
88
|
-
const resolution = mon.internals.durationResolution;
|
|
89
|
-
mon.duration = Math.round(resolution * (performance.now() - mon.internals.started)) / resolution;
|
|
90
|
-
});
|
|
91
|
-
const t = globalThis !== null && globalThis !== void 0 ? globalThis : global;
|
|
92
|
-
if (t.requestAnimationFrame)
|
|
93
|
-
requestAnimationFrame(() => MonitorImpl.tick(mon));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
exports.MonitorImpl = MonitorImpl;
|