reactronic 0.22.315 → 0.22.316

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 (33) hide show
  1. package/README.md +6 -6
  2. package/build/dist/source/Buffer.d.ts +1 -1
  3. package/build/dist/source/Buffer.js +1 -1
  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 +4 -4
  8. package/build/dist/source/api.js +4 -4
  9. package/build/dist/source/impl/Changeset.js +5 -5
  10. package/build/dist/source/impl/Data.d.ts +1 -1
  11. package/build/dist/source/impl/Journal.d.ts +1 -1
  12. package/build/dist/source/impl/Journal.js +4 -4
  13. package/build/dist/source/impl/Monitor.d.ts +1 -1
  14. package/build/dist/source/impl/Monitor.js +4 -4
  15. package/build/dist/source/impl/{Hooks.d.ts → Mvcc.d.ts} +11 -8
  16. package/build/dist/source/impl/{Hooks.js → Mvcc.js} +49 -44
  17. package/build/dist/source/impl/MvccArray.d.ts +60 -0
  18. package/build/dist/source/impl/MvccArray.js +58 -0
  19. package/build/dist/source/impl/MvccCollection.d.ts +25 -0
  20. package/build/dist/source/impl/MvccCollection.js +23 -0
  21. package/build/dist/source/impl/MvccMap.d.ts +25 -0
  22. package/build/dist/source/impl/MvccMap.js +35 -0
  23. package/build/dist/source/impl/Operation.d.ts +3 -3
  24. package/build/dist/source/impl/Operation.js +20 -20
  25. package/build/dist/source/impl/Transaction.d.ts +2 -2
  26. package/build/dist/source/impl/Transaction.js +9 -9
  27. package/build/dist/source/util/Collection.d.ts +3 -1
  28. package/build/dist/source/util/Collection.js +16 -8
  29. package/package.json +1 -1
  30. package/build/dist/source/impl/ReactiveArray.d.ts +0 -33
  31. package/build/dist/source/impl/ReactiveArray.js +0 -42
  32. package/build/dist/source/impl/ReactiveMap.d.ts +0 -15
  33. package/build/dist/source/impl/ReactiveMap.js +0 -24
