reactronic 0.22.314 → 0.22.317

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.
Files changed (35) hide show
  1. package/README.md +23 -23
  2. package/build/dist/source/Buffer.d.ts +2 -2
  3. package/build/dist/source/Buffer.js +2 -2
  4. package/build/dist/source/Options.d.ts +3 -3
  5. package/build/dist/source/Rx.d.ts +2 -2
  6. package/build/dist/source/Rx.js +14 -14
  7. package/build/dist/source/api.d.ts +5 -5
  8. package/build/dist/source/api.js +4 -4
  9. package/build/dist/source/impl/Changeset.js +8 -8
  10. package/build/dist/source/impl/Data.d.ts +1 -1
  11. package/build/dist/source/impl/Journal.d.ts +2 -2
  12. package/build/dist/source/impl/Journal.js +5 -5
  13. package/build/dist/source/impl/Meta.d.ts +1 -1
  14. package/build/dist/source/impl/Meta.js +1 -1
  15. package/build/dist/source/impl/Monitor.d.ts +2 -2
  16. package/build/dist/source/impl/Monitor.js +5 -5
  17. package/build/dist/source/impl/{Hooks.d.ts → Mvcc.d.ts} +15 -12
  18. package/build/dist/source/impl/{Hooks.js → Mvcc.js} +57 -52
  19. package/build/dist/source/impl/MvccArray.d.ts +60 -0
  20. package/build/dist/source/impl/MvccArray.js +58 -0
  21. package/build/dist/source/impl/MvccCollection.d.ts +25 -0
  22. package/build/dist/source/impl/MvccCollection.js +23 -0
  23. package/build/dist/source/impl/MvccMap.d.ts +25 -0
  24. package/build/dist/source/impl/MvccMap.js +35 -0
  25. package/build/dist/source/impl/Operation.d.ts +3 -3
  26. package/build/dist/source/impl/Operation.js +20 -20
  27. package/build/dist/source/impl/Transaction.d.ts +2 -2
  28. package/build/dist/source/impl/Transaction.js +9 -9
  29. package/build/dist/source/util/Collection.d.ts +3 -1
  30. package/build/dist/source/util/Collection.js +16 -8
  31. package/package.json +1 -1
  32. package/build/dist/source/impl/ReactiveArray.d.ts +0 -33
  33. package/build/dist/source/impl/ReactiveArray.js +0 -42
  34. package/build/dist/source/impl/ReactiveMap.d.ts +0 -15
  35. package/build/dist/source/impl/ReactiveMap.js +0 -24
@@ -3,11 +3,11 @@ import { Log, misuse } from '../util/Dbg';
3
3
  import { Kind, Reentrance } from '../Options';
4
4
  import { ObjectSnapshot, ObjectHandle, Subscription, Meta } from './Data';
5
5
  import { Changeset, Dump, EMPTY_SNAPSHOT } from './Changeset';
