reactronic 0.22.300 → 0.22.303

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,13 +19,13 @@ isolated data snapshot and then, once atomically applied, are
19
19
  **consistently propagated** to corresponding visual components for
20
20
  (re)rendering. All that is done in automatic, seamless, and fine-grained
21
21
  way, because reactronic **takes full care of tracking dependencies**
22
- between visual components (subscribers) and state (subscribing objects).
22
+ between visual components (subscribers) and state (reactive objects).
23
23
 
24
24
  Transactional reactivity is based on four fundamental concepts:
25
25
 
26
- - **Subscribing Objects** - a set of objects that store data of an
26
+ - **Reactive Objects** - a set of objects that store data of an
27
27
  application (state) and maintain subscription lists;
28
- - **Transaction** - a function that makes changes in subscribing
28
+ - **Transaction** - a function that makes changes in reactive
29
29
  objects in transactional (atomic) way;
30
30
  - **Reaction** - a function that is executed automatically in
31
31
  response to changes made by a transaction;
@@ -40,10 +40,10 @@ Quick introduction and detailed description is below.
40
40
  ## Quick Introduction
41
41
 
42
42
  Here is an example of transactional reactive code with
43
- subscribing object, transaction and reaction:
43
+ reactive object, transaction and reaction:
44
44
 
45
45
  ``` typescript
46
- class Demo extends SubscribingObject {
46
+ class Demo extends ReactiveObject {
47
47
  name: string = 'Nezaboodka Software'
48
48
  email: string = 'contact@nezaboodka.com'
49
49
 
@@ -70,7 +70,7 @@ to changes of these fields made by `saveContact` transaction.
70
70
  Here is an example of if cached value computed on-demand:
71
71
 
72
72
  ``` typescript