@@ -0,0 +1,60 @@
1
+ import { MvccObject } from './Mvcc';
2
+ export declare class MvccArray<T> extends MvccObject {
3
+ private all;
4
+ constructor(reactive: 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 ReactiveArray<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(reactive, array) {
5
+ super(reactive);
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 ReactiveArray 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 { ReactiveObject } from './Mvcc';
3
+ export declare abstract class ReactiveCollection<T> extends ReactiveObject 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 { ReactiveObject } from './Mvcc';
2
+ export class ReactiveCollection extends ReactiveObject {
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(reactive: 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 ReactiveMap<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(reactive, map) {
5
+ super(reactive);
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 ReactiveMap 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.reactive, 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;
@@ -17,8 +17,8 @@ export class Transaction {
17
17
  }
18
18
  static create(options) { return new TransactionImpl(options); }
19
19
  static run(options, func, ...args) { return TransactionImpl.run(options, func, ...args); }
20
- static standalone(func, ...args) { return TransactionImpl.standalone(func, ...args); }
21
- static off(func, ...args) { return TransactionImpl.off(func, ...args); }
20
+ static separate(func, ...args) { return TransactionImpl.separate(func, ...args); }
21
+ static outside(func, ...args) { return TransactionImpl.outside(func, ...args); }
22
22
  static isFrameOver(everyN = 1, timeLimit = 10) { return TransactionImpl.isFrameOver(everyN, timeLimit); }
23
23
  static requestNextFrame(sleepTime = 0) { return TransactionImpl.requestNextFrame(sleepTime); }
24
24
  static get isCanceled() { return TransactionImpl.current.isCanceled; }
@@ -118,7 +118,7 @@ class TransactionImpl extends Transaction {
118
118
  let result = t.runImpl(options === null || options === void 0 ? void 0 : options.logging, func, ...args);
119
119
  if (root) {
120
120
  if (result instanceof Promise) {
121
- result = TransactionImpl.off(() => {
121
+ result = TransactionImpl.outside(() => {
122
122
  return t.wrapToRetry(t.wrapToWaitUntilFinish(result), func, ...args);
123
123
  });
124
124
  }
@@ -126,10 +126,10 @@ class TransactionImpl extends Transaction {
126
126
  }
127
127
  return result;
128
128
  }
129
- static standalone(func, ...args) {
130
- return TransactionImpl.run({ standalone: true }, func, ...args);
129
+ static separate(func, ...args) {
130
+ return TransactionImpl.run({ separation: true }, func, ...args);
131
131
  }
132
- static off(func, ...args) {
132
+ static outside(func, ...args) {
133
133
  const outer = TransactionImpl.curr;
134
134
  try {
135
135
  TransactionImpl.curr = TransactionImpl.none;
@@ -153,7 +153,7 @@ class TransactionImpl extends Transaction {
153
153
  }
154
154
  static acquire(options) {
155
155
  const curr = TransactionImpl.curr;
156
- if ((options === null || options === void 0 ? void 0 : options.standalone) || curr.isFinished || curr.options.standalone === 'isolated')
156
+ if ((options === null || options === void 0 ? void 0 : options.separation) || curr.isFinished || curr.options.separation === 'isolated')
157
157
  return new TransactionImpl(options);
158
158
  else
159
159
  return TransactionImpl.curr;
@@ -176,7 +176,7 @@ class TransactionImpl extends Transaction {
176
176
  yield this.after.whenFinished();
177
177
  const options = {
178
178
  hint: `${this.hint} - restart after T${this.after.id}`,
179
- standalone: this.options.standalone === 'isolated' ? 'isolated' : true,
179
+ separation: this.options.separation === 'isolated' ? 'isolated' : true,
180
180
  logging: this.changeset.options.logging,
181
181
  token: this.changeset.options.token,
182
182
  };
@@ -226,7 +226,7 @@ class TransactionImpl extends Transaction {
226
226
  if (this.sealed && this.pending === 0) {
227
227
  const reactions = this.applyOrDiscard();
228
228
  TransactionImpl.curr = outer;
229
- TransactionImpl.off(Changeset.enqueueReactionsToRun, reactions);
229
+ TransactionImpl.outside(Changeset.enqueueReactionsToRun, reactions);
230
230
  }
231
231
  else
232
232
  TransactionImpl.curr = outer;
@@ -42,7 +42,9 @@ export declare class Collection<T> implements CollectionReader<T> {
42
42
  get removedCount(): number;
43
43
  get isMergeInProgress(): boolean;
44
44
  lookup(key: string | undefined): Item<T> | undefined;
45
- claim(key: string): Item<T> | undefined;
45
+ claim(key: string, resolution?: {
46
+ isDuplicate: boolean;
47
+ }): Item<T> | undefined;
46
48
  add(self: T): Item<T>;
47
49
  remove(item: Item<T>): void;
48
50
  move(item: Item<T>, after: Item<T>): void;
@@ -37,7 +37,7 @@ export class Collection {
37
37
  }
38
38
  return result;
39
39
  }
40
- claim(key) {
40
+ claim(key, resolution) {
41
41
  const tag = this.tag;
42
42
  if (tag < 0)
43
43
  throw new Error('merge is not in progress');
@@ -45,15 +45,23 @@ export class Collection {
45
45
  if (key !== (item ? this.getKey(item.self) : undefined))
46
46
  item = this.lookup(key);
47
47
  if (item) {
48
- if (item.tag === tag)
48
+ if (item.tag !== tag) {
49
+ item.tag = tag;
50
+ if (this.strict && item !== this.strictNextItem)
51
+ item.status = tag;
52
+ this.strictNextItem = item.next;
53
+ this.removed.exclude(item);
54
+ this.current.include(item);
55
+ if (resolution)
56
+ resolution.isDuplicate = false;
57
+ }
58
+ else if (resolution)
59
+ resolution.isDuplicate = true;
60
+ else
49
61
  throw new Error(`duplicate item: ${key}`);
50
- item.tag = tag;
51
- if (this.strict && item !== this.strictNextItem)
52
- item.status = tag;
53
- this.strictNextItem = item.next;
54
- this.removed.exclude(item);
55
- this.current.include(item);
56
62
  }
63
+ else if (resolution)
64
+ resolution.isDuplicate = false;
57
65
  return item;
58
66
  }
59
67
  add(self) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.22.315",
3
+ "version": "0.22.316",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "type": "module",
6
6
  "main": "build/dist/source/api.js",
@@ -1,33 +0,0 @@
1
- import { ReactiveObject } from './Hooks';
2
- export declare class ReactiveArray<T> extends ReactiveObject {
3
- private a;
4
- get length(): number;
5
- set length(n: number);
6
- get(n: number): T;
7
- set(n: number, item: T): void;
8
- toString(): string;
9
- toLocaleString(): string;
10
- pop(): T | undefined;
11
- push(...items: T[]): number;
12
- concat(...items: (T | ConcatArray<T>)[]): T[];
13
- join(separator?: string): string;
14
- reverse(): T[];
15
- shift(): T | undefined;
16
- slice(start?: number, end?: number): T[];
17
- sort(compareFn?: (a: T, b: T) => number): this;
18
- splice(start: number, deleteCount?: number): T[];
19
- unshift(...items: T[]): number;
20
- indexOf(searchElement: T, fromIndex?: number): number;
21
- lastIndexOf(searchElement: T, fromIndex?: number): number;
22
- every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
23
- some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
24
- forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
25
- map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
26
- filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
27
- reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
28
- reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
29
- entries(): IterableIterator<[number, T]>;
30
- keys(): IterableIterator<number>;
31
- values(): IterableIterator<T>;
32
- private get mutable();
33
- }
@@ -1,42 +0,0 @@
1
- import { Sealant } from '../util/Sealant';
2
- import { ReactiveObject } from './Hooks';
3
- export class ReactiveArray extends ReactiveObject {
4
- constructor() {
5
- super(...arguments);
6
- this.a = new Array();
7
- }
8
- get length() { return this.a.length; }
9
- set length(n) { this.a.length = n; }
10
- get(n) { return this.a[n]; }
11
- set(n, item) { this.mutable[n] = item; }
12
- toString() { return this.a.toString(); }
13
- toLocaleString() { return this.a.toLocaleString(); }
14
- pop() { return this.mutable.pop(); }
15
- push(...items) { return this.mutable.push(...items); }
16
- concat(...items) { return this.a.concat(...items); }
17
- join(separator) { return this.a.join(separator); }
18
- reverse() { return this.mutable.reverse(); }
19
- shift() { return this.mutable.shift(); }
20
- slice(start, end) { return this.a.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
- indexOf(searchElement, fromIndex) { return this.a.indexOf(searchElement, fromIndex); }
25
- lastIndexOf(searchElement, fromIndex) { return this.a.lastIndexOf(searchElement, fromIndex); }
26
- every(predicate, thisArg) { return this.a.every(predicate, thisArg); }
27
- some(predicate, thisArg) { return this.a.some(predicate, thisArg); }
28
- forEach(callbackfn, thisArg) { return this.a.forEach(callbackfn, thisArg); }
29
- map(callbackfn, thisArg) { return this.a.map(callbackfn, thisArg); }
30
- filter(predicate, thisArg) { return this.a.filter(predicate, thisArg); }
31
- reduce(callbackfn, initialValue) { return this.a.reduce(callbackfn, initialValue); }
32
- reduceRight(callbackfn, initialValue) { return this.a.reduceRight(callbackfn, initialValue); }
33
- entries() { return this.a.entries(); }
34
- keys() { return this.a.keys(); }
35
- values() { return this.a.values(); }
36
- get mutable() {
37
- const createCopy = this.a[Sealant.CreateCopy];
38
- if (createCopy)
39
- return this.a = createCopy.call(this.a);
40
- return this.a;
41
- }
42
- }
@@ -1,15 +0,0 @@
1
- import { ReactiveObject } from './Hooks';
2
- export declare class ReactiveMap<K, V> extends ReactiveObject {
3
- private m;
4
- clear(): void;
5
- delete(key: K): boolean;
6
- forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
7
- get(key: K): V | undefined;
8
- has(key: K): boolean;
9
- set(key: K, value: V): this;
10
- get size(): number;
11
- entries(): IterableIterator<[K, V]>;
12
- keys(): IterableIterator<K>;
13
- values(): IterableIterator<V>;
14
- private get mutable();
15
- }
@@ -1,24 +0,0 @@
1
- import { Sealant } from '../util/Sealant';
2
- import { ReactiveObject } from './Hooks';
3
- export class ReactiveMap extends ReactiveObject {
4
- constructor() {
5
- super(...arguments);
6
- this.m = new Map();
7
- }
8
- clear() { this.mutable.clear(); }
9
- delete(key) { return this.mutable.delete(key); }
10
- forEach(callbackfn, thisArg) { this.m.forEach(callbackfn, thisArg); }
11
- get(key) { return this.m.get(key); }
12
- has(key) { return this.m.has(key); }
13
- set(key, value) { this.mutable.set(key, value); return this; }
14
- get size() { return this.m.size; }
15
- entries() { return this.m.entries(); }
16
- keys() { return this.m.keys(); }
17
- values() { return this.m.values(); }
18
- get mutable() {
19
- const createCopy = this.m[Sealant.CreateCopy];
20
- if (createCopy)
21
- return this.m = createCopy.call(this.m);
22
- return this.m;
23
- }
24
- }