6
- export class HookedObject {
7
- constructor(reactive) {
6
+ export class MvccObject {
7
+ constructor(observable) {
8
8
  const proto = new.target.prototype;
9
9
  const initial = Meta.getFrom(proto, Meta.Initial);
10
- const h = Hooks.createHandleForReactronicObject(proto, this, initial, new.target.name, reactive);
10
+ const h = Mvcc.createHandleForMvccObject(proto, this, initial, new.target.name, observable);
11
11
  return h.proxy;
12
12
  }
13
13
  [Symbol.toStringTag]() {
@@ -15,14 +15,19 @@ export class HookedObject {
15
15
  return Dump.obj(h);
16
16
  }
17
17
  }
18
- export class ReactiveObject extends HookedObject {
18
+ export class TransactionalObject extends MvccObject {
19
+ constructor() {
20
+ super(false);
21
+ }
22
+ }
23
+ export class ObservableObject extends MvccObject {
19
24
  constructor() {
20
25
  super(true);
21
26
  }
22
27
  }
23
28
  const DEFAULT_OPTIONS = Object.freeze({
24
29
  kind: Kind.Plain,
25
- standalone: false,
30
+ separation: false,
26
31
  order: 0,
27
32
  noSideEffects: false,
28
33
  triggeringArgs: false,
@@ -37,7 +42,7 @@ export class OptionsImpl {
37
42
  this.getter = getter !== undefined ? getter : existing.getter;
38
43
  this.setter = setter !== undefined ? setter : existing.setter;
39
44
  this.kind = merge(DEFAULT_OPTIONS.kind, existing.kind, patch.kind, implicit);
40
- this.standalone = merge(DEFAULT_OPTIONS.standalone, existing.standalone, patch.standalone, implicit);
45
+ this.separation = merge(DEFAULT_OPTIONS.separation, existing.separation, patch.separation, implicit);
41
46
  this.order = merge(DEFAULT_OPTIONS.order, existing.order, patch.order, implicit);
42
47
  this.noSideEffects = merge(DEFAULT_OPTIONS.noSideEffects, existing.noSideEffects, patch.noSideEffects, implicit);
43
48
  this.triggeringArgs = merge(DEFAULT_OPTIONS.triggeringArgs, existing.triggeringArgs, patch.triggeringArgs, implicit);
@@ -54,9 +59,9 @@ OptionsImpl.INITIAL = Object.freeze(new OptionsImpl(UNDEF, UNDEF, Object.assign(
54
59
  function merge(def, existing, patch, implicit) {
55
60
  return patch !== undefined && (existing === def || !implicit) ? patch : existing;
56
61
  }
57
- export class Hooks {
58
- constructor(isReactive) {
59
- this.isReactive = isReactive;
62
+ export class Mvcc {
63
+ constructor(isObservable) {
64
+ this.isObservable = isObservable;
60
65
  }
61
66
  getPrototypeOf(h) {
62
67
  return Reflect.getPrototypeOf(h.data);
@@ -68,7 +73,7 @@ export class Hooks {
68
73
  const os = cs.getObjectSnapshot(h, m);
69
74
  result = os.data[m];
70
75
  if (result instanceof Subscription && !result.isOperation) {
71
- if (this.isReactive)
76
+ if (this.isObservable)
72
77
  Changeset.markUsed(result, os, m, h, Kind.Plain, false);
73
78
  result = result.content;
74
79
  }
@@ -84,7 +89,7 @@ export class Hooks {
84
89
  if (os !== EMPTY_SNAPSHOT) {
85
90
  let curr = os.data[m];
86
91
  if (curr !== undefined || (os.former.snapshot.changeset === EMPTY_SNAPSHOT.changeset && (m in h.data) === false)) {
87
- if (curr === undefined || curr.content !== value || Hooks.sensitivity) {
92
+ if (curr === undefined || curr.content !== value || Mvcc.sensitivity) {
88
93
  const existing = curr === null || curr === void 0 ? void 0 : curr.content;
89
94
  if (os.former.snapshot.data[m] === curr) {
90
95
  curr = os.data[m] = new Subscription(value);
@@ -124,22 +129,22 @@ export class Hooks {
124
129
  }
125
130
  return result;
126
131
  }
127
- static decorateData(reactive, proto, m) {
128
- if (reactive) {
132
+ static decorateData(isObservable, proto, m) {
133
+ if (isObservable) {
129
134
  const get = function () {
130
- const h = Hooks.acquireHandle(this);
131
- return Hooks.reactive.get(h, m, this);
135
+ const h = Mvcc.acquireHandle(this);
136
+ return Mvcc.observable.get(h, m, this);
132
137
  };
133
138
  const set = function (value) {
134
- const h = Hooks.acquireHandle(this);
135
- return Hooks.reactive.set(h, m, value, this);
139
+ const h = Mvcc.acquireHandle(this);
140
+ return Mvcc.observable.set(h, m, value, this);
136
141
  };
137
142
  const enumerable = true;
138
143
  const configurable = false;
139
144
  return Object.defineProperty(proto, m, { get, set, enumerable, configurable });
140
145
  }
141
146
  else
142
- Meta.acquire(proto, Meta.Initial)[m] = Meta.Nonreactive;
147
+ Meta.acquire(proto, Meta.Initial)[m] = Meta.Raw;
143
148
  }
144
149
  static decorateOperation(implicit, decorator, options, proto, member, pd) {
145
150
  var _a, _b, _c, _d;
@@ -147,11 +152,11 @@ export class Hooks {
147
152
  pd = EMPTY_PROP_DESCRIPTOR;
148
153
  const enumerable = (_a = pd.enumerable) !== null && _a !== void 0 ? _a : true;
149
154
  const configurable = (_b = pd.configurable) !== null && _b !== void 0 ? _b : true;
150
- 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);
155
+ const opts = Mvcc.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);
151
156
  if (opts.getter === opts.setter) {
152
157
  const bootstrap = function () {
153
- const h = Hooks.acquireHandle(this);
154
- const operation = Hooks.createOperation(h, member, opts);
158
+ const h = Mvcc.acquireHandle(this);
159
+ const operation = Mvcc.createOperation(h, member, opts);
155
160
  Object.defineProperty(h.data, member, { value: operation, enumerable, configurable });
156
161
  return operation;
157
162
  };
@@ -159,8 +164,8 @@ export class Hooks {
159
164
  }
160
165
  else if (opts.setter === UNDEF) {
161
166
  const bootstrap = function () {
162
- const h = Hooks.acquireHandle(this);
163
- const operation = Hooks.createOperation(h, member, opts);
167
+ const h = Mvcc.acquireHandle(this);
168
+ const operation = Mvcc.createOperation(h, member, opts);
164
169
  Object.defineProperty(h.data, member, { get: operation, enumerable, configurable });
165
170
  return operation.call(this);
166
171
  };
@@ -171,81 +176,81 @@ export class Hooks {
171
176
  }
172
177
  static decorateOperationParametrized(decorator, options) {
173
178
  return function (proto, prop, pd) {
174
- return Hooks.decorateOperation(false, decorator, options, proto, prop, pd);
179
+ return Mvcc.decorateOperation(false, decorator, options, proto, prop, pd);
175
180
  };
176
181
  }
177
182
  static acquireHandle(obj) {
178
183
  let h = obj[Meta.Handle];
179
184
  if (!h) {
180
185
  if (obj !== Object(obj) || Array.isArray(obj))
181
- throw misuse('only objects can be reactive');
186
+ throw misuse('only objects can be observable');
182
187
  const initial = Meta.getFrom(Object.getPrototypeOf(obj), Meta.Initial);
183
188
  const os = new ObjectSnapshot(EMPTY_SNAPSHOT.changeset, EMPTY_SNAPSHOT, Object.assign({}, initial));
184
- h = new ObjectHandle(obj, obj, Hooks.reactive, os, obj.constructor.name);
189
+ h = new ObjectHandle(obj, obj, Mvcc.observable, os, obj.constructor.name);
185
190
  Meta.set(os.data, Meta.Handle, h);
186
191
  Meta.set(obj, Meta.Handle, h);
187
192
  Meta.set(os.data, Meta.Revision, new Subscription(1));
188
193
  }
189
194
  return h;
190
195
  }
191
- static createHandleForReactronicObject(proto, data, blank, hint, reactive) {
196
+ static createHandleForMvccObject(proto, data, blank, hint, isObservable) {
192
197
  const ctx = Changeset.edit();
193
- const hooks = reactive ? Hooks.reactive : Hooks.transactional;
194
- const h = new ObjectHandle(data, undefined, hooks, EMPTY_SNAPSHOT, hint);
198
+ const mvcc = isObservable ? Mvcc.observable : Mvcc.transactional;
199
+ const h = new ObjectHandle(data, undefined, mvcc, EMPTY_SNAPSHOT, hint);
195
200
  ctx.getEditableObjectSnapshot(h, Meta.Handle, blank);
196
- if (!Hooks.reactionsAutoStartDisabled)
201
+ if (!Mvcc.reactionsAutoStartDisabled)
197
202
  for (const m in Meta.getFrom(proto, Meta.Reactions))
198
203
  h.proxy[m][Meta.Controller].markObsolete();
199
204
  return h;
200
205
  }
201
206
  static setProfilingMode(isOn, options) {
202
207
  if (isOn) {
203
- Hooks.repetitiveUsageWarningThreshold = options && options.repetitiveUsageWarningThreshold !== undefined ? options.repetitiveUsageWarningThreshold : 10;
204
- Hooks.mainThreadBlockingWarningThreshold = options && options.mainThreadBlockingWarningThreshold !== undefined ? options.mainThreadBlockingWarningThreshold : 14;
205
- Hooks.asyncActionDurationWarningThreshold = options && options.asyncActionDurationWarningThreshold !== undefined ? options.asyncActionDurationWarningThreshold : 300;
208
+ Mvcc.repetitiveUsageWarningThreshold = options && options.repetitiveUsageWarningThreshold !== undefined ? options.repetitiveUsageWarningThreshold : 10;
209
+ Mvcc.mainThreadBlockingWarningThreshold = options && options.mainThreadBlockingWarningThreshold !== undefined ? options.mainThreadBlockingWarningThreshold : 14;
210
+ Mvcc.asyncActionDurationWarningThreshold = options && options.asyncActionDurationWarningThreshold !== undefined ? options.asyncActionDurationWarningThreshold : 300;
206
211
  Changeset.garbageCollectionSummaryInterval = options && options.garbageCollectionSummaryInterval !== undefined ? options.garbageCollectionSummaryInterval : 100;
207
212
  }
208
213
  else {
209
- Hooks.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
210
- Hooks.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
211
- Hooks.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
214
+ Mvcc.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
215
+ Mvcc.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
216
+ Mvcc.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
212
217
  Changeset.garbageCollectionSummaryInterval = Number.MAX_SAFE_INTEGER;
213
218
  }
214
219
  }
215
220
  static sensitive(sensitivity, func, ...args) {
216
- const restore = Hooks.sensitivity;
217
- Hooks.sensitivity = sensitivity;
221
+ const restore = Mvcc.sensitivity;
222
+ Mvcc.sensitivity = sensitivity;
218
223
  try {
219
224
  return func(...args);
220
225
  }
221
226
  finally {
222
- Hooks.sensitivity = restore;
227
+ Mvcc.sensitivity = restore;
223
228
  }
224
229
  }
225
230
  static setHint(obj, hint) {
226
231
  if (hint) {
227
- const h = Hooks.acquireHandle(obj);
232
+ const h = Mvcc.acquireHandle(obj);
228
233
  h.hint = hint;
229
234
  }
230
235
  return obj;
231
236
  }
232
237
  static getHint(obj) {
233
- const h = Hooks.acquireHandle(obj);
238
+ const h = Mvcc.acquireHandle(obj);
234
239
  return h.hint;
235
240
  }
236
241
  }
237
- Hooks.reactionsAutoStartDisabled = false;
238
- Hooks.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
239
- Hooks.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
240
- Hooks.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
241
- Hooks.sensitivity = false;
242
- Hooks.transactional = new Hooks(false);
243
- Hooks.reactive = new Hooks(true);
244
- Hooks.createOperation = function (h, m, options) {
245
- throw misuse('createOperation should never be called');
242
+ Mvcc.reactionsAutoStartDisabled = false;
243
+ Mvcc.repetitiveUsageWarningThreshold = Number.MAX_SAFE_INTEGER;
244
+ Mvcc.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
245
+ Mvcc.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
246
+ Mvcc.sensitivity = false;
247
+ Mvcc.transactional = new Mvcc(false);
248
+ Mvcc.observable = new Mvcc(true);
249
+ Mvcc.createOperation = function (h, m, options) {
250
+ throw misuse('this implementation of createOperation should never be called');
246
251
  };
247
- Hooks.rememberOperationOptions = function (proto, m, getter, setter, enumerable, configurable, options, implicit) {
248
- throw misuse('rememberOperationOptions should never be called');
252
+ Mvcc.rememberOperationOptions = function (proto, m, getter, setter, enumerable, configurable, options, implicit) {
253
+ throw misuse('this implementation of rememberOperationOptions should never be called');
249
254
  };
250
255
  const EMPTY_PROP_DESCRIPTOR = {
251
256
  configurable: true,
@@ -0,0 +1,60 @@
1
+ import { MvccObject } from './Mvcc';
2
+ export declare class MvccArray<T> extends MvccObject {
3
+ private all;
4
+ constructor(isObservable: boolean, array: Array<T>);
5
+ get length(): number;
6
+ set length(n: number);
7
+ getItem(n: number): T;
8
+ setItem(n: number, item: T): void;
9
+ toString(): string;
10
+ toLocaleString(): string;
11
+ pop(): T | undefined;
12
+ push(...items: T[]): number;
13
+ concat(...items: (T | ConcatArray<T>)[]): T[];
14
+ concat(...items: ConcatArray<T>[]): T[];
15
+ join(separator?: string): string;
16
+ reverse(): T[];
17
+ shift(): T | undefined;
18
+ slice(start?: number, end?: number): T[];
19
+ sort(compareFn?: (a: T, b: T) => number): this;
20
+ splice(start: number, deleteCount?: number): T[];
21
+ splice(start: number, deleteCount: number, ...items: T[]): T[];
22
+ unshift(...items: T[]): number;
23
+ includes(searchElement: T, fromIndex?: number): boolean;
24
+ indexOf(searchElement: T, fromIndex?: number): number;
25
+ lastIndexOf(searchElement: T, fromIndex?: number): number;
26
+ every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
27
+ every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];
28
+ some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
29
+ forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
30
+ map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
31
+ filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
32
+ filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[];
33
+ reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
34
+ reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
35
+ reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
36
+ reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
37
+ reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
38
+ reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
39
+ find<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
40
+ findIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
41
+ fill(value: T, start?: number, end?: number): this;
42
+ copyWithin(target: number, start: number, end?: number): this;
43
+ [Symbol.iterator](): IterableIterator<T>;
44
+ entries(): IterableIterator<[number, T]>;
45
+ keys(): IterableIterator<number>;
46
+ values(): IterableIterator<T>;
47
+ private get mutable();
48
+ }
49
+ export declare class TransactionalArray<T> extends MvccArray<T> {
50
+ constructor();
51
+ constructor(arrayLength: number);
52
+ constructor(arrayLength?: number);
53
+ constructor(...items: T[]);
54
+ }
55
+ export declare class ObservableArray<T> extends MvccArray<T> {
56
+ constructor();
57
+ constructor(arrayLength: number);
58
+ constructor(arrayLength?: number);
59
+ constructor(...items: T[]);
60
+ }
@@ -0,0 +1,58 @@
1
+ import { Sealant } from '../util/Sealant';
2
+ import { MvccObject } from './Mvcc';
3
+ export class MvccArray extends MvccObject {
4
+ constructor(isObservable, array) {
5
+ super(isObservable);
6
+ this.all = array;
7
+ }
8
+ get length() { return this.all.length; }
9
+ set length(n) { this.mutable.length = n; }
10
+ getItem(n) { return this.all[n]; }
11
+ setItem(n, item) { this.mutable[n] = item; }
12
+ toString() { return this.all.toString(); }
13
+ toLocaleString() { return this.all.toLocaleString(); }
14
+ pop() { return this.mutable.pop(); }
15
+ push(...items) { return this.mutable.push(...items); }
16
+ concat(...items) { return this.all.concat(...items); }
17
+ join(separator) { return this.all.join(separator); }
18
+ reverse() { return this.mutable.reverse(); }
19
+ shift() { return this.mutable.shift(); }
20
+ slice(start, end) { return this.all.slice(start, end); }
21
+ sort(compareFn) { this.mutable.sort(compareFn); return this; }
22
+ splice(start, deleteCount, ...items) { return this.mutable.splice(start, deleteCount, ...items); }
23
+ unshift(...items) { return this.mutable.unshift(...items); }
24
+ includes(searchElement, fromIndex) { return this.all.includes(searchElement, fromIndex); }
25
+ indexOf(searchElement, fromIndex) { return this.all.indexOf(searchElement, fromIndex); }
26
+ lastIndexOf(searchElement, fromIndex) { return this.all.lastIndexOf(searchElement, fromIndex); }
27
+ every(predicate, thisArg) { return this.all.every(predicate, thisArg); }
28
+ some(predicate, thisArg) { return this.all.some(predicate, thisArg); }
29
+ forEach(callbackfn, thisArg) { return this.all.forEach(callbackfn, thisArg); }
30
+ map(callbackfn, thisArg) { return this.all.map(callbackfn, thisArg); }
31
+ filter(predicate, thisArg) { return this.all.filter(predicate, thisArg); }
32
+ reduce(callbackfn, initialValue) { return initialValue !== undefined ? this.all.reduce(callbackfn, initialValue) : this.all.reduce(callbackfn); }
33
+ reduceRight(callbackfn, initialValue) { return initialValue !== undefined ? this.all.reduceRight(callbackfn, initialValue) : this.all.reduceRight(callbackfn); }
34
+ find(predicate, thisArg) { return this.all.find(predicate, thisArg); }
35
+ findIndex(predicate, thisArg) { return this.all.findIndex(predicate, thisArg); }
36
+ fill(value, start, end) { this.mutable.fill(value, start, end); return this; }
37
+ copyWithin(target, start, end) { this.mutable.copyWithin(target, start, end); return this; }
38
+ [Symbol.iterator]() { return this.all[Symbol.iterator](); }
39
+ entries() { return this.all.entries(); }
40
+ keys() { return this.all.keys(); }
41
+ values() { return this.all.values(); }
42
+ get mutable() {
43
+ const createCopy = this.all[Sealant.CreateCopy];
44
+ if (createCopy)
45
+ return this.all = createCopy.call(this.all);
46
+ return this.all;
47
+ }
48
+ }
49
+ export class TransactionalArray extends MvccArray {
50
+ constructor(args) {
51
+ super(false, args !== undefined ? new Array(args) : new Array());
52
+ }
53
+ }
54
+ export class ObservableArray extends MvccArray {
55
+ constructor(args) {
56
+ super(true, args !== undefined ? new Array(args) : new Array());
57
+ }
58
+ }
@@ -0,0 +1,25 @@
1
+ import { Collection, Item, CollectionReader } from '../util/Collection';
2
+ import { ObservableObject } from './Mvcc';
3
+ export declare abstract class ObservableCollection<T> extends ObservableObject implements CollectionReader<T> {
4
+ protected abstract a: Collection<T>;
5
+ get strict(): boolean;
6
+ get count(): number;
7
+ get addedCount(): number;
8
+ get removedCount(): number;
9
+ get isMergeInProgress(): boolean;
10
+ lookup(key: string): Item<T> | undefined;
11
+ claim(key: string): Item<T> | undefined;
12
+ add(self: T): Item<T>;
13
+ remove(item: Item<T>): void;
14
+ move(item: Item<T>, after: Item<T>): void;
15
+ beginMerge(): void;
16
+ endMerge(error?: unknown): void;
17
+ resetAddedAndRemovedLists(): void;
18
+ items(): Generator<Item<T>>;
19
+ addedItems(reset?: boolean): Generator<Item<T>>;
20
+ removedItems(reset?: boolean): Generator<Item<T>>;
21
+ isAdded(item: Item<T>): boolean;
22
+ isMoved(item: Item<T>): boolean;
23
+ isRemoved(item: Item<T>): boolean;
24
+ isCurrent(item: Item<T>): boolean;
25
+ }
@@ -0,0 +1,23 @@
1
+ import { ObservableObject } from './Mvcc';
2
+ export class ObservableCollection extends ObservableObject {
3
+ get strict() { return this.a.strict; }
4
+ get count() { return this.a.count; }
5
+ get addedCount() { return this.a.addedCount; }
6
+ get removedCount() { return this.a.removedCount; }
7
+ get isMergeInProgress() { return this.a.isMergeInProgress; }
8
+ lookup(key) { return this.a.lookup(key); }
9
+ claim(key) { return this.a.claim(key); }
10
+ add(self) { return this.a.add(self); }
11
+ remove(item) { return this.a.remove(item); }
12
+ move(item, after) { this.a.move(item, after); }
13
+ beginMerge() { this.a.beginMerge(); }
14
+ endMerge(error) { this.a.endMerge(error); }
15
+ resetAddedAndRemovedLists() { this.a.resetAddedAndRemovedLists(); }
16
+ items() { return this.a.items(); }
17
+ addedItems(reset) { return this.a.addedItems(reset); }
18
+ removedItems(reset) { return this.a.removedItems(reset); }
19
+ isAdded(item) { return this.a.isAdded(item); }
20
+ isMoved(item) { return this.a.isMoved(item); }
21
+ isRemoved(item) { return this.a.isRemoved(item); }
22
+ isCurrent(item) { return this.a.isCurrent(item); }
23
+ }
@@ -0,0 +1,25 @@
1
+ import { MvccObject } from './Mvcc';
2
+ export declare class MvccMap<K, V> extends MvccObject {
3
+ private all;
4
+ constructor(isObservable: boolean, map: Map<K, V>);
5
+ clear(): void;
6
+ delete(key: K): boolean;
7
+ forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
8
+ get(key: K): V | undefined;
9
+ has(key: K): boolean;
10
+ set(key: K, value: V): this;
11
+ get size(): number;
12
+ entries(): IterableIterator<[K, V]>;
13
+ keys(): IterableIterator<K>;
14
+ values(): IterableIterator<V>;
15
+ [Symbol.toStringTag](): string;
16
+ private get mutable();
17
+ }
18
+ export declare class TransactionalMap<K, V> extends MvccMap<K, V> {
19
+ constructor();
20
+ constructor(iterable?: Iterable<readonly [K, V]> | null);
21
+ }
22
+ export declare class ObservableMap<K, V> extends MvccMap<K, V> {
23
+ constructor();
24
+ constructor(iterable?: Iterable<readonly [K, V]> | null);
25
+ }
@@ -0,0 +1,35 @@
1
+ import { Sealant } from '../util/Sealant';
2
+ import { MvccObject } from './Mvcc';
3
+ export class MvccMap extends MvccObject {
4
+ constructor(isObservable, map) {
5
+ super(isObservable);
6
+ this.all = map;
7
+ }
8
+ clear() { this.mutable.clear(); }
9
+ delete(key) { return this.mutable.delete(key); }
10
+ forEach(callbackfn, thisArg) { this.all.forEach(callbackfn, thisArg); }
11
+ get(key) { return this.all.get(key); }
12
+ has(key) { return this.all.has(key); }
13
+ set(key, value) { this.mutable.set(key, value); return this; }
14
+ get size() { return this.all.size; }
15
+ entries() { return this.all.entries(); }
16
+ keys() { return this.all.keys(); }
17
+ values() { return this.all.values(); }
18
+ [Symbol.toStringTag]() { return this.all[Symbol.toStringTag]; }
19
+ get mutable() {
20
+ const createCopy = this.all[Sealant.CreateCopy];
21
+ if (createCopy)
22
+ return this.all = createCopy.call(this.all);
23
+ return this.all;
24
+ }
25
+ }
26
+ export class TransactionalMap extends MvccMap {
27
+ constructor(args) {
28
+ super(true, args !== undefined ? new Map(args) : new Map());
29
+ }
30
+ }
31
+ export class ObservableMap extends MvccMap {
32
+ constructor(args) {
33
+ super(true, args !== undefined ? new Map(args) : new Map());
34
+ }
35
+ }
@@ -3,7 +3,7 @@ import { MemberOptions } from '../Options';
3
3
  import { Controller } from '../Controller';
4
4
  import { MemberName, ObjectHandle, Subscription, Subscriber, SubscriptionInfo, AbstractChangeset } from './Data';
5
5
  import { Transaction } from './Transaction';
6
- import { OptionsImpl } from './Hooks';
6
+ import { OptionsImpl } from './Mvcc';
7
7
  export declare class OperationController extends Controller<any> {
8
8
  readonly objectHandle: ObjectHandle;
9
9
  readonly memberName: MemberName;
@@ -19,7 +19,7 @@ export declare class OperationController extends Controller<any> {
19
19
  pullLastResult(args?: any[]): any;
20
20
  constructor(h: ObjectHandle, m: MemberName);
21
21
  useOrRun(weak: boolean, args: any[] | undefined): Operation;
22
- static of(method: F<any>): Controller<any>;
22
+ static getControllerOf(method: F<any>): Controller<any>;
23
23
  static configureImpl(self: OperationController | undefined, options: Partial<MemberOptions>): MemberOptions;
24
24
  static runWithin<T>(op: Operation | undefined, func: F<T>, ...args: any[]): T;
25
25
  static why(): string;
@@ -55,7 +55,7 @@ declare class Operation extends Subscription implements Subscriber {
55
55
  get originSnapshotId(): number;
56
56
  hint(): string;
57
57
  get order(): number;
58
- get ['#this'](): string;
58
+ get ['#this#'](): string;
59
59
  why(): string;
60
60
  briefWhy(): string;
61
61
  dependencies(): string[];
@@ -5,11 +5,11 @@ import { ObjectHandle, Subscription, Meta } from './Data';
5
5
  import { Changeset, Dump, EMPTY_SNAPSHOT, MAX_REVISION } from './Changeset';
6
6
  import { Transaction } from './Transaction';
7
7
  import { MonitorImpl } from './Monitor';
8
- import { Hooks, OptionsImpl } from './Hooks';
8
+ import { Mvcc, OptionsImpl } from './Mvcc';
9
9
  import { JournalImpl } from './Journal';
10
10
  const BOOT_ARGS = [];
11
11
  const BOOT_CAUSE = '<boot>';
12
- const EMPTY_HANDLE = new ObjectHandle(undefined, undefined, Hooks.reactive, EMPTY_SNAPSHOT, '<empty>');
12
+ const EMPTY_HANDLE = new ObjectHandle(undefined, undefined, Mvcc.observable, EMPTY_SNAPSHOT, '<empty>');
13
13
  export class OperationController extends Controller {
14
14
  constructor(h, m) {
15
15
  super();
@@ -36,12 +36,12 @@ export class OperationController extends Controller {
36
36
  && (!weak || op.cause === BOOT_CAUSE || !op.successor ||
37
37
  op.successor.transaction.isFinished)) {
38
38
  const outerOpts = (_a = Operation.current) === null || _a === void 0 ? void 0 : _a.options;
39
- const standalone = weak || opts.standalone || opts.kind === Kind.Reaction ||
39
+ const separation = weak || opts.separation || opts.kind === Kind.Reaction ||
40
40
  (opts.kind === Kind.Transaction && outerOpts && (outerOpts.noSideEffects || outerOpts.kind === Kind.Cache)) ||
41
41
  (opts.kind === Kind.Cache && (oc.snapshot.changeset.sealed ||
42
42
  oc.snapshot.former.snapshot !== EMPTY_SNAPSHOT));
43
43
  const token = opts.noSideEffects ? this : undefined;
44
- const oc2 = this.run(oc, standalone, opts, token, args);
44
+ const oc2 = this.run(oc, separation, opts, token, args);
45
45
  const ctx2 = oc2.operation.changeset;
46
46
  if (!weak || ctx === ctx2 || (ctx2.sealed && ctx.timestamp >= ctx2.timestamp))
47
47
  oc = oc2;
@@ -53,7 +53,7 @@ export class OperationController extends Controller {
53
53
  Changeset.markUsed(t, oc.snapshot, this.memberName, this.objectHandle, t.options.kind, weak);
54
54
  return t;
55
55
  }
56
- static of(method) {
56
+ static getControllerOf(method) {
57
57
  const ctl = Meta.get(method, Meta.Controller);
58
58
  if (!ctl)
59
59
  throw misuse(`given method is not decorated as reactronic one: ${method.name}`);
@@ -137,8 +137,8 @@ export class OperationController extends Controller {
137
137
  if (op.controller !== this) {
138
138
  if (os.changeset !== EMPTY_SNAPSHOT.changeset) {
139
139
  const hint = Log.isOn ? `${Dump.obj(this.objectHandle, m)}/boot` : 'MethodController/init';
140
- const standalone = os.changeset.sealed || os.former.snapshot !== EMPTY_SNAPSHOT;
141
- op = Transaction.run({ hint, standalone, token: this }, () => {
140
+ const separation = os.changeset.sealed || os.former.snapshot !== EMPTY_SNAPSHOT;
141
+ op = Transaction.run({ hint, separation, token: this }, () => {
142
142
  const h = this.objectHandle;
143
143
  let r2 = Changeset.current().getObjectSnapshot(h, m);
144
144
  let op2 = r2.data[m];
@@ -168,10 +168,10 @@ export class OperationController extends Controller {
168
168
  }
169
169
  return op;
170
170
  }
171
- run(existing, standalone, options, token, args) {
171
+ run(existing, separation, options, token, args) {
172
172
  const hint = Log.isOn ? `${Dump.obj(this.objectHandle, this.memberName)}${args && args.length > 0 && (typeof args[0] === 'number' || typeof args[0] === 'string') ? ` - ${args[0]}` : ''}` : `${Dump.obj(this.objectHandle, this.memberName)}`;
173
173
  let oc = existing;
174
- const opts = { hint, standalone, journal: options.journal, logging: options.logging, token };
174
+ const opts = { hint, separation, journal: options.journal, logging: options.logging, token };
175
175
  const result = Transaction.run(opts, (argsx) => {
176
176
  if (!oc.operation.transaction.isCanceled) {
177
177
  oc = this.edit();
@@ -226,7 +226,7 @@ class Operation extends Subscription {
226
226
  get originSnapshotId() { return this.changeset.id; }
227
227
  hint() { return `${Dump.snapshot2(this.controller.objectHandle, this.changeset, this.controller.memberName)}`; }
228
228
  get order() { return this.options.order; }
229
- get ['#this']() {
229
+ get ['#this#']() {
230
230
  return `Operation: ${this.why()}`;
231
231
  }
232
232
  why() {
@@ -254,7 +254,7 @@ class Operation extends Subscription {
254
254
  const ms = Date.now() - started;
255
255
  if (Log.isOn && Log.opt.step && this.result)
256
256
  Log.writeAs({ margin2: this.margin }, '║', '_/', `${this.hint()} - step out `, 0, this.started > 0 ? ' │' : '');
257
- if (ms > Hooks.mainThreadBlockingWarningThreshold)
257
+ if (ms > Mvcc.mainThreadBlockingWarningThreshold)
258
258
  Log.write('', '[!]', this.why(), ms, ' *** main thread is too busy ***');
259
259
  return result;
260
260
  };
@@ -410,7 +410,7 @@ class Operation extends Subscription {
410
410
  this.started = -this.started;
411
411
  if (Log.isOn && Log.opt.operation)
412
412
  Log.write('║', `${op}`, `${this.hint()} ${message}`, ms, highlight);
413
- if (ms > (main ? Hooks.mainThreadBlockingWarningThreshold : Hooks.asyncActionDurationWarningThreshold))
413
+ if (ms > (main ? Mvcc.mainThreadBlockingWarningThreshold : Mvcc.asyncActionDurationWarningThreshold))
414
414
  Log.write('', '[!]', this.why(), ms, main ? ' *** main thread is too busy ***' : ' *** async is too long ***');
415
415
  this.cause = undefined;
416
416
  if (this.options.monitor)
@@ -419,17 +419,17 @@ class Operation extends Subscription {
419
419
  monitorEnter(mon) {
420
420
  const options = {
421
421
  hint: 'Monitor.enter',
422
- standalone: 'isolated',
422
+ separation: 'isolated',
423
423
  logging: Log.isOn && Log.opt.monitor ? undefined : Log.global
424
424
  };
425
425
  OperationController.runWithin(undefined, Transaction.run, options, MonitorImpl.enter, mon, this.transaction);
426
426
  }
427
427
  monitorLeave(mon) {
428
- Transaction.off(() => {
428
+ Transaction.outside(() => {
429
429
  const leave = () => {
430
430
  const options = {
431
431
  hint: 'Monitor.leave',
432
- standalone: 'isolated',
432
+ separation: 'isolated',
433
433
  logging: Log.isOn && Log.opt.monitor ? undefined : Log.DefaultLevel
434
434
  };
435
435
  OperationController.runWithin(undefined, Transaction.run, options, MonitorImpl.leave, mon, this.transaction);
@@ -520,9 +520,9 @@ class Operation extends Subscription {
520
520
  }
521
521
  if (curr instanceof Operation) {
522
522
  if (curr.changeset === os.changeset && curr.subscriptions !== undefined) {
523
- if (Hooks.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
523
+ if (Mvcc.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
524
524
  curr.subscriptions.forEach((info, v) => {
525
- if (info.usageCount > Hooks.repetitiveUsageWarningThreshold)
525
+ if (info.usageCount > Mvcc.repetitiveUsageWarningThreshold)
526
526
  Log.write('', '[!]', `${curr.hint()} uses ${info.memberHint} ${info.usageCount} times (consider remembering it in a local variable)`, 0, ' *** WARNING ***');
527
527
  });
528
528
  }
@@ -566,7 +566,7 @@ class Operation extends Subscription {
566
566
  const ok = Operation.canSubscribe(subscription, os, m, h, timestamp);
567
567
  if (ok) {
568
568
  let times = 0;
569
- if (Hooks.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
569
+ if (Mvcc.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
570
570
  const existing = this.subscriptions.get(subscription);
571
571
  times = existing ? existing.usageCount + 1 : 1;
572
572
  }
@@ -628,8 +628,8 @@ class Operation extends Subscription {
628
628
  Changeset.propagateAllChangesThroughSubscriptions = Operation.propagateAllChangesThroughSubscriptions;
629
629
  Changeset.revokeAllSubscriptions = Operation.revokeAllSubscriptions;
630
630
  Changeset.enqueueReactionsToRun = Operation.enqueueReactionsToRun;
631
- Hooks.createOperation = Operation.createOperation;
632
- Hooks.rememberOperationOptions = Operation.rememberOperationOptions;
631
+ Mvcc.createOperation = Operation.createOperation;
632
+ Mvcc.rememberOperationOptions = Operation.rememberOperationOptions;
633
633
  Promise.prototype.then = reactronicHookedThen;
634
634
  try {
635
635
  Object.defineProperty(globalThis, 'rWhy', {
@@ -22,8 +22,8 @@ export declare abstract class Transaction implements Worker {
22
22
  whenFinished(): Promise<void>;
23
23
  static create(options: SnapshotOptions | null): Transaction;
24
24
  static run<T>(options: SnapshotOptions | null, func: F<T>, ...args: any[]): T;
25
- static standalone<T>(func: F<T>, ...args: any[]): T;
26
- static off<T>(func: F<T>, ...args: any[]): T;
25
+ static separate<T>(func: F<T>, ...args: any[]): T;
26
+ static outside<T>(func: F<T>, ...args: any[]): T;
27
27
  static isFrameOver(everyN?: number, timeLimit?: number): boolean;
28
28
  static requestNextFrame(sleepTime?: number): Promise<void>;
29
29
  static get isCanceled(): boolean;