reactronic 0.22.504 → 0.22.506

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.
@@ -4,6 +4,15 @@ export declare type BoolOnly<T> = Pick<T, {
4
4
  export declare type GivenTypeOnly<T, V> = Pick<T, {
5
5
  [P in keyof T]: T[P] extends V ? P : never;
6
6
  }[keyof T]>;
7
+ export declare function refs<O extends object = object>(owner: O): {
8
+ readonly [P in keyof O]-?: Ref<O[P]>;
9
+ };
10
+ export declare function toggleRefs<O extends object = object>(owner: O): {
11
+ readonly [P in keyof BoolOnly<O>]: ToggleRef<O[P]>;
12
+ };
13
+ export declare function customToggleRefs<T, O extends object = any>(owner: O, value1: T, value2: T): {
14
+ readonly [P in keyof GivenTypeOnly<O, T | any>]: ToggleRef<O[P]>;
15
+ };
7
16
  export declare class Ref<T = any> {
8
17
  readonly owner: any;
9
18
  readonly name: string;
@@ -14,15 +23,6 @@ export declare class Ref<T = any> {
14
23
  unobservable(): T;
15
24
  observe(): T;
16
25
  unobserve(): T;
17
- static to<O extends object = object>(owner: O): {
18
- readonly [P in keyof O]-?: Ref<O[P]>;
19
- };
20
- static toToggle<O extends object = object>(owner: O): {
21
- readonly [P in keyof BoolOnly<O>]: ToggleRef<O[P]>;
22
- };
23
- static toCustomToggle<T, O extends object = any>(owner: O, value1: T, value2: T): {
24
- readonly [P in keyof GivenTypeOnly<O, T | any>]: ToggleRef<O[P]>;
25
- };
26
26
  static sameRefs(v1: Ref, v2: Ref): boolean;
27
27
  static similarRefs(v1: Ref, v2: Ref): boolean;
28
28
  }
@@ -1,5 +1,15 @@
1
1
  import { Transaction } from './impl/Transaction';
2
2
  import { nonreactive } from './Rx';
3
+ export function refs(owner) {
4
+ return new Proxy(owner, RefGettingProxy);
5
+ }
6
+ export function toggleRefs(owner) {
7
+ return new Proxy(owner, BoolRefGettingProxy);
8
+ }
9
+ export function customToggleRefs(owner, value1, value2) {
10
+ const handler = new CustomToggleRefGettingProxy(value1, value2);
11
+ return new Proxy(owner, handler);
12
+ }
3
13
  export class Ref {
4
14
  constructor(owner, name, index = -1) {
5
15
  this.owner = owner;
@@ -27,16 +37,6 @@ export class Ref {
27
37
  unobserve() {
28
38
  throw new Error('not implemented');
29
39
  }
30
- static to(owner) {
31
- return new Proxy(owner, RefGettingProxy);
32
- }
33
- static toToggle(owner) {
34
- return new Proxy(owner, BoolRefGettingProxy);
35
- }
36
- static toCustomToggle(owner, value1, value2) {
37
- const handler = new CustomToggleRefGettingProxy(value1, value2);
38
- return new Proxy(owner, handler);
39
- }
40
40
  static sameRefs(v1, v2) {
41
41
  return v1.owner === v2.owner && v1.name === v2.name && v1.index === v2.index;
42
42
  }
@@ -21,6 +21,7 @@ export declare class Rx {
21
21
  export declare function nonreactive<T>(func: F<T>, ...args: any[]): T;
22
22
  export declare function sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
23
23
  export declare function raw(proto: object, prop: PropertyKey): any;
24
+ export declare function observable(proto: object, prop: PropertyKey): any;
24
25
  export declare function transactional(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
25
26
  export declare function reactive(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
26
27
  export declare function cached(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
@@ -30,6 +30,9 @@ export function sensitive(sensitivity, func, ...args) {
30
30
  export function raw(proto, prop) {
31
31
  return Mvcc.decorateData(false, proto, prop);
32
32
  }
33
+ export function observable(proto, prop) {
34
+ return Mvcc.decorateData(true, proto, prop);
35
+ }
33
36
  export function transactional(proto, prop, pd) {
34
37
  const opts = { kind: Kind.Transactional };
35
38
  return Mvcc.decorateOperation(true, transactional, opts, proto, prop, pd);
@@ -17,4 +17,4 @@ export { Changeset } from './impl/Changeset';
17
17
  export { Transaction } from './impl/Transaction';
18
18
  export { Monitor } from './impl/Monitor';
19
19
  export { Journal } from './impl/Journal';
20
- export { Rx, raw, transactional, reactive, cached, nonreactive, sensitive, options } from './Rx';
20
+ export { Rx, raw, observable, transactional, reactive, cached, nonreactive, sensitive, options } from './Rx';
@@ -13,4 +13,4 @@ export { Changeset } from './impl/Changeset';
13
13
  export { Transaction } from './impl/Transaction';
14
14
  export { Monitor } from './impl/Monitor';
15
15
  export { Journal } from './impl/Journal';
16
- export { Rx, raw, transactional, reactive, cached, nonreactive, sensitive, options } from './Rx';
16
+ export { Rx, raw, observable, transactional, reactive, cached, nonreactive, sensitive, options } from './Rx';
@@ -1,5 +1,5 @@
1
1
  import { Kind, SnapshotOptions } from '../Options';
2
- import { AbstractChangeset, ObjectSnapshot, MemberName, ObjectHandle, Subscription, Subscriber } from './Data';
2
+ import { AbstractChangeset, ObjectSnapshot, MemberName, ObjectHandle, Observable, Observer } from './Data';
3
3
  export declare const MAX_REVISION: number;
4
4
  export declare const UNDEFINED_REVISION: number;
5
5
  export declare class Changeset implements AbstractChangeset {
@@ -18,17 +18,17 @@ export declare class Changeset implements AbstractChangeset {
18
18
  private revision;
19
19
  private bumper;
20
20
  items: Map<ObjectHandle, ObjectSnapshot>;
21
- reactive: Subscriber[];
21
+ reactive: Observer[];
22
22
  sealed: boolean;
23
23
  constructor(options: SnapshotOptions | null);
24
24
  static current: () => Changeset;
25
25
  static edit: () => Changeset;
26
- static markUsed: (subscription: Subscription, os: ObjectSnapshot, m: MemberName, h: ObjectHandle, kind: Kind, weak: boolean) => void;
26
+ static markUsed: (observable: Observable, os: ObjectSnapshot, m: MemberName, h: ObjectHandle, kind: Kind, weak: boolean) => void;
27
27
  static markEdited: (oldValue: any, newValue: any, edited: boolean, os: ObjectSnapshot, m: MemberName, h: ObjectHandle) => void;
28
28
  static isConflicting: (oldValue: any, newValue: any) => boolean;
29
29
  static propagateAllChangesThroughSubscriptions: (changeset: Changeset) => void;
30
30
  static revokeAllSubscriptions: (changeset: Changeset) => void;
31
- static enqueueReactiveFunctionsToRun: (reactive: Array<Subscriber>) => void;
31
+ static enqueueReactiveFunctionsToRun: (reactive: Array<Observer>) => void;
32
32
  lookupObjectSnapshot(h: ObjectHandle, m: MemberName): ObjectSnapshot;
33
33
  getObjectSnapshot(h: ObjectHandle, m: MemberName): ObjectSnapshot;
34
34
  getEditableObjectSnapshot(h: ObjectHandle, m: MemberName, value: any, token?: any): ObjectSnapshot;
@@ -40,9 +40,9 @@ export declare class Changeset implements AbstractChangeset {
40
40
  bumpBy(timestamp: number): void;
41
41
  rebase(): ObjectSnapshot[] | undefined;
42
42
  private merge;
43
- applyOrDiscard(error?: any): Array<Subscriber>;
43
+ applyOrDiscard(error?: any): Array<Observer>;
44
44
  static sealObjectSnapshot(h: ObjectHandle, os: ObjectSnapshot): void;
45
- static sealSubscription(subscription: Subscription | symbol, m: MemberName, typeName: string): void;
45
+ static sealObservable(o: Observable | symbol, m: MemberName, typeName: string): void;
46
46
  static freezeObjectSnapshot(os: ObjectSnapshot): ObjectSnapshot;
47
47
  triggerGarbageCollection(): void;
48
48
  private unlinkHistory;
@@ -51,7 +51,7 @@ export declare class Changeset implements AbstractChangeset {
51
51
  export declare class Dump {
52
52
  static valueHint: (value: any, m?: MemberName) => string;
53
53
  static obj(h: ObjectHandle | undefined, m?: MemberName | undefined, stamp?: number, snapshotId?: number, originSnapshotId?: number, value?: any): string;
54
- static snapshot2(h: ObjectHandle, s: AbstractChangeset, m?: MemberName, o?: Subscription): string;
54
+ static snapshot2(h: ObjectHandle, s: AbstractChangeset, m?: MemberName, o?: Observable): string;
55
55
  static snapshot(os: ObjectSnapshot, m?: MemberName): string;
56
56
  static conflicts(conflicts: ObjectSnapshot[]): string;
57
57
  static conflictingMemberHint(m: MemberName, ours: ObjectSnapshot, theirs: ObjectSnapshot): string;
@@ -4,7 +4,7 @@ import { Sealant } from '../util/Sealant';
4
4
  import { SealedArray } from '../util/SealedArray';
5
5
  import { SealedMap } from '../util/SealedMap';
6
6
  import { SealedSet } from '../util/SealedSet';
7
- import { ObjectSnapshot, ObjectHandle, Subscription, Meta } from './Data';
7
+ import { ObjectSnapshot, ObjectHandle, Observable, Meta } from './Data';
8
8
  export const MAX_REVISION = Number.MAX_SAFE_INTEGER;
9
9
  export const UNDEFINED_REVISION = MAX_REVISION - 1;
10
10
  Object.defineProperty(ObjectHandle.prototype, '#this#', {
@@ -14,7 +14,7 @@ Object.defineProperty(ObjectHandle.prototype, '#this#', {
14
14
  const data = Changeset.current().getObjectSnapshot(this, '#this#').data;
15
15
  for (const m in data) {
16
16
  const v = data[m];
17
- if (v instanceof Subscription)
17
+ if (v instanceof Observable)
18
18
  result[m] = v.content;
19
19
  else if (v === Meta.Raw)
20
20
  result[m] = this.data[m];
@@ -67,7 +67,7 @@ export class Changeset {
67
67
  const revision = m === Meta.Handle ? 1 : os.revision + 1;
68
68
  const data = Object.assign({}, m === Meta.Handle ? value : os.data);
69
69
  Meta.set(data, Meta.Handle, h);
70
- Meta.set(data, Meta.Revision, new Subscription(revision));
70
+ Meta.set(data, Meta.Revision, new Observable(revision));
71
71
  os = new ObjectSnapshot(this, os, data);
72
72
  this.items.set(h, os);
73
73
  h.editing = os;
@@ -218,20 +218,20 @@ export class Changeset {
218
218
  }
219
219
  static sealObjectSnapshot(h, os) {
220
220
  if (!os.disposed)
221
- os.changes.forEach((o, m) => Changeset.sealSubscription(os.data[m], m, h.proxy.constructor.name));
221
+ os.changes.forEach((o, m) => Changeset.sealObservable(os.data[m], m, h.proxy.constructor.name));
222
222
  else
223
223
  for (const m in os.former.snapshot.data)
224
224
  os.data[m] = Meta.Undefined;
225
225
  if (Log.isOn)
226
226
  Changeset.freezeObjectSnapshot(os);
227
227
  }
228
- static sealSubscription(subscription, m, typeName) {
229
- if (subscription instanceof Subscription) {
230
- const value = subscription.content;
228
+ static sealObservable(o, m, typeName) {
229
+ if (o instanceof Observable) {
230
+ const value = o.content;
231
231
  if (value !== undefined && value !== null) {
232
232
  const sealedType = Object.getPrototypeOf(value)[Sealant.SealedType];
233
233
  if (sealedType)
234
- subscription.content = Sealant.seal(value, sealedType, typeName, m);
234
+ o.content = Sealant.seal(value, sealedType, typeName, m);
235
235
  }
236
236
  }
237
237
  }
@@ -5,24 +5,24 @@ export interface AbstractChangeset {
5
5
  readonly timestamp: number;
6
6
  readonly sealed: boolean;
7
7
  }
8
- export declare class Subscription {
8
+ export declare class Observable {
9
9
  content: any;
10
- subscribers?: Set<Subscriber>;
10
+ observers?: Set<Observer>;
11
11
  get isOperation(): boolean;
12
12
  get originSnapshotId(): number | undefined;
13
13
  constructor(content: any);
14
14
  }
15
15
  export declare type SeparationMode = boolean | 'isolated' | 'disposal';
16
- export interface Subscriber {
16
+ export interface Observer {
17
17
  readonly order: number;
18
- readonly subscriptions: Map<Subscription, SubscriptionInfo> | undefined;
18
+ readonly observables: Map<Observable, Subscription> | undefined;
19
19
  readonly obsoleteSince: number;
20
20
  hint(nop?: boolean): string;
21
- markObsoleteDueTo(subscription: Subscription, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, reactive: Array<Subscriber>): void;
21
+ markObsoleteDueTo(observable: Observable, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, reactive: Array<Observer>): void;
22
22
  runIfNotUpToDate(now: boolean, nothrow: boolean): void;
23
23
  }
24
24
  export declare type MemberName = PropertyKey;
25
- export interface SubscriptionInfo {
25
+ export interface Subscription {
26
26
  readonly memberHint: string;
27
27
  readonly usageCount: number;
28
28
  }
@@ -1,7 +1,7 @@
1
1
  import { Log } from '../util/Dbg';
2
2
  import { Meta } from './Meta';
3
3
  export { Meta } from './Meta';
4
- export class Subscription {
4
+ export class Observable {
5
5
  constructor(content) { this.content = content; }
6
6
  get isOperation() { return false; }
7
7
  get originSnapshotId() { return 0; }
@@ -1,5 +1,5 @@
1
1
  import { ObservableObject } from './Mvcc';
2
- import { Meta, Subscription } from './Data';
2
+ import { Meta, Observable } from './Data';
3
3
  import { Changeset, EMPTY_SNAPSHOT } from './Changeset';
4
4
  import { Transaction } from './Transaction';
5
5
  import { Sealant } from '../util/Sealant';
@@ -99,7 +99,7 @@ export class JournalImpl extends Journal {
99
99
  const value = undoing ? vp.formerValue : vp.freshValue;
100
100
  const os = ctx.getEditableObjectSnapshot(h, m, value);
101
101
  if (os.changeset === ctx) {
102
- os.data[m] = new Subscription(value);
102
+ os.data[m] = new Observable(value);
103
103
  const existing = os.former.snapshot.data[m];
104
104
  Changeset.markEdited(existing, value, existing !== value, os, m, h);
105
105
  }
@@ -137,8 +137,8 @@ export class JournalImpl extends Journal {
137
137
  });
138
138
  }
139
139
  }
140
- function unseal(subscription) {
141
- const result = subscription.content;
140
+ function unseal(o) {
141
+ const result = o.content;
142
142
  const createCopy = result === null || result === void 0 ? void 0 : result[Sealant.CreateCopy];
143
143
  return createCopy !== undefined ? createCopy.call(result) : result;
144
144
  }
@@ -44,9 +44,10 @@ export declare class Mvcc implements ProxyHandler<ObjectHandle> {
44
44
  get(h: ObjectHandle, m: MemberName, receiver: any): any;
45
45
  set(h: ObjectHandle, m: MemberName, value: any, receiver: any): boolean;
46
46
  has(h: ObjectHandle, m: MemberName): boolean;
47
+ defineProperty?(h: ObjectHandle, m: string | symbol, attributes: PropertyDescriptor): boolean;
47
48
  getOwnPropertyDescriptor(h: ObjectHandle, m: MemberName): PropertyDescriptor | undefined;
48
49
  ownKeys(h: ObjectHandle): Array<string | symbol>;
49
- static decorateData(isObservable: boolean, proto: any, m: MemberName): any;
50
+ static decorateData(isObservable: boolean, proto: any, member: MemberName): any;
50
51
  static decorateOperation(implicit: boolean, decorator: Function, options: Partial<MemberOptions>, proto: any, member: MemberName, pd: PropertyDescriptor | undefined): any;
51
52
  static decorateOperationParametrized(decorator: Function, options: Partial<MemberOptions>): F<any>;
52
53
  static acquireHandle(obj: any): ObjectHandle;
@@ -1,7 +1,7 @@
1
1
  import { UNDEF } from '../util/Utils';
2
2
  import { Log, misuse } from '../util/Dbg';
3
3
  import { Kind, Reentrance } from '../Options';
4
- import { ObjectSnapshot, ObjectHandle, Subscription, Meta } from './Data';
4
+ import { ObjectSnapshot, ObjectHandle, Observable, Meta } from './Data';
5
5
  import { Changeset, Dump, EMPTY_SNAPSHOT } from './Changeset';
6
6
  export class MvccObject {
7
7
  constructor(observable) {
@@ -72,7 +72,7 @@ export class Mvcc {
72
72
  const cs = Changeset.current();
73
73
  const os = cs.getObjectSnapshot(h, m);
74
74
  result = os.data[m];
75
- if (result instanceof Subscription && !result.isOperation) {
75
+ if (result instanceof Observable && !result.isOperation) {
76
76
  if (this.isObservable)
77
77
  Changeset.markUsed(result, os, m, h, Kind.Plain, false);
78
78
  result = result.content;
@@ -92,7 +92,7 @@ export class Mvcc {
92
92
  if (curr === undefined || curr.content !== value || Mvcc.sensitivity) {
93
93
  const existing = curr === null || curr === void 0 ? void 0 : curr.content;
94
94
  if (os.former.snapshot.data[m] === curr) {
95
- curr = os.data[m] = new Subscription(value);
95
+ curr = os.data[m] = new Observable(value);
96
96
  Changeset.markEdited(existing, value, true, os, m, h);
97
97
  }
98
98
  else {
@@ -112,6 +112,14 @@ export class Mvcc {
112
112
  const os = Changeset.current().getObjectSnapshot(h, m);
113
113
  return m in os.data || m in h.data;
114
114
  }
115
+ defineProperty(h, m, attributes) {
116
+ if (attributes.get && attributes.set) {
117
+ Object.defineProperty(h.data, m, attributes);
118
+ return true;
119
+ }
120
+ else
121
+ throw new Error('not implemented');
122
+ }
115
123
  getOwnPropertyDescriptor(h, m) {
116
124
  const os = Changeset.current().getObjectSnapshot(h, m);
117
125
  const pd = Reflect.getOwnPropertyDescriptor(os.data, m);
@@ -124,27 +132,28 @@ export class Mvcc {
124
132
  const result = [];
125
133
  for (const m of Object.getOwnPropertyNames(os.data)) {
126
134
  const value = os.data[m];
127
- if (!(value instanceof Subscription) || !value.isOperation)
135
+ if (!(value instanceof Observable) || !value.isOperation)
128
136
  result.push(m);
129
137
  }
130
138
  return result;
131
139
  }
132
- static decorateData(isObservable, proto, m) {
140
+ static decorateData(isObservable, proto, member) {
133
141
  if (isObservable) {
142
+ Meta.acquire(proto, Meta.Initial)[member] = new Observable(undefined);
134
143
  const get = function () {
135
144
  const h = Mvcc.acquireHandle(this);
136
- return Mvcc.observable.get(h, m, this);
145
+ return Mvcc.observable.get(h, member, this);
137
146
  };
138
147
  const set = function (value) {
139
148
  const h = Mvcc.acquireHandle(this);
140
- return Mvcc.observable.set(h, m, value, this);
149
+ return Mvcc.observable.set(h, member, value, this);
141
150
  };
142
151
  const enumerable = true;
143
152
  const configurable = false;
144
- return Object.defineProperty(proto, m, { get, set, enumerable, configurable });
153
+ return Object.defineProperty(proto, member, { get, set, enumerable, configurable });
145
154
  }
146
155
  else
147
- Meta.acquire(proto, Meta.Initial)[m] = Meta.Raw;
156
+ Meta.acquire(proto, Meta.Initial)[member] = Meta.Raw;
148
157
  }
149
158
  static decorateOperation(implicit, decorator, options, proto, member, pd) {
150
159
  var _a, _b, _c, _d;
@@ -189,7 +198,7 @@ export class Mvcc {
189
198
  h = new ObjectHandle(obj, obj, Mvcc.observable, os, obj.constructor.name);
190
199
  Meta.set(os.data, Meta.Handle, h);
191
200
  Meta.set(obj, Meta.Handle, h);
192
- Meta.set(os.data, Meta.Revision, new Subscription(1));
201
+ Meta.set(os.data, Meta.Revision, new Observable(1));
193
202
  }
194
203
  return h;
195
204
  }
@@ -1,7 +1,7 @@
1
1
  import { F } from '../util/Utils';
2
2
  import { MemberOptions } from '../Options';
3
3
  import { Controller } from '../Controller';
4
- import { MemberName, ObjectHandle, Subscription, Subscriber, SubscriptionInfo, AbstractChangeset } from './Data';
4
+ import { MemberName, ObjectHandle, Observable, Observer, Subscription, AbstractChangeset } from './Data';
5
5
  import { Transaction } from './Transaction';
6
6
  import { OptionsImpl } from './Mvcc';
7
7
  export declare class OperationController extends Controller<any> {
@@ -32,15 +32,15 @@ export declare class OperationController extends Controller<any> {
32
32
  private run;
33
33
  private static markObsolete;
34
34
  }
35
- declare class Operation extends Subscription implements Subscriber {
35
+ declare class Operation extends Observable implements Observer {
36
36
  static current?: Operation;
37
- static queuedReactiveFunctions: Array<Subscriber>;
37
+ static queuedReactiveFunctions: Array<Observer>;
38
38
  static deferredReactiveFunctions: Array<Operation>;
39
39
  readonly margin: number;
40
40
  readonly transaction: Transaction;
41
41
  readonly controller: OperationController;
42
42
  readonly changeset: AbstractChangeset;
43
- subscriptions: Map<Subscription, SubscriptionInfo> | undefined;
43
+ observables: Map<Observable, Subscription> | undefined;
44
44
  options: OptionsImpl;
45
45
  cause: string | undefined;
46
46
  args: any[];
@@ -61,7 +61,7 @@ declare class Operation extends Subscription implements Subscriber {
61
61
  dependencies(): string[];
62
62
  wrap<T>(func: F<T>): F<T>;
63
63
  run(proxy: any, args: any[] | undefined): void;
64
- markObsoleteDueTo(subscription: Subscription, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, reactive: Subscriber[]): void;
64
+ markObsoleteDueTo(observable: Observable, m: MemberName, changeset: AbstractChangeset, h: ObjectHandle, outer: string, since: number, reactive: Observer[]): void;
65
65
  runIfNotUpToDate(now: boolean, nothrow: boolean): void;
66
66
  isNotUpToDate(): boolean;
67
67
  reenterOver(head: Operation): this;
@@ -81,7 +81,7 @@ declare class Operation extends Subscription implements Subscriber {
81
81
  private static propagateMemberChangeThroughSubscriptions;
82
82
  private static enqueueReactiveFunctionsToRun;
83
83
  private static runQueuedReactiveLoop;
84
- private unsubscribeFromAllSubscriptions;
84
+ private unsubscribeFromAllObservables;
85
85
  private subscribeTo;
86
86
  private static canSubscribe;
87
87
  private static createOperation;
@@ -1,7 +1,7 @@
1
1
  import { Log, misuse } from '../util/Dbg';
2
2
  import { Kind, Reentrance } from '../Options';
3
3
  import { Controller } from '../Controller';
4
- import { ObjectHandle, Subscription, Meta } from './Data';
4
+ import { ObjectHandle, Observable, 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';
@@ -199,14 +199,14 @@ export class OperationController extends Controller {
199
199
  oc.operation.markObsoleteDueTo(oc.operation, self.memberName, EMPTY_SNAPSHOT.changeset, EMPTY_HANDLE, BOOT_CAUSE, ctx.timestamp, ctx.reactive);
200
200
  }
201
201
  }
202
- class Operation extends Subscription {
202
+ class Operation extends Observable {
203
203
  constructor(controller, changeset, former) {
204
204
  super(undefined);
205
205
  this.margin = Operation.current ? Operation.current.margin + 1 : 1;
206
206
  this.transaction = Transaction.current;
207
207
  this.controller = controller;
208
208
  this.changeset = changeset;
209
- this.subscriptions = new Map();
209
+ this.observables = new Map();
210
210
  if (former instanceof Operation) {
211
211
  this.options = former.options;
212
212
  this.args = former.args;
@@ -269,13 +269,13 @@ class Operation extends Subscription {
269
269
  else
270
270
  this.result = Promise.reject(this.error);
271
271
  }
272
- markObsoleteDueTo(subscription, m, changeset, h, outer, since, reactive) {
272
+ markObsoleteDueTo(observable, m, changeset, h, outer, since, reactive) {
273
273
  var _a, _b, _c;
274
- if (this.subscriptions !== undefined) {
275
- const skip = !subscription.isOperation &&
274
+ if (this.observables !== undefined) {
275
+ const skip = !observable.isOperation &&
276
276
  changeset === this.changeset;
277
277
  if (!skip) {
278
- const why = `${Dump.snapshot2(h, changeset, m, subscription)} << ${outer}`;
278
+ const why = `${Dump.snapshot2(h, changeset, m, observable)} << ${outer}`;
279
279
  const isReactive = this.options.kind === Kind.Reactive;
280
280
  this.obsoleteDueTo = why;
281
281
  this.obsoleteSince = since;
@@ -283,15 +283,15 @@ class Operation extends Subscription {
283
283
  Log.write(Log.opt.transaction && !Changeset.current().sealed ? '║' : ' ', isReactive ? '█' : '▒', isReactive && changeset === EMPTY_SNAPSHOT.changeset
284
284
  ? `${this.hint()} is a reactive and will run automatically (order ${this.options.order})`
285
285
  : `${this.hint()} is obsolete due to ${Dump.snapshot2(h, changeset, m)} since v${since}${isReactive ? ` and will run automatically (order ${this.options.order})` : ''}`);
286
- this.unsubscribeFromAllSubscriptions();
286
+ this.unsubscribeFromAllObservables();
287
287
  if (isReactive)
288
288
  reactive.push(this);
289
289
  else
290
- (_b = this.subscribers) === null || _b === void 0 ? void 0 : _b.forEach(s => s.markObsoleteDueTo(this, this.controller.memberName, this.changeset, this.controller.objectHandle, why, since, reactive));
290
+ (_b = this.observers) === null || _b === void 0 ? void 0 : _b.forEach(s => s.markObsoleteDueTo(this, this.controller.memberName, this.changeset, this.controller.objectHandle, why, since, reactive));
291
291
  const tran = this.transaction;
292
292
  if (tran.changeset === changeset) {
293
293
  }
294
- else if (!tran.isFinished && this !== subscription)
294
+ else if (!tran.isFinished && this !== observable)
295
295
  tran.cancel(new Error(`T${tran.id}[${tran.hint}] is canceled due to obsolete ${Dump.snapshot2(h, changeset, m)} changed by T${changeset.id}[${changeset.hint}]`), null);
296
296
  }
297
297
  else if (Log.isOn && (Log.opt.obsolete || ((_c = this.options.logging) === null || _c === void 0 ? void 0 : _c.obsolete)))
@@ -448,7 +448,7 @@ class Operation extends Subscription {
448
448
  for (const x of deferred)
449
449
  x.runIfNotUpToDate(true, true);
450
450
  }
451
- static markUsed(subscription, os, m, h, kind, weak) {
451
+ static markUsed(observable, os, m, h, kind, weak) {
452
452
  if (kind !== Kind.Transactional) {
453
453
  const op = Operation.current;
454
454
  if (op && op.options.kind !== Kind.Transactional &&
@@ -457,8 +457,8 @@ class Operation extends Subscription {
457
457
  if (ctx !== os.changeset)
458
458
  ctx.bumpBy(os.changeset.timestamp);
459
459
  const t = weak ? -1 : ctx.timestamp;
460
- if (!op.subscribeTo(subscription, os, m, h, t))
461
- op.markObsoleteDueTo(subscription, m, os.changeset, h, BOOT_CAUSE, ctx.timestamp, ctx.reactive);
460
+ if (!op.subscribeTo(observable, os, m, h, t))
461
+ op.markObsoleteDueTo(observable, m, os.changeset, h, BOOT_CAUSE, ctx.timestamp, ctx.reactive);
462
462
  }
463
463
  }
464
464
  }
@@ -499,13 +499,13 @@ class Operation extends Subscription {
499
499
  const curr = os.data[m];
500
500
  if (reactive) {
501
501
  const former = os.former.snapshot.data[m];
502
- if (former !== undefined && former instanceof Subscription) {
502
+ if (former !== undefined && former instanceof Observable) {
503
503
  const why = `T${os.changeset.id}[${os.changeset.hint}]`;
504
504
  if (former instanceof Operation) {
505
505
  if ((former.obsoleteSince === MAX_REVISION || former.obsoleteSince <= 0)) {
506
506
  former.obsoleteDueTo = why;
507
507
  former.obsoleteSince = timestamp;
508
- former.unsubscribeFromAllSubscriptions();
508
+ former.unsubscribeFromAllObservables();
509
509
  }
510
510
  const formerSuccessor = former.successor;
511
511
  if (formerSuccessor !== curr) {
@@ -515,22 +515,22 @@ class Operation extends Subscription {
515
515
  else
516
516
  former.successor = undefined;
517
517
  }
518
- (_a = former.subscribers) === null || _a === void 0 ? void 0 : _a.forEach(s => s.markObsoleteDueTo(former, m, os.changeset, h, why, timestamp, reactive));
518
+ (_a = former.observers) === null || _a === void 0 ? void 0 : _a.forEach(s => s.markObsoleteDueTo(former, m, os.changeset, h, why, timestamp, reactive));
519
519
  }
520
520
  }
521
521
  if (curr instanceof Operation) {
522
- if (curr.changeset === os.changeset && curr.subscriptions !== undefined) {
522
+ if (curr.changeset === os.changeset && curr.observables !== undefined) {
523
523
  if (Mvcc.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
524
- curr.subscriptions.forEach((info, v) => {
524
+ curr.observables.forEach((info, v) => {
525
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
  }
529
529
  if (unsubscribe)
530
- curr.unsubscribeFromAllSubscriptions();
530
+ curr.unsubscribeFromAllObservables();
531
531
  }
532
532
  }
533
- else if (curr instanceof Subscription && curr.subscribers) {
533
+ else if (curr instanceof Observable && curr.observers) {
534
534
  }
535
535
  }
536
536
  static enqueueReactiveFunctionsToRun(reactive) {
@@ -551,33 +551,33 @@ class Operation extends Subscription {
551
551
  }
552
552
  Operation.queuedReactiveFunctions = [];
553
553
  }
554
- unsubscribeFromAllSubscriptions() {
554
+ unsubscribeFromAllObservables() {
555
555
  var _a;
556
- (_a = this.subscriptions) === null || _a === void 0 ? void 0 : _a.forEach((info, value) => {
556
+ (_a = this.observables) === null || _a === void 0 ? void 0 : _a.forEach((info, value) => {
557
557
  var _a;
558
- value.subscribers.delete(this);
558
+ value.observers.delete(this);
559
559
  if (Log.isOn && (Log.opt.read || ((_a = this.options.logging) === null || _a === void 0 ? void 0 : _a.read)))
560
560
  Log.write(Log.opt.transaction && !Changeset.current().sealed ? '║' : ' ', '-', `${this.hint()} is unsubscribed from ${info.memberHint}`);
561
561
  });
562
- this.subscriptions = undefined;
562
+ this.observables = undefined;
563
563
  }
564
- subscribeTo(subscription, os, m, h, timestamp) {
564
+ subscribeTo(observable, os, m, h, timestamp) {
565
565
  var _a, _b, _c;
566
- const ok = Operation.canSubscribe(subscription, os, m, h, timestamp);
566
+ const ok = Operation.canSubscribe(observable, os, m, h, timestamp);
567
567
  if (ok) {
568
568
  let times = 0;
569
569
  if (Mvcc.repetitiveUsageWarningThreshold < Number.MAX_SAFE_INTEGER) {
570
- const existing = this.subscriptions.get(subscription);
570
+ const existing = this.observables.get(observable);
571
571
  times = existing ? existing.usageCount + 1 : 1;
572
572
  }
573
- if (this.subscriptions !== undefined) {
574
- if (!subscription.subscribers)
575
- subscription.subscribers = new Set();
576
- const info = { memberHint: Dump.snapshot2(h, os.changeset, m), usageCount: times };
577
- subscription.subscribers.add(this);
578
- this.subscriptions.set(subscription, info);
573
+ if (this.observables !== undefined) {
574
+ if (!observable.observers)
575
+ observable.observers = new Set();
576
+ const subscription = { memberHint: Dump.snapshot2(h, os.changeset, m), usageCount: times };
577
+ observable.observers.add(this);
578
+ this.observables.set(observable, subscription);
579
579
  if (Log.isOn && (Log.opt.read || ((_a = this.options.logging) === null || _a === void 0 ? void 0 : _a.read)))
580
- Log.write('║', ' ∞ ', `${this.hint()} is subscribed to ${Dump.snapshot2(h, os.changeset, m)}${info.usageCount > 1 ? ` (${info.usageCount} times)` : ''}`);
580
+ Log.write('║', ' ∞ ', `${this.hint()} is subscribed to ${Dump.snapshot2(h, os.changeset, m)}${subscription.usageCount > 1 ? ` (${subscription.usageCount} times)` : ''}`);
581
581
  }
582
582
  else if (Log.isOn && (Log.opt.read || ((_b = this.options.logging) === null || _b === void 0 ? void 0 : _b.read)))
583
583
  Log.write('║', ' x ', `${this.hint()} is obsolete and is NOT subscribed to ${Dump.snapshot2(h, os.changeset, m)}`);
@@ -588,10 +588,10 @@ class Operation extends Subscription {
588
588
  }
589
589
  return ok;
590
590
  }
591
- static canSubscribe(subscription, os, m, h, timestamp) {
592
- let result = !os.changeset.sealed || subscription === h.head.data[m];
591
+ static canSubscribe(observable, os, m, h, timestamp) {
592
+ let result = !os.changeset.sealed || observable === h.head.data[m];
593
593
  if (result && timestamp !== -1)
594
- result = !(subscription instanceof Operation && timestamp >= subscription.obsoleteSince);
594
+ result = !(observable instanceof Operation && timestamp >= observable.obsoleteSince);
595
595
  return result;
596
596
  }
597
597
  static createOperation(h, m, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactronic",
3
- "version": "0.22.504",
3
+ "version": "0.22.506",
4
4
  "description": "Reactronic - Transactional Reactive State Management",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",