73
- class Demo extends SubscribingObject {
73
+ class Demo extends ReactiveObject {
74
74
  name: string = 'Nezaboodka Software'
75
75
  email: string = 'contact@nezaboodka.com'
76
76
 
@@ -95,14 +95,14 @@ invalidated, thus causing execution of depending reaction
95
95
  `printContact`. Then `printContact` reaction causes `contact`
96
96
  re-computation on the first use.
97
97
 
98
- ## Subscribing Objects
98
+ ## Reactive Objects
99
99
 
100
- Subscribing objects store data of an application. All such objects
100
+ Reactive objects store data of an application. All such objects
101
101
  are transparently hooked to track access to their properties,
102
102
  both on reads and writes.
103
103
 
104
104
  ``` typescript
105
- class MyModel extends SubscribingObject {
105
+ class MyModel extends ReactiveObject {
106
106
  url: string = "https://github.com/nezaboodka/reactronic"
107
107
  content: string = "transactional reactive state management"
108
108
  timestamp: Date = Date.now()
@@ -110,18 +110,18 @@ class MyModel extends SubscribingObject {
110
110
  ```
111
111
 
112
112
  In the example above, the class `MyModel` is based on Reactronic's
113
- `SubscribingObject` class and all its properties `url`, `content`,
113
+ `ReactiveObject` class and all its properties `url`, `content`,
114
114
  and `timestamp` are hooked.
115
115
 
116
116
  ## Transaction
117
117
 
118
- Transaction is a function that makes changes in subscribing objects
118
+ Transaction is a function that makes changes in reactive objects
119
119
  in transactional (atomic) way. Such a function is instrumented with hooks
120
120
  to provide transparent atomicity (by implicit context switching
121
121
  and isolation).
122
122
 
123
123
  ``` typescript
124
- class MyModel extends SubscribingObject {
124
+ class MyModel extends ReactiveObject {
125
125
  // ...
126
126
  @transaction
127
127
  async load(url: string): Promise<void> {
@@ -164,12 +164,12 @@ of asynchronous operations is fully completed.
164
164
  ## Reaction & Cache
165
165
 
166
166
  Reaction is an code block that is immediately called in response to
167
- changes made by a transaction in subscribing objects. Cache is a
167
+ changes made by a transaction in reactive objects. Cache is a
168
168
  computed value having an associated function that is called
169
169
  on-demand to renew the value if it was marked as obsolete due to changes
170
170
  made by a transaction. Reactive and cached functions are
171
171
  instrumented with hooks to seamlessly subscribe to those
172
- subscribing objects and other cached functions (dependencies),
172
+ reactive objects and other cached functions (dependencies),
173
173
  which are used during their execution.
174
174
 
175
175
  ``` tsx
@@ -223,15 +223,15 @@ function enqueues re-rendering request to React, which calls
223
223
  `render` function causing it to renew its cached value.
224
224
 
225
225
  In general case, all reactions and caches are automatically and
226
- immediately marked as obsolete when changes are made in those subscribing
226
+ immediately marked as obsolete when changes are made in those reactive
227
227
  objects and cached functions that were used during their execution.
228
228
  And once marked, the functions are automatically executed again,
229
229
  either immediately (for @reactive functions) or on-demand
230
230
  (for @cached functions).
231
231
 
232
232
  Reactronic takes full care of tracking dependencies between
233
- all the subscribing objects and reactions/caches (subscribing objects
234
- and subscribers). With Reactronic, you no longer need to create data change events
233
+ all the reactive objects and reactions/caches.
234
+ With Reactronic, you no longer need to create data change events
235
235
  in one set of objects, subscribe to these events in other objects,
236
236
  and manually maintain switching from the previous object version
237
237
  to a new one.
@@ -292,17 +292,17 @@ NPM: `npm install reactronic`
292
292
 
293
293
  // Classes
294
294
 
295
- class SubscribingObject { }
295
+ class ReactiveObject { }
296
296
 
297
297
  // Decorators & Operators
298
298
 
299
- function subscribeless(proto, prop) // field only
299
+ function isnonreactive(proto, prop) // field only
300
300
  function transaction(proto, prop, pd) // method only
301
301
  function reaction(proto, prop, pd) // method only
302
302
  function cached(proto, prop, pd) // method only
303
303
  function options(value: Partial<MemberOptions>): F<any>
304
304
 
305
- function nonsubscribing<T>(func: F<T>, ...args: any[]): T
305
+ function nonreactive<T>(func: F<T>, ...args: any[]): T
306
306
  function sensitive<T>(sensitivity: Sensitivity, func: F<T>, ...args: any[]): T
307
307
 
308
308
  // SnapshotOptions, MemberOptions, Kind, Reentrance, Monitor, LoggingOptions, ProfilingOptions
@@ -1,5 +1,5 @@
1
- import { SubscribingObject } from './impl/Hooks';
2
- export declare abstract class Buffer<T> extends SubscribingObject {
1
+ import { ReactiveObject } from './impl/Hooks';
2
+ export declare abstract class Buffer<T> extends ReactiveObject {
3
3
  abstract readonly capacity: number;
4
4
  abstract readonly count: number;
5
5
  abstract put(...items: T[]): void;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Buffer = void 0;
4
4
  const Hooks_1 = require("./impl/Hooks");
5
- class Buffer extends Hooks_1.SubscribingObject {
5
+ class Buffer extends Hooks_1.ReactiveObject {
6
6
  static create(hint, capacity) { throw new Error('not implemented'); }
7
7
  }
8
8
  exports.Buffer = Buffer;
@@ -23,12 +23,12 @@ export interface ProfilingOptions {
23
23
  garbageCollectionSummaryInterval: number;
24
24
  }
25
25
  export declare const LoggingLevel: {
26
- Off: LoggingOptions;
27
- ErrorsOnly: LoggingOptions;
28
- Reactions: LoggingOptions;
29
- Transactions: LoggingOptions;
30
- Operations: LoggingOptions;
31
- Debug: LoggingOptions;
26
+ readonly Off: LoggingOptions;
27
+ readonly ErrorsOnly: LoggingOptions;
28
+ readonly Reactions: LoggingOptions;
29
+ readonly Transactions: LoggingOptions;
30
+ readonly Operations: LoggingOptions;
31
+ readonly Debug: LoggingOptions;
32
32
  };
33
33
  declare global {
34
34
  interface Window {
@@ -11,7 +11,7 @@ export declare class Ref<T = any> {
11
11
  constructor(owner: any, name: string, index?: number);
12
12
  get value(): T;
13
13
  set value(value: T);
14
- nonsubscribing(): T;
14
+ nonreactive(): T;
15
15
  observe(): T;
16
16
  unobserve(): T;
17
17
  static to<O extends object = object>(owner: O): {
@@ -21,8 +21,8 @@ class Ref {
21
21
  else
22
22
  this.owner[this.name][this.index] = value;
23
23
  }
24
- nonsubscribing() {
25
- return (0, Rx_1.nonsubscribing)(() => this.value);
24
+ nonreactive() {
25
+ return (0, Rx_1.nonreactive)(() => this.value);
26
26
  }
27
27
  observe() {
28
28
  return this.value;
@@ -2,6 +2,7 @@ import { F } from './util/Utils';
2
2
  import { Controller } from './Controller';
3
3
  import { MemberOptions, LoggingOptions, ProfilingOptions } from './Options';
4
4
  export declare class Rx {
5
+ static getRevisionOf(obj: any): number;
5
6
  static why(brief?: boolean): string;
6
7
  static getController<T>(method: F<T>): Controller<T>;
7
8
  static pullLastResult<T>(method: F<Promise<T>>, args?: any[]): T | undefined;
@@ -17,9 +18,9 @@ export declare class Rx {
17
18
  static getLoggingHint<T extends object>(obj: T, full?: boolean): string | undefined;
18
19
  static setProfilingMode(isOn: boolean, options?: Partial<ProfilingOptions>): void;
19
20
  }
20
- export declare function nonsubscribing<T>(func: F<T>, ...args: any[]): T;
21
+ export declare function nonreactive<T>(func: F<T>, ...args: any[]): T;
21
22
  export declare function sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
22
- export declare function subscribeless(proto: object, prop: PropertyKey): any;
23
+ export declare function isnonreactive(proto: object, prop: PropertyKey): any;
23
24
  export declare function transaction(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
24
25
  export declare function reaction(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
25
26
  export declare function cached(proto: object, prop: PropertyKey, pd: PropertyDescriptor): any;
@@ -1,41 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.options = exports.cached = exports.reaction = exports.transaction = exports.subscribeless = exports.sensitive = exports.nonsubscribing = exports.Rx = void 0;
3
+ exports.options = exports.cached = exports.reaction = exports.transaction = exports.isnonreactive = exports.sensitive = exports.nonreactive = exports.Rx = void 0;
4
4
  const Dbg_1 = require("./util/Dbg");
5
5
  const Options_1 = require("./Options");
6
6
  const Data_1 = require("./impl/Data");
7
- const Snapshot_1 = require("./impl/Snapshot");
7
+ const Changeset_1 = require("./impl/Changeset");
8
8
  const Hooks_1 = require("./impl/Hooks");
9
9
  const Operation_1 = require("./impl/Operation");
10
10
  class Rx {
11
+ static getRevisionOf(obj) { return obj[Data_1.Meta.Revision]; }
11
12
  static why(brief = false) { return brief ? Operation_1.OperationController.briefWhy() : Operation_1.OperationController.why(); }
12
13
  static getController(method) { return Operation_1.OperationController.of(method); }
13
14
  static pullLastResult(method, args) { return Rx.getController(method).pullLastResult(args); }
14
15
  static configureCurrentOperation(options) { return Operation_1.OperationController.configureImpl(undefined, options); }
15
- static takeSnapshot(obj) { return Snapshot_1.Snapshot.takeSnapshot(obj); }
16
- static dispose(obj) { Snapshot_1.Snapshot.dispose(obj); }
16
+ static takeSnapshot(obj) { return Changeset_1.Changeset.takeSnapshot(obj); }
17
+ static dispose(obj) { Changeset_1.Changeset.dispose(obj); }
17
18
  static get reactionsAutoStartDisabled() { return Hooks_1.Hooks.reactionsAutoStartDisabled; }
18
19
  static set reactionsAutoStartDisabled(value) { Hooks_1.Hooks.reactionsAutoStartDisabled = value; }
19
20
  static get isLogging() { return Dbg_1.Log.isOn; }
20
21
  static get loggingOptions() { return Dbg_1.Log.opt; }
21
22
  static setLoggingMode(isOn, options) { Dbg_1.Log.setMode(isOn, options); }
22
23
  static setLoggingHint(obj, name) { Hooks_1.Hooks.setHint(obj, name); }
23
- static getLoggingHint(obj, full = false) { return Data_1.DataHolder.getHint(obj, full); }
24
+ static getLoggingHint(obj, full = false) { return Data_1.ObjectHandle.getHint(obj, full); }
24
25
  static setProfilingMode(isOn, options) { Hooks_1.Hooks.setProfilingMode(isOn, options); }
25
26
  }
26
27
  exports.Rx = Rx;
27
- function nonsubscribing(func, ...args) {
28
+ function nonreactive(func, ...args) {
28
29
  return Operation_1.OperationController.runWithin(undefined, func, ...args);
29
30
  }
30
- exports.nonsubscribing = nonsubscribing;
31
+ exports.nonreactive = nonreactive;
31
32
  function sensitive(sensitivity, func, ...args) {
32
33
  return Hooks_1.Hooks.sensitive(sensitivity, func, ...args);
33
34
  }
34
35
  exports.sensitive = sensitive;
35
- function subscribeless(proto, prop) {
36
+ function isnonreactive(proto, prop) {
36
37
  return Hooks_1.Hooks.decorateData(false, proto, prop);
37
38
  }
38
- exports.subscribeless = subscribeless;
39
+ exports.isnonreactive = isnonreactive;
39
40
  function transaction(proto, prop, pd) {
40
41
  const opts = { kind: Options_1.Kind.Transaction };
41
42
  return Hooks_1.Hooks.decorateOperation(true, transaction, opts, proto, prop, pd);
@@ -6,9 +6,9 @@ export { MemberOptions, SnapshotOptions, Kind, Reentrance, LoggingOptions, Profi
6
6
  export { Worker } from './Worker';
7
7
  export { Controller } from './Controller';
8
8
  export { Ref, ToggleRef, BoolOnly, GivenTypeOnly } from './Ref';
9
- export { SubscribingObject } from './impl/Hooks';
10
- export { Snapshot } from './impl/Snapshot';
9
+ export { ReactiveObject } from './impl/Hooks';
10
+ export { Changeset } from './impl/Changeset';
11
11
  export { Transaction } from './impl/Transaction';
12
12
  export { Monitor } from './impl/Monitor';
13
13
  export { Journal } from './impl/Journal';
14
- export { Rx, nonsubscribing, sensitive, subscribeless, transaction, reaction, cached, options } from './Rx';
14
+ export { Rx, nonreactive, sensitive, isnonreactive, transaction, reaction, cached, options } from './Rx';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.options = exports.cached = exports.reaction = exports.transaction = exports.subscribeless = exports.sensitive = exports.nonsubscribing = exports.Rx = exports.Journal = exports.Monitor = exports.Transaction = exports.Snapshot = exports.SubscribingObject = exports.ToggleRef = exports.Ref = exports.Controller = exports.LoggingLevel = exports.Reentrance = exports.Kind = exports.SealedSet = exports.SealedMap = exports.SealedArray = exports.pause = exports.all = void 0;
3
+ exports.options = exports.cached = exports.reaction = exports.transaction = exports.isnonreactive = exports.sensitive = exports.nonreactive = exports.Rx = exports.Journal = exports.Monitor = exports.Transaction = exports.Changeset = exports.ReactiveObject = exports.ToggleRef = exports.Ref = exports.Controller = exports.LoggingLevel = exports.Reentrance = exports.Kind = exports.SealedSet = exports.SealedMap = exports.SealedArray = exports.pause = exports.all = void 0;
4
4
  var Utils_1 = require("./util/Utils");
5
5
  Object.defineProperty(exports, "all", { enumerable: true, get: function () { return Utils_1.all; } });
6
6
  Object.defineProperty(exports, "pause", { enumerable: true, get: function () { return Utils_1.pause; } });
@@ -20,9 +20,9 @@ var Ref_1 = require("./Ref");
20
20
  Object.defineProperty(exports, "Ref", { enumerable: true, get: function () { return Ref_1.Ref; } });
21
21
  Object.defineProperty(exports, "ToggleRef", { enumerable: true, get: function () { return Ref_1.ToggleRef; } });
22
22
  var Hooks_1 = require("./impl/Hooks");
23
- Object.defineProperty(exports, "SubscribingObject", { enumerable: true, get: function () { return Hooks_1.SubscribingObject; } });
24
- var Snapshot_1 = require("./impl/Snapshot");
25
- Object.defineProperty(exports, "Snapshot", { enumerable: true, get: function () { return Snapshot_1.Snapshot; } });
23
+ Object.defineProperty(exports, "ReactiveObject", { enumerable: true, get: function () { return Hooks_1.ReactiveObject; } });
24
+ var Changeset_1 = require("./impl/Changeset");
25
+ Object.defineProperty(exports, "Changeset", { enumerable: true, get: function () { return Changeset_1.Changeset; } });
26
26
  var Transaction_1 = require("./impl/Transaction");
27
27
  Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return Transaction_1.Transaction; } });
28
28
  var Monitor_1 = require("./impl/Monitor");
@@ -31,9 +31,9 @@ var Journal_1 = require("./impl/Journal");
31
31
  Object.defineProperty(exports, "Journal", { enumerable: true, get: function () { return Journal_1.Journal; } });
32
32
  var Rx_1 = require("./Rx");
33
33
  Object.defineProperty(exports, "Rx", { enumerable: true, get: function () { return Rx_1.Rx; } });
34
- Object.defineProperty(exports, "nonsubscribing", { enumerable: true, get: function () { return Rx_1.nonsubscribing; } });
34
+ Object.defineProperty(exports, "nonreactive", { enumerable: true, get: function () { return Rx_1.nonreactive; } });
35
35
  Object.defineProperty(exports, "sensitive", { enumerable: true, get: function () { return Rx_1.sensitive; } });
36
- Object.defineProperty(exports, "subscribeless", { enumerable: true, get: function () { return Rx_1.subscribeless; } });
36
+ Object.defineProperty(exports, "isnonreactive", { enumerable: true, get: function () { return Rx_1.isnonreactive; } });
37
37
  Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return Rx_1.transaction; } });
38
38
  Object.defineProperty(exports, "reaction", { enumerable: true, get: function () { return Rx_1.reaction; } });
39
39
  Object.defineProperty(exports, "cached", { enumerable: true, get: function () { return Rx_1.cached; } });
@@ -0,0 +1,60 @@
1
+ import { Kind, SnapshotOptions } from '../Options';
2
+ import { AbstractChangeset, ObjectSnapshot, MemberName, ObjectHandle, Subscription, Subscriber } from './Data';
3
+ export declare const MAX_REVISION: number;
4
+ export declare const UNDEFINED_REVISION: number;
5
+ export declare class Changeset implements AbstractChangeset {
6
+ static idGen: number;
7
+ private static stampGen;
8
+ private static pending;
9
+ private static oldest;
10
+ static garbageCollectionSummaryInterval: number;
11
+ static lastGarbageCollectionSummaryTimestamp: number;
12
+ static totalObjectHandleCount: number;
13
+ static totalObjectSnapshotCount: number;
14
+ readonly id: number;
15
+ readonly options: SnapshotOptions;
16
+ get hint(): string;
17
+ get timestamp(): number;
18
+ private revision;
19
+ private bumper;
20
+ items: Map<ObjectHandle, ObjectSnapshot>;
21
+ reactions: Subscriber[];
22
+ sealed: boolean;
23
+ constructor(options: SnapshotOptions | null);
24
+ static current: () => Changeset;
25
+ static edit: () => Changeset;
26
+ static markUsed: (subscription: Subscription, os: ObjectSnapshot, m: MemberName, h: ObjectHandle, kind: Kind, weak: boolean) => void;
27
+ static markEdited: (oldValue: any, newValue: any, edited: boolean, os: ObjectSnapshot, m: MemberName, h: ObjectHandle) => void;
28
+ static isConflicting: (oldValue: any, newValue: any) => boolean;
29
+ static propagateAllChangesThroughSubscriptions: (changeset: Changeset) => void;
30
+ static revokeAllSubscriptions: (changeset: Changeset) => void;
31
+ static enqueueReactionsToRun: (reactions: Array<Subscriber>) => void;
32
+ seekSnapshot(h: ObjectHandle, m: MemberName): ObjectSnapshot;
33
+ getRelevantSnapshot(h: ObjectHandle, m: MemberName): ObjectSnapshot;
34
+ getEditableSnapshot(h: ObjectHandle, m: MemberName, value: any, token?: any): ObjectSnapshot;
35
+ static takeSnapshot<T>(obj: T): T;
36
+ static dispose(obj: any): void;
37
+ static doDispose(ctx: Changeset, h: ObjectHandle): ObjectSnapshot;
38
+ private isNewSnapshotRequired;
39
+ acquire(outer: Changeset): void;
40
+ bumpBy(timestamp: number): void;
41
+ rebase(): ObjectSnapshot[] | undefined;
42
+ private merge;
43
+ applyOrDiscard(error?: any): Array<Subscriber>;
44
+ static sealObjectSnapshot(h: ObjectHandle, os: ObjectSnapshot): void;
45
+ static sealSubscription(subscription: Subscription | symbol, m: MemberName, typeName: string): void;
46
+ static freezeObjectSnapshot(os: ObjectSnapshot): ObjectSnapshot;
47
+ triggerGarbageCollection(): void;
48
+ private unlinkHistory;
49
+ static _init(): void;
50
+ }
51
+ export declare class Dump {
52
+ static valueHint: (value: any, m?: PropertyKey | undefined) => string;
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;
55
+ static snapshot(os: ObjectSnapshot, m?: MemberName): string;
56
+ static conflicts(conflicts: ObjectSnapshot[]): string;
57
+ static conflictingMemberHint(m: MemberName, ours: ObjectSnapshot, theirs: ObjectSnapshot): string;
58
+ }
59
+ export declare const EMPTY_SNAPSHOT: ObjectSnapshot;
60
+ export declare const DefaultSnapshotOptions: SnapshotOptions;