reactronic 0.22.204 → 0.22.205
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 +2 -2
- package/build/dist/source/Options.d.ts +3 -3
- package/build/dist/source/api.d.ts +1 -1
- package/build/dist/source/api.js +3 -3
- package/build/dist/source/impl/EditJournal.d.ts +37 -0
- package/build/dist/source/impl/{TransactionJournal.js → EditJournal.js} +58 -31
- package/build/dist/source/impl/Hooks.d.ts +2 -2
- package/build/dist/source/impl/Operation.js +2 -2
- package/package.json +1 -1
- package/build/dist/source/impl/TransactionJournal.d.ts +0 -27
package/README.md
CHANGED
|
@@ -310,7 +310,7 @@ function sensitive<T>(sensitivity: Sensitivity, func: F<T>, ...args: any[]): T
|
|
|
310
310
|
export interface SnapshotOptions {
|
|
311
311
|
readonly hint?: string
|
|
312
312
|
readonly standalone?: StandaloneMode
|
|
313
|
-
readonly journal?:
|
|
313
|
+
readonly journal?: EditJournal
|
|
314
314
|
readonly logging?: Partial<LoggingOptions>
|
|
315
315
|
readonly token?: any
|
|
316
316
|
}
|
|
@@ -323,7 +323,7 @@ interface MemberOptions {
|
|
|
323
323
|
readonly triggeringArgs: boolean
|
|
324
324
|
readonly throttling: number // milliseconds, -1 is immediately, Number.MAX_SAFE_INTEGER is never
|
|
325
325
|
readonly reentrance: Reentrance
|
|
326
|
-
readonly journal:
|
|
326
|
+
readonly journal: EditJournal | undefined
|
|
327
327
|
readonly monitor: Monitor | null
|
|
328
328
|
readonly logging?: Partial<LoggingOptions>
|
|
329
329
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { LoggingOptions } from './Logging';
|
|
2
2
|
import { StandaloneMode } from './impl/Data';
|
|
3
3
|
export { LoggingOptions, ProfilingOptions, LoggingLevel } from './Logging';
|
|
4
|
-
import {
|
|
4
|
+
import { EditJournal } from './impl/EditJournal';
|
|
5
5
|
import { Monitor } from './impl/Monitor';
|
|
6
6
|
export interface SnapshotOptions {
|
|
7
7
|
readonly hint?: string;
|
|
8
8
|
readonly standalone?: StandaloneMode;
|
|
9
|
-
readonly journal?:
|
|
9
|
+
readonly journal?: EditJournal;
|
|
10
10
|
readonly logging?: Partial<LoggingOptions>;
|
|
11
11
|
readonly token?: any;
|
|
12
12
|
}
|
|
@@ -18,7 +18,7 @@ export interface MemberOptions {
|
|
|
18
18
|
readonly triggeringArgs: boolean;
|
|
19
19
|
readonly throttling: number;
|
|
20
20
|
readonly reentrance: Reentrance;
|
|
21
|
-
readonly journal:
|
|
21
|
+
readonly journal: EditJournal | undefined;
|
|
22
22
|
readonly monitor: Monitor | null;
|
|
23
23
|
readonly logging?: Partial<LoggingOptions>;
|
|
24
24
|
}
|
|
@@ -10,5 +10,5 @@ export { ObservableObject } from './impl/Hooks';
|
|
|
10
10
|
export { Snapshot } from './impl/Snapshot';
|
|
11
11
|
export { Transaction } from './impl/Transaction';
|
|
12
12
|
export { Monitor } from './impl/Monitor';
|
|
13
|
-
export {
|
|
13
|
+
export { EditJournal } from './impl/EditJournal';
|
|
14
14
|
export { Rx, nonreactive, sensitive, unobservable, transaction, reaction, cached, options } from './Rx';
|
package/build/dist/source/api.js
CHANGED
|
@@ -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.unobservable = exports.sensitive = exports.nonreactive = exports.Rx = exports.
|
|
3
|
+
exports.options = exports.cached = exports.reaction = exports.transaction = exports.unobservable = exports.sensitive = exports.nonreactive = exports.Rx = exports.EditJournal = exports.Monitor = exports.Transaction = exports.Snapshot = exports.ObservableObject = 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; } });
|
|
@@ -27,8 +27,8 @@ 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");
|
|
29
29
|
Object.defineProperty(exports, "Monitor", { enumerable: true, get: function () { return Monitor_1.Monitor; } });
|
|
30
|
-
var
|
|
31
|
-
Object.defineProperty(exports, "
|
|
30
|
+
var EditJournal_1 = require("./impl/EditJournal");
|
|
31
|
+
Object.defineProperty(exports, "EditJournal", { enumerable: true, get: function () { return EditJournal_1.EditJournal; } });
|
|
32
32
|
var Rx_1 = require("./Rx");
|
|
33
33
|
Object.defineProperty(exports, "Rx", { enumerable: true, get: function () { return Rx_1.Rx; } });
|
|
34
34
|
Object.defineProperty(exports, "nonreactive", { enumerable: true, get: function () { return Rx_1.nonreactive; } });
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ObservableObject } from './Hooks';
|
|
2
|
+
import { ObjectHolder, ObjectRevision, Patch } from './Data';
|
|
3
|
+
export declare abstract class EditJournal extends ObservableObject {
|
|
4
|
+
abstract capacity: number;
|
|
5
|
+
abstract readonly isSaving: boolean;
|
|
6
|
+
abstract readonly edits: ReadonlyArray<Patch>;
|
|
7
|
+
abstract readonly canUndo: boolean;
|
|
8
|
+
abstract readonly canRedo: boolean;
|
|
9
|
+
abstract undo(count?: number): void;
|
|
10
|
+
abstract redo(count?: number): void;
|
|
11
|
+
abstract getUnsaved(): Patch | undefined;
|
|
12
|
+
abstract beginSave(): void;
|
|
13
|
+
abstract endSave(success: boolean): void;
|
|
14
|
+
abstract register(patch: Patch): void;
|
|
15
|
+
static create(): EditJournal;
|
|
16
|
+
}
|
|
17
|
+
export declare class EditJournalImpl extends EditJournal {
|
|
18
|
+
private _capacity;
|
|
19
|
+
private _isSaving;
|
|
20
|
+
private _edits;
|
|
21
|
+
private _position;
|
|
22
|
+
private _saved;
|
|
23
|
+
get capacity(): number;
|
|
24
|
+
set capacity(value: number);
|
|
25
|
+
get isSaving(): boolean;
|
|
26
|
+
get edits(): ReadonlyArray<Patch>;
|
|
27
|
+
get canUndo(): boolean;
|
|
28
|
+
get canRedo(): boolean;
|
|
29
|
+
undo(count?: number): void;
|
|
30
|
+
redo(count?: number): void;
|
|
31
|
+
getUnsaved(): Patch | undefined;
|
|
32
|
+
beginSave(): void;
|
|
33
|
+
endSave(success: boolean): void;
|
|
34
|
+
register(p: Patch): void;
|
|
35
|
+
static buildPatch(hint: string, changeset: Map<ObjectHolder, ObjectRevision>): Patch;
|
|
36
|
+
static applyPatch(patch: Patch, undo: boolean): void;
|
|
37
|
+
}
|
|
@@ -1,62 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.EditJournalImpl = exports.EditJournal = void 0;
|
|
4
4
|
const Hooks_1 = require("./Hooks");
|
|
5
5
|
const Data_1 = require("./Data");
|
|
6
6
|
const Snapshot_1 = require("./Snapshot");
|
|
7
7
|
const Transaction_1 = require("./Transaction");
|
|
8
8
|
const Sealant_1 = require("../util/Sealant");
|
|
9
|
-
class
|
|
10
|
-
static create() { return new
|
|
9
|
+
class EditJournal extends Hooks_1.ObservableObject {
|
|
10
|
+
static create() { return new EditJournalImpl(); }
|
|
11
11
|
}
|
|
12
|
-
exports.
|
|
13
|
-
class
|
|
12
|
+
exports.EditJournal = EditJournal;
|
|
13
|
+
class EditJournalImpl extends EditJournal {
|
|
14
14
|
constructor() {
|
|
15
15
|
super(...arguments);
|
|
16
16
|
this._capacity = 5;
|
|
17
|
-
this.
|
|
17
|
+
this._isSaving = false;
|
|
18
|
+
this._edits = [];
|
|
18
19
|
this._position = 0;
|
|
20
|
+
this._saved = 0;
|
|
19
21
|
}
|
|
20
22
|
get capacity() { return this._capacity; }
|
|
21
|
-
set capacity(value) { this._capacity = value; if (value < this.
|
|
22
|
-
this.
|
|
23
|
-
get
|
|
24
|
-
get
|
|
25
|
-
get
|
|
26
|
-
|
|
27
|
-
Transaction_1.Transaction.run({ hint: 'TransactionJournal.remember', standalone: 'isolated' }, () => {
|
|
28
|
-
const items = this._items = this._items.toMutable();
|
|
29
|
-
if (items.length >= this._capacity)
|
|
30
|
-
items.shift();
|
|
31
|
-
else
|
|
32
|
-
items.splice(this._position);
|
|
33
|
-
items.push(p);
|
|
34
|
-
this._position = items.length;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
23
|
+
set capacity(value) { this._capacity = value; if (value < this._edits.length)
|
|
24
|
+
this._edits.splice(0, this._edits.length - value); }
|
|
25
|
+
get isSaving() { return this._isSaving; }
|
|
26
|
+
get edits() { return this._edits; }
|
|
27
|
+
get canUndo() { return this._edits.length > 0 && this._position > 0; }
|
|
28
|
+
get canRedo() { return this._position < this._edits.length; }
|
|
37
29
|
undo(count = 1) {
|
|
38
|
-
Transaction_1.Transaction.run({ hint: '
|
|
30
|
+
Transaction_1.Transaction.run({ hint: 'EditJournal.undo', standalone: 'isolated' }, () => {
|
|
39
31
|
let i = this._position - 1;
|
|
40
32
|
while (i >= 0 && count > 0) {
|
|
41
|
-
const patch = this.
|
|
42
|
-
|
|
33
|
+
const patch = this._edits[i];
|
|
34
|
+
EditJournalImpl.applyPatch(patch, true);
|
|
43
35
|
i--, count--;
|
|
44
36
|
}
|
|
45
37
|
this._position = i + 1;
|
|
46
38
|
});
|
|
47
39
|
}
|
|
48
40
|
redo(count = 1) {
|
|
49
|
-
Transaction_1.Transaction.run({ hint: '
|
|
41
|
+
Transaction_1.Transaction.run({ hint: 'EditJournal.redo', standalone: 'isolated' }, () => {
|
|
50
42
|
let i = this._position;
|
|
51
|
-
while (i < this.
|
|
52
|
-
const patch = this.
|
|
53
|
-
|
|
43
|
+
while (i < this._edits.length && count > 0) {
|
|
44
|
+
const patch = this._edits[i];
|
|
45
|
+
EditJournalImpl.applyPatch(patch, false);
|
|
54
46
|
i++, count--;
|
|
55
47
|
}
|
|
56
48
|
this._position = i;
|
|
57
49
|
});
|
|
58
50
|
}
|
|
59
|
-
|
|
51
|
+
getUnsaved() {
|
|
52
|
+
let result = undefined;
|
|
53
|
+
const length = Math.abs(this._position - this._saved);
|
|
54
|
+
if (length !== 0) {
|
|
55
|
+
result = { hint: 'unsaved changes', objects: new Map() };
|
|
56
|
+
const direction = Math.sign(this._position - this._saved);
|
|
57
|
+
let i = 0;
|
|
58
|
+
while (i < length) {
|
|
59
|
+
const patch = this._edits[this._position + direction * (i + 1)];
|
|
60
|
+
patch.objects.forEach((p, obj) => {
|
|
61
|
+
});
|
|
62
|
+
i++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
beginSave() {
|
|
68
|
+
this._isSaving = true;
|
|
69
|
+
}
|
|
70
|
+
endSave(success) {
|
|
71
|
+
if (success)
|
|
72
|
+
this._saved = this._position;
|
|
73
|
+
this._isSaving = false;
|
|
74
|
+
}
|
|
75
|
+
register(p) {
|
|
76
|
+
Transaction_1.Transaction.run({ hint: 'EditJournal.remember', standalone: 'isolated' }, () => {
|
|
77
|
+
const items = this._edits = this._edits.toMutable();
|
|
78
|
+
if (items.length >= this._capacity)
|
|
79
|
+
items.shift();
|
|
80
|
+
else
|
|
81
|
+
items.splice(this._position);
|
|
82
|
+
items.push(p);
|
|
83
|
+
this._position = items.length;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
static buildPatch(hint, changeset) {
|
|
60
87
|
const patch = { hint, objects: new Map() };
|
|
61
88
|
changeset.forEach((r, h) => {
|
|
62
89
|
const p = { current: {}, former: {} };
|
|
@@ -95,7 +122,7 @@ class TransactionJournalImpl extends TransactionJournal {
|
|
|
95
122
|
});
|
|
96
123
|
}
|
|
97
124
|
}
|
|
98
|
-
exports.
|
|
125
|
+
exports.EditJournalImpl = EditJournalImpl;
|
|
99
126
|
function unseal(observable) {
|
|
100
127
|
const result = observable.value;
|
|
101
128
|
const createCopy = result === null || result === void 0 ? void 0 : result[Sealant_1.Sealant.CreateCopy];
|
|
@@ -2,7 +2,7 @@ import { F } from '../util/Utils';
|
|
|
2
2
|
import { MemberOptions, Kind, Reentrance } from '../Options';
|
|
3
3
|
import { LoggingOptions, ProfilingOptions } from '../Logging';
|
|
4
4
|
import { MemberName, ObjectHolder, StandaloneMode } from './Data';
|
|
5
|
-
import {
|
|
5
|
+
import { EditJournal } from './EditJournal';
|
|
6
6
|
import { Monitor } from './Monitor';
|
|
7
7
|
export declare abstract class ObservableObject {
|
|
8
8
|
constructor();
|
|
@@ -18,7 +18,7 @@ export declare class OptionsImpl implements MemberOptions {
|
|
|
18
18
|
readonly triggeringArgs: boolean;
|
|
19
19
|
readonly throttling: number;
|
|
20
20
|
readonly reentrance: Reentrance;
|
|
21
|
-
readonly journal:
|
|
21
|
+
readonly journal: EditJournal | undefined;
|
|
22
22
|
readonly monitor: Monitor | null;
|
|
23
23
|
readonly logging?: Partial<LoggingOptions>;
|
|
24
24
|
static readonly INITIAL: Readonly<OptionsImpl>;
|
|
@@ -9,7 +9,7 @@ const Snapshot_1 = require("./Snapshot");
|
|
|
9
9
|
const Transaction_1 = require("./Transaction");
|
|
10
10
|
const Monitor_1 = require("./Monitor");
|
|
11
11
|
const Hooks_1 = require("./Hooks");
|
|
12
|
-
const
|
|
12
|
+
const EditJournal_1 = require("./EditJournal");
|
|
13
13
|
const BOOT_ARGS = [];
|
|
14
14
|
const BOOT_CAUSE = '<boot>';
|
|
15
15
|
const ROOT_HOLDER = new Data_1.ObjectHolder(undefined, undefined, Hooks_1.Hooks.proxy, Snapshot_1.ROOT_REV, '<root>');
|
|
@@ -490,7 +490,7 @@ class Operation extends Data_1.Observable {
|
|
|
490
490
|
Operation.propagateMemberChangeThroughSubscriptions(true, since, r, m, h, reactions);
|
|
491
491
|
});
|
|
492
492
|
reactions.sort(compareReactionsByOrder);
|
|
493
|
-
(_a = snapshot.options.journal) === null || _a === void 0 ? void 0 : _a.
|
|
493
|
+
(_a = snapshot.options.journal) === null || _a === void 0 ? void 0 : _a.register(EditJournal_1.EditJournalImpl.buildPatch(snapshot.hint, snapshot.changeset));
|
|
494
494
|
}
|
|
495
495
|
static revokeAllSubscriptions(snapshot) {
|
|
496
496
|
snapshot.changeset.forEach((r, h) => r.changes.forEach((o, m) => Operation.propagateMemberChangeThroughSubscriptions(true, snapshot.timestamp, r, m, h, undefined)));
|
package/package.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ObservableObject } from './Hooks';
|
|
2
|
-
import { ObjectHolder, ObjectRevision, Patch } from './Data';
|
|
3
|
-
export declare abstract class TransactionJournal extends ObservableObject {
|
|
4
|
-
abstract capacity: number;
|
|
5
|
-
abstract readonly items: ReadonlyArray<Patch>;
|
|
6
|
-
abstract readonly canUndo: boolean;
|
|
7
|
-
abstract readonly canRedo: boolean;
|
|
8
|
-
abstract undo(count?: number): void;
|
|
9
|
-
abstract redo(count?: number): void;
|
|
10
|
-
abstract remember(patch: Patch): void;
|
|
11
|
-
static create(): TransactionJournal;
|
|
12
|
-
}
|
|
13
|
-
export declare class TransactionJournalImpl extends TransactionJournal {
|
|
14
|
-
private _capacity;
|
|
15
|
-
private _items;
|
|
16
|
-
private _position;
|
|
17
|
-
get capacity(): number;
|
|
18
|
-
set capacity(value: number);
|
|
19
|
-
get items(): ReadonlyArray<Patch>;
|
|
20
|
-
get canUndo(): boolean;
|
|
21
|
-
get canRedo(): boolean;
|
|
22
|
-
remember(p: Patch): void;
|
|
23
|
-
undo(count?: number): void;
|
|
24
|
-
redo(count?: number): void;
|
|
25
|
-
static createPatch(hint: string, changeset: Map<ObjectHolder, ObjectRevision>): Patch;
|
|
26
|
-
static applyPatch(patch: Patch, undo: boolean): void;
|
|
27
|
-
}
|