reactronic 0.22.316 → 0.22.318
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 +17 -17
- package/build/dist/source/Buffer.d.ts +2 -2
- package/build/dist/source/Buffer.js +2 -2
- package/build/dist/source/Ref.d.ts +2 -2
- package/build/dist/source/Ref.js +4 -4
- package/build/dist/source/api.d.ts +3 -3
- package/build/dist/source/api.js +3 -3
- package/build/dist/source/impl/Changeset.js +3 -3
- package/build/dist/source/impl/Journal.d.ts +2 -2
- package/build/dist/source/impl/Journal.js +2 -2
- package/build/dist/source/impl/Meta.d.ts +1 -1
- package/build/dist/source/impl/Meta.js +1 -1
- package/build/dist/source/impl/Monitor.d.ts +2 -2
- package/build/dist/source/impl/Monitor.js +2 -2
- package/build/dist/source/impl/Mvcc.d.ts +7 -7
- package/build/dist/source/impl/Mvcc.js +16 -16
- package/build/dist/source/impl/MvccArray.d.ts +2 -2
- package/build/dist/source/impl/MvccArray.js +3 -3
- package/build/dist/source/impl/MvccCollection.d.ts +2 -2
- package/build/dist/source/impl/MvccCollection.js +2 -2
- package/build/dist/source/impl/MvccMap.d.ts +2 -2
- package/build/dist/source/impl/MvccMap.js +3 -3
- package/build/dist/source/impl/Operation.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,13 +18,13 @@ isolated data snapshot and then, once atomically applied, are
|
|
|
18
18
|
**consistently propagated** to corresponding visual components for
|
|
19
19
|
(re)rendering. All that is done in automatic, seamless, and fine-grained
|
|
20
20
|
way, because reactronic **takes full care of tracking dependencies**
|
|
21
|
-
between visual components (
|
|
21
|
+
between visual components (observers) and state (observable objects).
|
|
22
22
|
|
|
23
23
|
Transactional reactivity is based on four fundamental concepts:
|
|
24
24
|
|
|
25
|
-
- **
|
|
25
|
+
- **Observable Objects** - a set of objects that store data of an
|
|
26
26
|
application (state) and maintain subscription lists;
|
|
27
|
-
- **Transaction** - a function that makes changes in
|
|
27
|
+
- **Transaction** - a function that makes changes in observable
|
|
28
28
|
objects in transactional (atomic) way;
|
|
29
29
|
- **Reaction** - a function that is executed automatically in
|
|
30
30
|
response to changes made by a transaction;
|
|
@@ -39,10 +39,10 @@ Quick introduction and detailed description is below.
|
|
|
39
39
|
## Quick Introduction
|
|
40
40
|
|
|
41
41
|
Here is an example of transactional reactive code with
|
|
42
|
-
|
|
42
|
+
observable object, transaction and reaction:
|
|
43
43
|
|
|
44
44
|
``` typescript
|
|
45
|
-
class Demo extends
|
|
45
|
+
class Demo extends ObservableObject {
|
|
46
46
|
name: string = 'Nezaboodka Software'
|
|
47
47
|
email: string = 'contact@nezaboodka.com'
|
|
48
48
|
|
|
@@ -69,7 +69,7 @@ to changes of these fields made by `saveContact` transaction.
|
|
|
69
69
|
Here is an example of if cached value computed on-demand:
|
|
70
70
|
|
|
71
71
|
``` typescript
|
|
72
|
-
class Demo extends
|
|
72
|
+
class Demo extends ObservableObject {
|
|
73
73
|
name: string = 'Nezaboodka Software'
|
|
74
74
|
email: string = 'contact@nezaboodka.com'
|
|
75
75
|
|
|
@@ -94,14 +94,14 @@ invalidated, thus causing execution of depending reaction
|
|
|
94
94
|
`printContact`. Then `printContact` reaction causes `contact`
|
|
95
95
|
re-computation on the first use.
|
|
96
96
|
|
|
97
|
-
##
|
|
97
|
+
## Observable Objects
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
Observable objects store data of an application. All such objects
|
|
100
100
|
are transparently hooked to track access to their properties,
|
|
101
101
|
both on reads and writes.
|
|
102
102
|
|
|
103
103
|
``` typescript
|
|
104
|
-
class MyModel extends
|
|
104
|
+
class MyModel extends ObservableObject {
|
|
105
105
|
url: string = "https://github.com/nezaboodka/reactronic"
|
|
106
106
|
content: string = "transactional reactive state management"
|
|
107
107
|
timestamp: Date = Date.now()
|
|
@@ -109,18 +109,18 @@ class MyModel extends ReactiveObject {
|
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
In the example above, the class `MyModel` is based on Reactronic's
|
|
112
|
-
`
|
|
112
|
+
`ObservableObject` class and all its properties `url`, `content`,
|
|
113
113
|
and `timestamp` are hooked.
|
|
114
114
|
|
|
115
115
|
## Transaction
|
|
116
116
|
|
|
117
|
-
Transaction is a function that makes changes in
|
|
117
|
+
Transaction is a function that makes changes in observable objects
|
|
118
118
|
in transactional (atomic) way. Such a function is instrumented with hooks
|
|
119
119
|
to provide transparent atomicity (by implicit context switching
|
|
120
120
|
and isolation).
|
|
121
121
|
|
|
122
122
|
``` typescript
|
|
123
|
-
class MyModel extends
|
|
123
|
+
class MyModel extends ObservableObject {
|
|
124
124
|
// ...
|
|
125
125
|
@transaction
|
|
126
126
|
async load(url: string): Promise<void> {
|
|
@@ -163,12 +163,12 @@ of asynchronous operations is fully completed.
|
|
|
163
163
|
## Reaction & Cache
|
|
164
164
|
|
|
165
165
|
Reaction is an code block that is immediately called in response to
|
|
166
|
-
changes made by a transaction in
|
|
166
|
+
changes made by a transaction in observable objects. Cache is a
|
|
167
167
|
computed value having an associated function that is called
|
|
168
168
|
on-demand to renew the value if it was marked as obsolete due to changes
|
|
169
169
|
made by a transaction. Reactive and cached functions are
|
|
170
170
|
instrumented with hooks to seamlessly subscribe to those
|
|
171
|
-
|
|
171
|
+
observable objects and other cached functions (dependencies),
|
|
172
172
|
which are used during their execution.
|
|
173
173
|
|
|
174
174
|
``` tsx
|
|
@@ -222,14 +222,14 @@ function enqueues re-rendering request to React, which calls
|
|
|
222
222
|
`render` function causing it to renew its cached value.
|
|
223
223
|
|
|
224
224
|
In general case, all reactions and caches are automatically and
|
|
225
|
-
immediately marked as obsolete when changes are made in those
|
|
225
|
+
immediately marked as obsolete when changes are made in those observable
|
|
226
226
|
objects and cached functions that were used during their execution.
|
|
227
227
|
And once marked, the functions are automatically executed again,
|
|
228
228
|
either immediately (for @reactive functions) or on-demand
|
|
229
229
|
(for @cached functions).
|
|
230
230
|
|
|
231
231
|
Reactronic takes full care of tracking dependencies between
|
|
232
|
-
all the
|
|
232
|
+
all the observable objects and reactions/caches.
|
|
233
233
|
With Reactronic, you no longer need to create data change events
|
|
234
234
|
in one set of objects, subscribe to these events in other objects,
|
|
235
235
|
and manually maintain switching from the previous object version
|
|
@@ -292,7 +292,7 @@ NPM: `npm install reactronic`
|
|
|
292
292
|
// Classes
|
|
293
293
|
|
|
294
294
|
class TransactionalObject { }
|
|
295
|
-
class
|
|
295
|
+
class ObservableObject { }
|
|
296
296
|
|
|
297
297
|
// Decorators & Operators
|
|
298
298
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare abstract class Buffer<T> extends
|
|
1
|
+
import { ObservableObject } from './impl/Mvcc';
|
|
2
|
+
export declare abstract class Buffer<T> extends ObservableObject {
|
|
3
3
|
abstract readonly capacity: number;
|
|
4
4
|
abstract readonly count: number;
|
|
5
5
|
abstract put(...items: T[]): void;
|
|
@@ -9,8 +9,8 @@ export declare class Ref<T = any> {
|
|
|
9
9
|
readonly name: string;
|
|
10
10
|
readonly index: number;
|
|
11
11
|
constructor(owner: any, name: string, index?: number);
|
|
12
|
-
get
|
|
13
|
-
set
|
|
12
|
+
get variable(): T;
|
|
13
|
+
set variable(value: T);
|
|
14
14
|
nonreactive(): T;
|
|
15
15
|
observe(): T;
|
|
16
16
|
unobserve(): T;
|
package/build/dist/source/Ref.js
CHANGED
|
@@ -6,23 +6,23 @@ export class Ref {
|
|
|
6
6
|
this.name = name;
|
|
7
7
|
this.index = index;
|
|
8
8
|
}
|
|
9
|
-
get
|
|
9
|
+
get variable() {
|
|
10
10
|
if (this.index < 0)
|
|
11
11
|
return this.owner[this.name];
|
|
12
12
|
else
|
|
13
13
|
return this.owner[this.name][this.index];
|
|
14
14
|
}
|
|
15
|
-
set
|
|
15
|
+
set variable(value) {
|
|
16
16
|
if (this.index < 0)
|
|
17
17
|
this.owner[this.name] = value;
|
|
18
18
|
else
|
|
19
19
|
this.owner[this.name][this.index] = value;
|
|
20
20
|
}
|
|
21
21
|
nonreactive() {
|
|
22
|
-
return nonreactive(() => this.
|
|
22
|
+
return nonreactive(() => this.variable);
|
|
23
23
|
}
|
|
24
24
|
observe() {
|
|
25
|
-
return this.
|
|
25
|
+
return this.variable;
|
|
26
26
|
}
|
|
27
27
|
unobserve() {
|
|
28
28
|
throw new Error('not implemented');
|
|
@@ -7,9 +7,9 @@ export { MemberOptions, SnapshotOptions, Kind, Reentrance, LoggingOptions, Profi
|
|
|
7
7
|
export { Worker } from './Worker';
|
|
8
8
|
export { Controller } from './Controller';
|
|
9
9
|
export { Ref, ToggleRef, BoolOnly, GivenTypeOnly } from './Ref';
|
|
10
|
-
export { TransactionalObject,
|
|
11
|
-
export { TransactionalArray,
|
|
12
|
-
export { TransactionalMap,
|
|
10
|
+
export { TransactionalObject, ObservableObject } from './impl/Mvcc';
|
|
11
|
+
export { TransactionalArray, ObservableArray } from './impl/MvccArray';
|
|
12
|
+
export { TransactionalMap, ObservableMap } from './impl/MvccMap';
|
|
13
13
|
export { Changeset } from './impl/Changeset';
|
|
14
14
|
export { Transaction } from './impl/Transaction';
|
|
15
15
|
export { Monitor } from './impl/Monitor';
|
package/build/dist/source/api.js
CHANGED
|
@@ -6,9 +6,9 @@ export { SealedSet } from './util/SealedSet';
|
|
|
6
6
|
export { Kind, Reentrance, LoggingLevel } from './Options';
|
|
7
7
|
export { Controller } from './Controller';
|
|
8
8
|
export { Ref, ToggleRef } from './Ref';
|
|
9
|
-
export { TransactionalObject,
|
|
10
|
-
export { TransactionalArray,
|
|
11
|
-
export { TransactionalMap,
|
|
9
|
+
export { TransactionalObject, ObservableObject } from './impl/Mvcc';
|
|
10
|
+
export { TransactionalArray, ObservableArray } from './impl/MvccArray';
|
|
11
|
+
export { TransactionalMap, ObservableMap } from './impl/MvccMap';
|
|
12
12
|
export { Changeset } from './impl/Changeset';
|
|
13
13
|
export { Transaction } from './impl/Transaction';
|
|
14
14
|
export { Monitor } from './impl/Monitor';
|
|
@@ -16,7 +16,7 @@ Object.defineProperty(ObjectHandle.prototype, '#this#', {
|
|
|
16
16
|
const v = data[m];
|
|
17
17
|
if (v instanceof Subscription)
|
|
18
18
|
result[m] = v.content;
|
|
19
|
-
else if (v === Meta.
|
|
19
|
+
else if (v === Meta.Raw)
|
|
20
20
|
result[m] = this.data[m];
|
|
21
21
|
else
|
|
22
22
|
result[m] = v;
|
|
@@ -61,7 +61,7 @@ export class Changeset {
|
|
|
61
61
|
getEditableObjectSnapshot(h, m, value, token) {
|
|
62
62
|
let os = this.lookupObjectSnapshot(h, m);
|
|
63
63
|
const existing = os.data[m];
|
|
64
|
-
if (existing !== Meta.
|
|
64
|
+
if (existing !== Meta.Raw) {
|
|
65
65
|
if (this.isNewSnapshotRequired(h, os, m, existing, value, token)) {
|
|
66
66
|
this.bumpBy(os.changeset.timestamp);
|
|
67
67
|
const revision = m === Meta.Handle ? 1 : os.revision + 1;
|
|
@@ -97,7 +97,7 @@ export class Changeset {
|
|
|
97
97
|
}
|
|
98
98
|
isNewSnapshotRequired(h, os, m, existing, value, token) {
|
|
99
99
|
if (this.sealed && os.changeset !== EMPTY_SNAPSHOT.changeset)
|
|
100
|
-
throw misuse(`
|
|
100
|
+
throw misuse(`observable property ${Dump.obj(h, m)} can only be modified inside transaction`);
|
|
101
101
|
if (m !== Meta.Handle) {
|
|
102
102
|
if (value !== Meta.Handle) {
|
|
103
103
|
if (os.changeset !== this || os.former.snapshot !== EMPTY_SNAPSHOT) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObservableObject } from './Mvcc';
|
|
2
2
|
import { ObjectHandle, ObjectSnapshot, PatchSet } from './Data';
|
|
3
3
|
export declare type Saver = (patch: PatchSet) => Promise<void>;
|
|
4
|
-
export declare abstract class Journal extends
|
|
4
|
+
export declare abstract class Journal extends ObservableObject {
|
|
5
5
|
abstract capacity: number;
|
|
6
6
|
abstract readonly edits: ReadonlyArray<PatchSet>;
|
|
7
7
|
abstract readonly unsaved: PatchSet;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObservableObject } from './Mvcc';
|
|
2
2
|
import { Meta, Subscription } from './Data';
|
|
3
3
|
import { Changeset, EMPTY_SNAPSHOT } from './Changeset';
|
|
4
4
|
import { Transaction } from './Transaction';
|
|
5
5
|
import { Sealant } from '../util/Sealant';
|
|
6
|
-
export class Journal extends
|
|
6
|
+
export class Journal extends ObservableObject {
|
|
7
7
|
static create() { return new JournalImpl(); }
|
|
8
8
|
}
|
|
9
9
|
export class JournalImpl extends Journal {
|
|
@@ -4,7 +4,7 @@ export declare abstract class Meta {
|
|
|
4
4
|
static readonly Controller: unique symbol;
|
|
5
5
|
static readonly Initial: unique symbol;
|
|
6
6
|
static readonly Reactions: unique symbol;
|
|
7
|
-
static readonly
|
|
7
|
+
static readonly Raw: unique symbol;
|
|
8
8
|
static readonly Undefined: unique symbol;
|
|
9
9
|
static get<T>(obj: any, sym: symbol): T;
|
|
10
10
|
static set(obj: any, sym: symbol, value: any): any;
|
|
@@ -25,5 +25,5 @@ Meta.Revision = Symbol('rx-revision');
|
|
|
25
25
|
Meta.Controller = Symbol('rx-controller');
|
|
26
26
|
Meta.Initial = Symbol('rx-initial');
|
|
27
27
|
Meta.Reactions = Symbol('rx-reactions');
|
|
28
|
-
Meta.
|
|
28
|
+
Meta.Raw = Symbol('rx-raw');
|
|
29
29
|
Meta.Undefined = Symbol('rx-undefined');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Worker } from '../Worker';
|
|
2
|
-
import {
|
|
3
|
-
export declare abstract class Monitor extends
|
|
2
|
+
import { ObservableObject } from './Mvcc';
|
|
3
|
+
export declare abstract class Monitor extends ObservableObject {
|
|
4
4
|
abstract readonly isActive: boolean;
|
|
5
5
|
abstract readonly counter: number;
|
|
6
6
|
abstract readonly workers: ReadonlySet<Worker>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObservableObject, Mvcc } from './Mvcc';
|
|
2
2
|
import { Transaction } from './Transaction';
|
|
3
|
-
export class Monitor extends
|
|
3
|
+
export class Monitor extends ObservableObject {
|
|
4
4
|
static create(hint, activationDelay, deactivationDelay, durationResolution) {
|
|
5
5
|
return MonitorImpl.create(hint, activationDelay, deactivationDelay, durationResolution);
|
|
6
6
|
}
|
|
@@ -5,13 +5,13 @@ import { MemberName, ObjectHandle, SeparationMode } from './Data';
|
|
|
5
5
|
import { Journal } from './Journal';
|
|
6
6
|
import { Monitor } from './Monitor';
|
|
7
7
|
export declare abstract class MvccObject {
|
|
8
|
-
protected constructor(
|
|
8
|
+
protected constructor(observable: boolean);
|
|
9
9
|
[Symbol.toStringTag](): string;
|
|
10
10
|
}
|
|
11
11
|
export declare abstract class TransactionalObject extends MvccObject {
|
|
12
12
|
constructor();
|
|
13
13
|
}
|
|
14
|
-
export declare abstract class
|
|
14
|
+
export declare abstract class ObservableObject extends MvccObject {
|
|
15
15
|
constructor();
|
|
16
16
|
}
|
|
17
17
|
export declare class OptionsImpl implements MemberOptions {
|
|
@@ -37,20 +37,20 @@ export declare class Mvcc implements ProxyHandler<ObjectHandle> {
|
|
|
37
37
|
static asyncActionDurationWarningThreshold: number;
|
|
38
38
|
static sensitivity: boolean;
|
|
39
39
|
static readonly transactional: Mvcc;
|
|
40
|
-
static readonly
|
|
41
|
-
readonly
|
|
42
|
-
constructor(
|
|
40
|
+
static readonly observable: Mvcc;
|
|
41
|
+
readonly isObservable: boolean;
|
|
42
|
+
constructor(isObservable: boolean);
|
|
43
43
|
getPrototypeOf(h: ObjectHandle): object | null;
|
|
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
47
|
getOwnPropertyDescriptor(h: ObjectHandle, m: MemberName): PropertyDescriptor | undefined;
|
|
48
48
|
ownKeys(h: ObjectHandle): Array<string | symbol>;
|
|
49
|
-
static decorateData(
|
|
49
|
+
static decorateData(isObservable: boolean, proto: any, m: MemberName): any;
|
|
50
50
|
static decorateOperation(implicit: boolean, decorator: Function, options: Partial<MemberOptions>, proto: any, member: MemberName, pd: PropertyDescriptor | undefined): any;
|
|
51
51
|
static decorateOperationParametrized(decorator: Function, options: Partial<MemberOptions>): F<any>;
|
|
52
52
|
static acquireHandle(obj: any): ObjectHandle;
|
|
53
|
-
static createHandleForMvccObject(proto: any, data: any, blank: any, hint: string,
|
|
53
|
+
static createHandleForMvccObject(proto: any, data: any, blank: any, hint: string, isObservable: boolean): ObjectHandle;
|
|
54
54
|
static setProfilingMode(isOn: boolean, options?: Partial<ProfilingOptions>): void;
|
|
55
55
|
static sensitive<T>(sensitivity: boolean, func: F<T>, ...args: any[]): T;
|
|
56
56
|
static setHint<T>(obj: T, hint: string | undefined): T;
|
|
@@ -4,10 +4,10 @@ import { Kind, Reentrance } from '../Options';
|
|
|
4
4
|
import { ObjectSnapshot, ObjectHandle, Subscription, Meta } from './Data';
|
|
5
5
|
import { Changeset, Dump, EMPTY_SNAPSHOT } from './Changeset';
|
|
6
6
|
export class MvccObject {
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(observable) {
|
|
8
8
|
const proto = new.target.prototype;
|
|
9
9
|
const initial = Meta.getFrom(proto, Meta.Initial);
|
|
10
|
-
const h = Mvcc.createHandleForMvccObject(proto, this, initial, new.target.name,
|
|
10
|
+
const h = Mvcc.createHandleForMvccObject(proto, this, initial, new.target.name, observable);
|
|
11
11
|
return h.proxy;
|
|
12
12
|
}
|
|
13
13
|
[Symbol.toStringTag]() {
|
|
@@ -20,7 +20,7 @@ export class TransactionalObject extends MvccObject {
|
|
|
20
20
|
super(false);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
export class
|
|
23
|
+
export class ObservableObject extends MvccObject {
|
|
24
24
|
constructor() {
|
|
25
25
|
super(true);
|
|
26
26
|
}
|
|
@@ -60,8 +60,8 @@ function merge(def, existing, patch, implicit) {
|
|
|
60
60
|
return patch !== undefined && (existing === def || !implicit) ? patch : existing;
|
|
61
61
|
}
|
|
62
62
|
export class Mvcc {
|
|
63
|
-
constructor(
|
|
64
|
-
this.
|
|
63
|
+
constructor(isObservable) {
|
|
64
|
+
this.isObservable = isObservable;
|
|
65
65
|
}
|
|
66
66
|
getPrototypeOf(h) {
|
|
67
67
|
return Reflect.getPrototypeOf(h.data);
|
|
@@ -73,7 +73,7 @@ export class Mvcc {
|
|
|
73
73
|
const os = cs.getObjectSnapshot(h, m);
|
|
74
74
|
result = os.data[m];
|
|
75
75
|
if (result instanceof Subscription && !result.isOperation) {
|
|
76
|
-
if (this.
|
|
76
|
+
if (this.isObservable)
|
|
77
77
|
Changeset.markUsed(result, os, m, h, Kind.Plain, false);
|
|
78
78
|
result = result.content;
|
|
79
79
|
}
|
|
@@ -129,22 +129,22 @@ export class Mvcc {
|
|
|
129
129
|
}
|
|
130
130
|
return result;
|
|
131
131
|
}
|
|
132
|
-
static decorateData(
|
|
133
|
-
if (
|
|
132
|
+
static decorateData(isObservable, proto, m) {
|
|
133
|
+
if (isObservable) {
|
|
134
134
|
const get = function () {
|
|
135
135
|
const h = Mvcc.acquireHandle(this);
|
|
136
|
-
return Mvcc.
|
|
136
|
+
return Mvcc.observable.get(h, m, this);
|
|
137
137
|
};
|
|
138
138
|
const set = function (value) {
|
|
139
139
|
const h = Mvcc.acquireHandle(this);
|
|
140
|
-
return Mvcc.
|
|
140
|
+
return Mvcc.observable.set(h, m, value, this);
|
|
141
141
|
};
|
|
142
142
|
const enumerable = true;
|
|
143
143
|
const configurable = false;
|
|
144
144
|
return Object.defineProperty(proto, m, { get, set, enumerable, configurable });
|
|
145
145
|
}
|
|
146
146
|
else
|
|
147
|
-
Meta.acquire(proto, Meta.Initial)[m] = Meta.
|
|
147
|
+
Meta.acquire(proto, Meta.Initial)[m] = Meta.Raw;
|
|
148
148
|
}
|
|
149
149
|
static decorateOperation(implicit, decorator, options, proto, member, pd) {
|
|
150
150
|
var _a, _b, _c, _d;
|
|
@@ -183,19 +183,19 @@ export class Mvcc {
|
|
|
183
183
|
let h = obj[Meta.Handle];
|
|
184
184
|
if (!h) {
|
|
185
185
|
if (obj !== Object(obj) || Array.isArray(obj))
|
|
186
|
-
throw misuse('only objects can be
|
|
186
|
+
throw misuse('only objects can be observable');
|
|
187
187
|
const initial = Meta.getFrom(Object.getPrototypeOf(obj), Meta.Initial);
|
|
188
188
|
const os = new ObjectSnapshot(EMPTY_SNAPSHOT.changeset, EMPTY_SNAPSHOT, Object.assign({}, initial));
|
|
189
|
-
h = new ObjectHandle(obj, obj, Mvcc.
|
|
189
|
+
h = new ObjectHandle(obj, obj, Mvcc.observable, os, obj.constructor.name);
|
|
190
190
|
Meta.set(os.data, Meta.Handle, h);
|
|
191
191
|
Meta.set(obj, Meta.Handle, h);
|
|
192
192
|
Meta.set(os.data, Meta.Revision, new Subscription(1));
|
|
193
193
|
}
|
|
194
194
|
return h;
|
|
195
195
|
}
|
|
196
|
-
static createHandleForMvccObject(proto, data, blank, hint,
|
|
196
|
+
static createHandleForMvccObject(proto, data, blank, hint, isObservable) {
|
|
197
197
|
const ctx = Changeset.edit();
|
|
198
|
-
const mvcc =
|
|
198
|
+
const mvcc = isObservable ? Mvcc.observable : Mvcc.transactional;
|
|
199
199
|
const h = new ObjectHandle(data, undefined, mvcc, EMPTY_SNAPSHOT, hint);
|
|
200
200
|
ctx.getEditableObjectSnapshot(h, Meta.Handle, blank);
|
|
201
201
|
if (!Mvcc.reactionsAutoStartDisabled)
|
|
@@ -245,7 +245,7 @@ Mvcc.mainThreadBlockingWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
|
245
245
|
Mvcc.asyncActionDurationWarningThreshold = Number.MAX_SAFE_INTEGER;
|
|
246
246
|
Mvcc.sensitivity = false;
|
|
247
247
|
Mvcc.transactional = new Mvcc(false);
|
|
248
|
-
Mvcc.
|
|
248
|
+
Mvcc.observable = new Mvcc(true);
|
|
249
249
|
Mvcc.createOperation = function (h, m, options) {
|
|
250
250
|
throw misuse('this implementation of createOperation should never be called');
|
|
251
251
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MvccObject } from './Mvcc';
|
|
2
2
|
export declare class MvccArray<T> extends MvccObject {
|
|
3
3
|
private all;
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(isObservable: boolean, array: Array<T>);
|
|
5
5
|
get length(): number;
|
|
6
6
|
set length(n: number);
|
|
7
7
|
getItem(n: number): T;
|
|
@@ -52,7 +52,7 @@ export declare class TransactionalArray<T> extends MvccArray<T> {
|
|
|
52
52
|
constructor(arrayLength?: number);
|
|
53
53
|
constructor(...items: T[]);
|
|
54
54
|
}
|
|
55
|
-
export declare class
|
|
55
|
+
export declare class ObservableArray<T> extends MvccArray<T> {
|
|
56
56
|
constructor();
|
|
57
57
|
constructor(arrayLength: number);
|
|
58
58
|
constructor(arrayLength?: number);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Sealant } from '../util/Sealant';
|
|
2
2
|
import { MvccObject } from './Mvcc';
|
|
3
3
|
export class MvccArray extends MvccObject {
|
|
4
|
-
constructor(
|
|
5
|
-
super(
|
|
4
|
+
constructor(isObservable, array) {
|
|
5
|
+
super(isObservable);
|
|
6
6
|
this.all = array;
|
|
7
7
|
}
|
|
8
8
|
get length() { return this.all.length; }
|
|
@@ -51,7 +51,7 @@ export class TransactionalArray extends MvccArray {
|
|
|
51
51
|
super(false, args !== undefined ? new Array(args) : new Array());
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
export class
|
|
54
|
+
export class ObservableArray extends MvccArray {
|
|
55
55
|
constructor(args) {
|
|
56
56
|
super(true, args !== undefined ? new Array(args) : new Array());
|
|
57
57
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Collection, Item, CollectionReader } from '../util/Collection';
|
|
2
|
-
import {
|
|
3
|
-
export declare abstract class
|
|
2
|
+
import { ObservableObject } from './Mvcc';
|
|
3
|
+
export declare abstract class ObservableCollection<T> extends ObservableObject implements CollectionReader<T> {
|
|
4
4
|
protected abstract a: Collection<T>;
|
|
5
5
|
get strict(): boolean;
|
|
6
6
|
get count(): number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export class
|
|
1
|
+
import { ObservableObject } from './Mvcc';
|
|
2
|
+
export class ObservableCollection extends ObservableObject {
|
|
3
3
|
get strict() { return this.a.strict; }
|
|
4
4
|
get count() { return this.a.count; }
|
|
5
5
|
get addedCount() { return this.a.addedCount; }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MvccObject } from './Mvcc';
|
|
2
2
|
export declare class MvccMap<K, V> extends MvccObject {
|
|
3
3
|
private all;
|
|
4
|
-
constructor(
|
|
4
|
+
constructor(isObservable: boolean, map: Map<K, V>);
|
|
5
5
|
clear(): void;
|
|
6
6
|
delete(key: K): boolean;
|
|
7
7
|
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
|
|
@@ -19,7 +19,7 @@ export declare class TransactionalMap<K, V> extends MvccMap<K, V> {
|
|
|
19
19
|
constructor();
|
|
20
20
|
constructor(iterable?: Iterable<readonly [K, V]> | null);
|
|
21
21
|
}
|
|
22
|
-
export declare class
|
|
22
|
+
export declare class ObservableMap<K, V> extends MvccMap<K, V> {
|
|
23
23
|
constructor();
|
|
24
24
|
constructor(iterable?: Iterable<readonly [K, V]> | null);
|
|
25
25
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Sealant } from '../util/Sealant';
|
|
2
2
|
import { MvccObject } from './Mvcc';
|
|
3
3
|
export class MvccMap extends MvccObject {
|
|
4
|
-
constructor(
|
|
5
|
-
super(
|
|
4
|
+
constructor(isObservable, map) {
|
|
5
|
+
super(isObservable);
|
|
6
6
|
this.all = map;
|
|
7
7
|
}
|
|
8
8
|
clear() { this.mutable.clear(); }
|
|
@@ -28,7 +28,7 @@ export class TransactionalMap extends MvccMap {
|
|
|
28
28
|
super(true, args !== undefined ? new Map(args) : new Map());
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
export class
|
|
31
|
+
export class ObservableMap extends MvccMap {
|
|
32
32
|
constructor(args) {
|
|
33
33
|
super(true, args !== undefined ? new Map(args) : new Map());
|
|
34
34
|
}
|
|
@@ -9,7 +9,7 @@ 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, Mvcc.
|
|
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();
|