mol_wire_pub 1.0.1709 → 1.0.1711
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/node.d.ts +73 -0
- package/node.d.ts.map +1 -1
- package/node.js +53 -1
- package/node.js.map +1 -1
- package/node.mjs +53 -1
- package/node.test.js +53 -1
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +73 -0
- package/web.d.ts.map +1 -1
- package/web.js +53 -1
- package/web.js.map +1 -1
- package/web.mjs +53 -1
package/node.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare namespace $ {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
declare namespace $ {
|
|
18
|
+
/** Generates unique identifier. */
|
|
18
19
|
function $mol_guid(length?: number, exists?: (id: string) => boolean): string;
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -23,53 +24,125 @@ declare namespace $ {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
declare namespace $ {
|
|
27
|
+
/** Special status statuses. */
|
|
26
28
|
enum $mol_wire_cursor {
|
|
29
|
+
/** Update required. */
|
|
27
30
|
stale = -1,
|
|
31
|
+
/** Some of (transitive) pub update required. */
|
|
28
32
|
doubt = -2,
|
|
33
|
+
/** Actual state but may be dropped. */
|
|
29
34
|
fresh = -3,
|
|
35
|
+
/** State will never be changed. */
|
|
30
36
|
final = -4
|
|
31
37
|
}
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
declare namespace $ {
|
|
41
|
+
/**
|
|
42
|
+
* Collects subscribers in compact array. 28B
|
|
43
|
+
*/
|
|
35
44
|
class $mol_wire_pub extends Object {
|
|
36
45
|
constructor(id?: string);
|
|
37
46
|
[Symbol.toStringTag]: string;
|
|
38
47
|
data: unknown[];
|
|
39
48
|
static get [Symbol.species](): ArrayConstructor;
|
|
49
|
+
/**
|
|
50
|
+
* Index of first subscriber.
|
|
51
|
+
*/
|
|
40
52
|
protected sub_from: number;
|
|
53
|
+
/**
|
|
54
|
+
* All current subscribers.
|
|
55
|
+
*/
|
|
41
56
|
get sub_list(): readonly $mol_wire_sub[];
|
|
57
|
+
/**
|
|
58
|
+
* Has any subscribers or not.
|
|
59
|
+
*/
|
|
42
60
|
get sub_empty(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
63
|
+
*/
|
|
43
64
|
sub_on(sub: $mol_wire_pub, pub_pos: number): number;
|
|
65
|
+
/**
|
|
66
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
67
|
+
*/
|
|
44
68
|
sub_off(sub_pos: number): void;
|
|
69
|
+
/**
|
|
70
|
+
* Called when last sub was unsubscribed.
|
|
71
|
+
**/
|
|
45
72
|
reap(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Autowire this publisher with current subscriber.
|
|
75
|
+
**/
|
|
46
76
|
promote(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Enforce actualization. Should not throw errors.
|
|
79
|
+
*/
|
|
47
80
|
fresh(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Allow to put data to caches in the subtree.
|
|
83
|
+
*/
|
|
48
84
|
complete(): void;
|
|
49
85
|
get incompleted(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Notify subscribers about self changes.
|
|
88
|
+
*/
|
|
50
89
|
emit(quant?: $mol_wire_cursor): void;
|
|
90
|
+
/**
|
|
91
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
92
|
+
*/
|
|
51
93
|
peer_move(from_pos: number, to_pos: number): void;
|
|
94
|
+
/**
|
|
95
|
+
* Updates self position in the peer.
|
|
96
|
+
*/
|
|
52
97
|
peer_repos(peer_pos: number, self_pos: number): void;
|
|
53
98
|
}
|
|
54
99
|
}
|
|
55
100
|
|
|
56
101
|
declare namespace $ {
|
|
102
|
+
/** Generic subscriber interface */
|
|
57
103
|
interface $mol_wire_sub extends $mol_wire_pub {
|
|
58
104
|
temp: boolean;
|
|
59
105
|
pub_list: $mol_wire_pub[];
|
|
106
|
+
/**
|
|
107
|
+
* Begin auto wire to publishers.
|
|
108
|
+
* Returns previous auto subscriber that must me transfer to the `end`.
|
|
109
|
+
*/
|
|
60
110
|
track_on(): $mol_wire_sub | null;
|
|
111
|
+
/**
|
|
112
|
+
* Returns next auto wired publisher. It can be easely repormoted.
|
|
113
|
+
* Or promotes next publisher to auto wire its togeter.
|
|
114
|
+
* Must be used only between `track_on` and `track_off`.
|
|
115
|
+
*/
|
|
61
116
|
track_next(pub?: $mol_wire_pub): $mol_wire_pub | null;
|
|
62
117
|
pub_off(pub_pos: number): void;
|
|
118
|
+
/**
|
|
119
|
+
* Unsubscribes from unpromoted publishers.
|
|
120
|
+
*/
|
|
63
121
|
track_cut(sub: $mol_wire_pub | null): void;
|
|
122
|
+
/**
|
|
123
|
+
* Ends auto wire to publishers.
|
|
124
|
+
*/
|
|
64
125
|
track_off(sub: $mol_wire_pub | null): void;
|
|
126
|
+
/**
|
|
127
|
+
* Receive notification about publisher changes.
|
|
128
|
+
*/
|
|
65
129
|
absorb(quant: $mol_wire_cursor, pos: number): void;
|
|
130
|
+
/**
|
|
131
|
+
* Unsubscribes from all publishers.
|
|
132
|
+
*/
|
|
66
133
|
destructor(): void;
|
|
67
134
|
}
|
|
68
135
|
}
|
|
69
136
|
|
|
70
137
|
declare namespace $ {
|
|
71
138
|
let $mol_wire_auto_sub: $mol_wire_sub | null;
|
|
139
|
+
/**
|
|
140
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
141
|
+
*/
|
|
72
142
|
function $mol_wire_auto(next?: $mol_wire_sub | null): $mol_wire_sub | null;
|
|
143
|
+
/**
|
|
144
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
145
|
+
*/
|
|
73
146
|
const $mol_wire_affected: ($mol_wire_sub | number)[];
|
|
74
147
|
}
|
|
75
148
|
|
package/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../mam.d.ts","../../../guid/guid.d.ts","../../../fail/fail.d.ts","../../cursor/cursor.d.ts","../pub.d.ts","../../sub/sub.d.ts","../../wire.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACfA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["../../../../mam.d.ts","../../../guid/guid.d.ts","../../../fail/fail.d.ts","../../cursor/cursor.d.ts","../pub.d.ts","../../sub/sub.d.ts","../../wire.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACfA;AACA;AACA;AACA;AACA;ACJA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC5DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourcesContent":[null,null,null,null,null,null,null]}
|
package/node.js
CHANGED
|
@@ -32,6 +32,7 @@ $.$$ = $
|
|
|
32
32
|
"use strict";
|
|
33
33
|
var $;
|
|
34
34
|
(function ($) {
|
|
35
|
+
/** Generates unique identifier. */
|
|
35
36
|
function $mol_guid(length = 8, exists = () => false) {
|
|
36
37
|
for (;;) {
|
|
37
38
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -57,11 +58,16 @@ var $;
|
|
|
57
58
|
"use strict";
|
|
58
59
|
var $;
|
|
59
60
|
(function ($) {
|
|
61
|
+
/** Special status statuses. */
|
|
60
62
|
let $mol_wire_cursor;
|
|
61
63
|
(function ($mol_wire_cursor) {
|
|
64
|
+
/** Update required. */
|
|
62
65
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
66
|
+
/** Some of (transitive) pub update required. */
|
|
63
67
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
68
|
+
/** Actual state but may be dropped. */
|
|
64
69
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
70
|
+
/** State will never be changed. */
|
|
65
71
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
66
72
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
67
73
|
})($ || ($ = {}));
|
|
@@ -70,6 +76,9 @@ var $;
|
|
|
70
76
|
"use strict";
|
|
71
77
|
var $;
|
|
72
78
|
(function ($) {
|
|
79
|
+
/**
|
|
80
|
+
* Collects subscribers in compact array. 28B
|
|
81
|
+
*/
|
|
73
82
|
class $mol_wire_pub extends Object {
|
|
74
83
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
75
84
|
super();
|
|
@@ -77,10 +86,17 @@ var $;
|
|
|
77
86
|
}
|
|
78
87
|
[Symbol.toStringTag];
|
|
79
88
|
data = [];
|
|
89
|
+
// Derived objects should be Arrays.
|
|
80
90
|
static get [Symbol.species]() {
|
|
81
91
|
return Array;
|
|
82
92
|
}
|
|
83
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Index of first subscriber.
|
|
95
|
+
*/
|
|
96
|
+
sub_from = 0; // 4B
|
|
97
|
+
/**
|
|
98
|
+
* All current subscribers.
|
|
99
|
+
*/
|
|
84
100
|
get sub_list() {
|
|
85
101
|
const res = [];
|
|
86
102
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -88,14 +104,23 @@ var $;
|
|
|
88
104
|
}
|
|
89
105
|
return res;
|
|
90
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Has any subscribers or not.
|
|
109
|
+
*/
|
|
91
110
|
get sub_empty() {
|
|
92
111
|
return this.sub_from === this.data.length;
|
|
93
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
115
|
+
*/
|
|
94
116
|
sub_on(sub, pub_pos) {
|
|
95
117
|
const pos = this.data.length;
|
|
96
118
|
this.data.push(sub, pub_pos);
|
|
97
119
|
return pos;
|
|
98
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
123
|
+
*/
|
|
99
124
|
sub_off(sub_pos) {
|
|
100
125
|
if (!(sub_pos < this.data.length)) {
|
|
101
126
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -108,21 +133,39 @@ var $;
|
|
|
108
133
|
if (end === this.sub_from)
|
|
109
134
|
this.reap();
|
|
110
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Called when last sub was unsubscribed.
|
|
138
|
+
**/
|
|
111
139
|
reap() { }
|
|
140
|
+
/**
|
|
141
|
+
* Autowire this publisher with current subscriber.
|
|
142
|
+
**/
|
|
112
143
|
promote() {
|
|
113
144
|
$mol_wire_auto()?.track_next(this);
|
|
114
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Enforce actualization. Should not throw errors.
|
|
148
|
+
*/
|
|
115
149
|
fresh() { }
|
|
150
|
+
/**
|
|
151
|
+
* Allow to put data to caches in the subtree.
|
|
152
|
+
*/
|
|
116
153
|
complete() { }
|
|
117
154
|
get incompleted() {
|
|
118
155
|
return false;
|
|
119
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Notify subscribers about self changes.
|
|
159
|
+
*/
|
|
120
160
|
emit(quant = $mol_wire_cursor.stale) {
|
|
121
161
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
122
162
|
;
|
|
123
163
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
124
164
|
}
|
|
125
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
168
|
+
*/
|
|
126
169
|
peer_move(from_pos, to_pos) {
|
|
127
170
|
const peer = this.data[from_pos];
|
|
128
171
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -130,6 +173,9 @@ var $;
|
|
|
130
173
|
this.data[to_pos + 1] = self_pos;
|
|
131
174
|
peer.peer_repos(self_pos, to_pos);
|
|
132
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Updates self position in the peer.
|
|
178
|
+
*/
|
|
133
179
|
peer_repos(peer_pos, self_pos) {
|
|
134
180
|
this.data[peer_pos + 1] = self_pos;
|
|
135
181
|
}
|
|
@@ -145,10 +191,16 @@ var $;
|
|
|
145
191
|
var $;
|
|
146
192
|
(function ($) {
|
|
147
193
|
$.$mol_wire_auto_sub = null;
|
|
194
|
+
/**
|
|
195
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
196
|
+
*/
|
|
148
197
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
149
198
|
return $.$mol_wire_auto_sub = next;
|
|
150
199
|
}
|
|
151
200
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
201
|
+
/**
|
|
202
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
203
|
+
*/
|
|
152
204
|
$.$mol_wire_affected = [];
|
|
153
205
|
})($ || ($ = {}));
|
|
154
206
|
|
package/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["-","../../../../mam.ts","../../../../mol/guid/guid.ts","../../../../mol/fail/fail.ts","../../../../mol/wire/cursor/cursor.ts","../../../../mol/wire/pub/pub.ts","../../../../mol/wire/wire.ts"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAQV;AARD,WAAU,CAAC;AAQX,CAAC,EARS,CAAC,KAAD,CAAC,QAQV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;ADflB;AACA;AACA;;;;;;;;;;;;;;;AEFA,IAAU,CAAC,CAkBV;AAlBD,WAAU,CAAC;
|
|
1
|
+
{"version":3,"sources":["-","../../../../mam.ts","../../../../mol/guid/guid.ts","../../../../mol/fail/fail.ts","../../../../mol/wire/cursor/cursor.ts","../../../../mol/wire/pub/pub.ts","../../../../mol/wire/wire.ts"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAQV;AARD,WAAU,CAAC;AAQX,CAAC,EARS,CAAC,KAAD,CAAC,QAQV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;ADflB;AACA;AACA;;;;;;;;;;;;;;;AEFA,IAAU,CAAC,CAkBV;AAlBD,WAAU,CAAC;IAEV,mCAAmC;IACnC,SAAgB,SAAS,CACxB,MAAM,GAAG,CAAC,EACV,SAAmC,GAAE,EAAE,CAAC,KAAK;QAG7C,SAAQ,CAAC;YAER,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAE,EAAE,CAAE,CAAC,SAAS,CAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAE,CAAC,WAAW,EAAE,CAAA;YAC9E,IAAI,MAAM,CAAE,EAAE,CAAE;gBAAG,SAAQ;YAE3B,OAAO,EAAE,CAAA;QACV,CAAC;IAEF,CAAC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CAAA;IACjC,CAAC;IAFe,gBAAc,iBAE7B,CAAA;IAED;;OAEG;IACU,oBAAkB,GAAG,EAAkC,CAAA;AAErE,CAAC,EAhBS,CAAC,KAAD,CAAC,QAgBV;;","sourcesContent":[null,"Error.stackTraceLimit = 50;\n\ndeclare let _$_: { new(): {} } & typeof globalThis\ndeclare class $ extends _$_ {}\n\nnamespace $ {\n\texport type $ = typeof $$\n\texport declare class $$ extends $ {\n\t\tstatic $: $\n\t}\n\tnamespace $$ {\n\t\texport type $$ = $\n\t}\n}\n\nmodule.exports = $\n","namespace $ {\n\n\t/** Generates unique identifier. */\n\texport function $mol_guid(\n\t\tlength = 8,\n\t\texists: ( id: string )=> boolean = ()=> false,\n\t) {\n\n\t\tfor(;;) {\n\n\t\t\tlet id = Math.random().toString( 36 ).substring( 2, length + 2 ).toUpperCase()\n\t\t\tif( exists( id ) ) continue\n\t\t\t\n\t\t\treturn id\n\t\t}\n\n\t}\n\n}\n","namespace $ {\n\n\texport function $mol_fail( error : any ) : never {\n\t\tthrow error\n\t}\n\n}\n","namespace $ {\n\t\n\t/** Special status statuses. */\n\texport enum $mol_wire_cursor {\n\t\t\n\t\t/** Update required. */\n\t\tstale = -1,\n\t\t\n\t\t/** Some of (transitive) pub update required. */\n\t\tdoubt = -2,\n\t\t\n\t\t/** Actual state but may be dropped. */\n\t\tfresh = -3,\n\t\t\n\t\t/** State will never be changed. */\n\t\tfinal = -4,\n\t\t\n\t}\n\t\n}\n","namespace $ {\n\t\n\t/**\n\t * Collects subscribers in compact array. 28B\n\t */\n\texport class $mol_wire_pub extends Object {\n\t\t\n\t\tconstructor( id = `$mol_wire_pub:${ $mol_guid() }` ) {\n\t\t\tsuper()\n\t\t\tthis[ Symbol.toStringTag ] = id\n\t\t}\n\t\t\n\t\t[ Symbol.toStringTag ]!: string\n\t\tdata = [] as unknown[]\n\t\t\n\t\t// Derived objects should be Arrays.\n\t\tstatic get [ Symbol.species ]() {\n\t\t\treturn Array\n\t\t}\n\t\t\n\t\t/**\n\t\t * Index of first subscriber.\n\t\t */\n\t\tprotected sub_from = 0 // 4B\n\t\t\n\t\t/**\n\t\t * All current subscribers.\n\t\t */\n\t\tget sub_list() {\n\t\t\tconst res = [] as $mol_wire_sub[]\n\t\t\tfor( let i = this.sub_from; i < this.data.length; i += 2 ) {\n\t\t\t\tres.push( this.data[i] as $mol_wire_sub )\n\t\t\t}\n\t\t\treturn res as readonly $mol_wire_sub[]\n\t\t}\n\t\t\n\t\t/**\n\t\t * Has any subscribers or not.\n\t\t */\n\t\tget sub_empty() {\n\t\t\treturn this.sub_from === this.data.length\n\t\t}\n\t\t\n\t\t/**\n\t\t * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.\n\t\t */\n\t\tsub_on( sub: $mol_wire_pub, pub_pos: number ) {\n\t\t\tconst pos = this.data.length\n\t\t\tthis.data.push( sub, pub_pos )\n\t\t\treturn pos\n\t\t}\n\t\t\n\t\t/**\n\t\t * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.\n\t\t */\n\t\tsub_off( sub_pos: number ) {\n\t\t\t\n\t\t\tif(!( sub_pos < this.data.length )) {\n\t\t\t\t$mol_fail( new Error( `Wrong pos ${ sub_pos }` ) )\n\t\t\t}\n\t\t\t\n\t\t\tconst end = this.data.length - 2\n\t\t\tif( sub_pos !== end ) {\n\t\t\t\tthis.peer_move( end, sub_pos )\n\t\t\t}\n\t\t\t\n\t\t\tthis.data.length = end\n\t\t\t\n\t\t\tif( end === this.sub_from ) this.reap()\n\t\t\t\n\t\t}\n\t\t\n\t\t/**\n\t\t * Called when last sub was unsubscribed.\n\t\t **/\n\t\treap() { }\n\t\t\n\t\t/**\n\t\t * Autowire this publisher with current subscriber.\n\t\t **/\n\t\tpromote() {\n\t\t\t$mol_wire_auto()?.track_next( this )\n\t\t}\n\t\t\n\t\t/**\n\t\t * Enforce actualization. Should not throw errors.\n\t\t */\n\t\tfresh() {}\n\t\t\n\t\t/**\n\t\t * Allow to put data to caches in the subtree.\n\t\t */\n\t\tcomplete() {}\n\t\t\n\t\tget incompleted() {\n\t\t\treturn false\n\t\t}\n\t\t\n\t\t/**\n\t\t * Notify subscribers about self changes.\n\t\t */\n\t\temit( quant = $mol_wire_cursor.stale ) {\n\t\t\tfor( let i = this.sub_from; i < this.data.length; i += 2 ) {\n\t\t\t\t;( this.data[i] as $mol_wire_sub ).absorb( quant, this.data[ i + 1 ] as number )\n\t\t\t}\n\t\t}\n\t\t\n\t\t/**\n\t\t * Moves peer from one position to another. Doesn't clear data at old position!\n\t\t */\n\t\tpeer_move( from_pos: number, to_pos: number ) {\n\t\t\t\n\t\t\tconst peer = this.data[ from_pos ] as $mol_wire_pub\n\t\t\tconst self_pos = this.data[ from_pos + 1 ] as number\n\t\t\t\n\t\t\tthis.data[ to_pos ] = peer\n\t\t\tthis.data[ to_pos + 1 ] = self_pos\n\t\t\t\n\t\t\tpeer.peer_repos( self_pos, to_pos )\n\t\t}\n\t\t\n\t\t/**\n\t\t * Updates self position in the peer.\n\t\t */\n\t\tpeer_repos( peer_pos: number, self_pos: number ) {\n\t\t\tthis.data[ peer_pos + 1 ] = self_pos\n\t\t}\n\t\t\n\t}\n\t\n}\n","namespace $ {\n\t\n\texport let $mol_wire_auto_sub: $mol_wire_sub | null = null\n\t\n\t/**\n\t * When fulfilled, all publishers are promoted to this subscriber on access to its.\n\t */\n\texport function $mol_wire_auto( next = $mol_wire_auto_sub ) {\n\t\treturn $mol_wire_auto_sub = next\n\t}\n\t\n\t/**\n\t * Affection queue. Used to prevent accidental stack overflow on emit.\n\t */\n\texport const $mol_wire_affected = [] as ( $mol_wire_sub | number )[]\n\t\n}\n"]}
|
package/node.mjs
CHANGED
|
@@ -32,6 +32,7 @@ $.$$ = $
|
|
|
32
32
|
"use strict";
|
|
33
33
|
var $;
|
|
34
34
|
(function ($) {
|
|
35
|
+
/** Generates unique identifier. */
|
|
35
36
|
function $mol_guid(length = 8, exists = () => false) {
|
|
36
37
|
for (;;) {
|
|
37
38
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -57,11 +58,16 @@ var $;
|
|
|
57
58
|
"use strict";
|
|
58
59
|
var $;
|
|
59
60
|
(function ($) {
|
|
61
|
+
/** Special status statuses. */
|
|
60
62
|
let $mol_wire_cursor;
|
|
61
63
|
(function ($mol_wire_cursor) {
|
|
64
|
+
/** Update required. */
|
|
62
65
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
66
|
+
/** Some of (transitive) pub update required. */
|
|
63
67
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
68
|
+
/** Actual state but may be dropped. */
|
|
64
69
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
70
|
+
/** State will never be changed. */
|
|
65
71
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
66
72
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
67
73
|
})($ || ($ = {}));
|
|
@@ -70,6 +76,9 @@ var $;
|
|
|
70
76
|
"use strict";
|
|
71
77
|
var $;
|
|
72
78
|
(function ($) {
|
|
79
|
+
/**
|
|
80
|
+
* Collects subscribers in compact array. 28B
|
|
81
|
+
*/
|
|
73
82
|
class $mol_wire_pub extends Object {
|
|
74
83
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
75
84
|
super();
|
|
@@ -77,10 +86,17 @@ var $;
|
|
|
77
86
|
}
|
|
78
87
|
[Symbol.toStringTag];
|
|
79
88
|
data = [];
|
|
89
|
+
// Derived objects should be Arrays.
|
|
80
90
|
static get [Symbol.species]() {
|
|
81
91
|
return Array;
|
|
82
92
|
}
|
|
83
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Index of first subscriber.
|
|
95
|
+
*/
|
|
96
|
+
sub_from = 0; // 4B
|
|
97
|
+
/**
|
|
98
|
+
* All current subscribers.
|
|
99
|
+
*/
|
|
84
100
|
get sub_list() {
|
|
85
101
|
const res = [];
|
|
86
102
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -88,14 +104,23 @@ var $;
|
|
|
88
104
|
}
|
|
89
105
|
return res;
|
|
90
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Has any subscribers or not.
|
|
109
|
+
*/
|
|
91
110
|
get sub_empty() {
|
|
92
111
|
return this.sub_from === this.data.length;
|
|
93
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
115
|
+
*/
|
|
94
116
|
sub_on(sub, pub_pos) {
|
|
95
117
|
const pos = this.data.length;
|
|
96
118
|
this.data.push(sub, pub_pos);
|
|
97
119
|
return pos;
|
|
98
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
123
|
+
*/
|
|
99
124
|
sub_off(sub_pos) {
|
|
100
125
|
if (!(sub_pos < this.data.length)) {
|
|
101
126
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -108,21 +133,39 @@ var $;
|
|
|
108
133
|
if (end === this.sub_from)
|
|
109
134
|
this.reap();
|
|
110
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Called when last sub was unsubscribed.
|
|
138
|
+
**/
|
|
111
139
|
reap() { }
|
|
140
|
+
/**
|
|
141
|
+
* Autowire this publisher with current subscriber.
|
|
142
|
+
**/
|
|
112
143
|
promote() {
|
|
113
144
|
$mol_wire_auto()?.track_next(this);
|
|
114
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Enforce actualization. Should not throw errors.
|
|
148
|
+
*/
|
|
115
149
|
fresh() { }
|
|
150
|
+
/**
|
|
151
|
+
* Allow to put data to caches in the subtree.
|
|
152
|
+
*/
|
|
116
153
|
complete() { }
|
|
117
154
|
get incompleted() {
|
|
118
155
|
return false;
|
|
119
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Notify subscribers about self changes.
|
|
159
|
+
*/
|
|
120
160
|
emit(quant = $mol_wire_cursor.stale) {
|
|
121
161
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
122
162
|
;
|
|
123
163
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
124
164
|
}
|
|
125
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
168
|
+
*/
|
|
126
169
|
peer_move(from_pos, to_pos) {
|
|
127
170
|
const peer = this.data[from_pos];
|
|
128
171
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -130,6 +173,9 @@ var $;
|
|
|
130
173
|
this.data[to_pos + 1] = self_pos;
|
|
131
174
|
peer.peer_repos(self_pos, to_pos);
|
|
132
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Updates self position in the peer.
|
|
178
|
+
*/
|
|
133
179
|
peer_repos(peer_pos, self_pos) {
|
|
134
180
|
this.data[peer_pos + 1] = self_pos;
|
|
135
181
|
}
|
|
@@ -145,10 +191,16 @@ var $;
|
|
|
145
191
|
var $;
|
|
146
192
|
(function ($) {
|
|
147
193
|
$.$mol_wire_auto_sub = null;
|
|
194
|
+
/**
|
|
195
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
196
|
+
*/
|
|
148
197
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
149
198
|
return $.$mol_wire_auto_sub = next;
|
|
150
199
|
}
|
|
151
200
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
201
|
+
/**
|
|
202
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
203
|
+
*/
|
|
152
204
|
$.$mol_wire_affected = [];
|
|
153
205
|
})($ || ($ = {}));
|
|
154
206
|
|
package/node.test.js
CHANGED
|
@@ -23,6 +23,7 @@ $.$$ = $
|
|
|
23
23
|
"use strict";
|
|
24
24
|
var $;
|
|
25
25
|
(function ($) {
|
|
26
|
+
/** Generates unique identifier. */
|
|
26
27
|
function $mol_guid(length = 8, exists = () => false) {
|
|
27
28
|
for (;;) {
|
|
28
29
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -48,11 +49,16 @@ var $;
|
|
|
48
49
|
"use strict";
|
|
49
50
|
var $;
|
|
50
51
|
(function ($) {
|
|
52
|
+
/** Special status statuses. */
|
|
51
53
|
let $mol_wire_cursor;
|
|
52
54
|
(function ($mol_wire_cursor) {
|
|
55
|
+
/** Update required. */
|
|
53
56
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
57
|
+
/** Some of (transitive) pub update required. */
|
|
54
58
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
59
|
+
/** Actual state but may be dropped. */
|
|
55
60
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
61
|
+
/** State will never be changed. */
|
|
56
62
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
57
63
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
58
64
|
})($ || ($ = {}));
|
|
@@ -61,6 +67,9 @@ var $;
|
|
|
61
67
|
"use strict";
|
|
62
68
|
var $;
|
|
63
69
|
(function ($) {
|
|
70
|
+
/**
|
|
71
|
+
* Collects subscribers in compact array. 28B
|
|
72
|
+
*/
|
|
64
73
|
class $mol_wire_pub extends Object {
|
|
65
74
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
66
75
|
super();
|
|
@@ -68,10 +77,17 @@ var $;
|
|
|
68
77
|
}
|
|
69
78
|
[Symbol.toStringTag];
|
|
70
79
|
data = [];
|
|
80
|
+
// Derived objects should be Arrays.
|
|
71
81
|
static get [Symbol.species]() {
|
|
72
82
|
return Array;
|
|
73
83
|
}
|
|
74
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Index of first subscriber.
|
|
86
|
+
*/
|
|
87
|
+
sub_from = 0; // 4B
|
|
88
|
+
/**
|
|
89
|
+
* All current subscribers.
|
|
90
|
+
*/
|
|
75
91
|
get sub_list() {
|
|
76
92
|
const res = [];
|
|
77
93
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -79,14 +95,23 @@ var $;
|
|
|
79
95
|
}
|
|
80
96
|
return res;
|
|
81
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Has any subscribers or not.
|
|
100
|
+
*/
|
|
82
101
|
get sub_empty() {
|
|
83
102
|
return this.sub_from === this.data.length;
|
|
84
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
106
|
+
*/
|
|
85
107
|
sub_on(sub, pub_pos) {
|
|
86
108
|
const pos = this.data.length;
|
|
87
109
|
this.data.push(sub, pub_pos);
|
|
88
110
|
return pos;
|
|
89
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
114
|
+
*/
|
|
90
115
|
sub_off(sub_pos) {
|
|
91
116
|
if (!(sub_pos < this.data.length)) {
|
|
92
117
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -99,21 +124,39 @@ var $;
|
|
|
99
124
|
if (end === this.sub_from)
|
|
100
125
|
this.reap();
|
|
101
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Called when last sub was unsubscribed.
|
|
129
|
+
**/
|
|
102
130
|
reap() { }
|
|
131
|
+
/**
|
|
132
|
+
* Autowire this publisher with current subscriber.
|
|
133
|
+
**/
|
|
103
134
|
promote() {
|
|
104
135
|
$mol_wire_auto()?.track_next(this);
|
|
105
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Enforce actualization. Should not throw errors.
|
|
139
|
+
*/
|
|
106
140
|
fresh() { }
|
|
141
|
+
/**
|
|
142
|
+
* Allow to put data to caches in the subtree.
|
|
143
|
+
*/
|
|
107
144
|
complete() { }
|
|
108
145
|
get incompleted() {
|
|
109
146
|
return false;
|
|
110
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Notify subscribers about self changes.
|
|
150
|
+
*/
|
|
111
151
|
emit(quant = $mol_wire_cursor.stale) {
|
|
112
152
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
113
153
|
;
|
|
114
154
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
115
155
|
}
|
|
116
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
159
|
+
*/
|
|
117
160
|
peer_move(from_pos, to_pos) {
|
|
118
161
|
const peer = this.data[from_pos];
|
|
119
162
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -121,6 +164,9 @@ var $;
|
|
|
121
164
|
this.data[to_pos + 1] = self_pos;
|
|
122
165
|
peer.peer_repos(self_pos, to_pos);
|
|
123
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Updates self position in the peer.
|
|
169
|
+
*/
|
|
124
170
|
peer_repos(peer_pos, self_pos) {
|
|
125
171
|
this.data[peer_pos + 1] = self_pos;
|
|
126
172
|
}
|
|
@@ -136,10 +182,16 @@ var $;
|
|
|
136
182
|
var $;
|
|
137
183
|
(function ($) {
|
|
138
184
|
$.$mol_wire_auto_sub = null;
|
|
185
|
+
/**
|
|
186
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
187
|
+
*/
|
|
139
188
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
140
189
|
return $.$mol_wire_auto_sub = next;
|
|
141
190
|
}
|
|
142
191
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
192
|
+
/**
|
|
193
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
194
|
+
*/
|
|
143
195
|
$.$mol_wire_affected = [];
|
|
144
196
|
})($ || ($ = {}));
|
|
145
197
|
|
package/node.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../mam.ts","../../../../mol/guid/guid.ts","../../../../mol/fail/fail.ts","../../../../mol/wire/cursor/cursor.ts","../../../../mol/wire/pub/pub.ts","../../../../mol/wire/wire.ts"],"names":[],"mappings":";;AAAA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAQV;AARD,WAAU,CAAC;AAQX,CAAC,EARS,CAAC,KAAD,CAAC,QAQV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;;;;;;;;;;;;;;;ACflB,IAAU,CAAC,CAkBV;AAlBD,WAAU,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../../../mam.ts","../../../../mol/guid/guid.ts","../../../../mol/fail/fail.ts","../../../../mol/wire/cursor/cursor.ts","../../../../mol/wire/pub/pub.ts","../../../../mol/wire/wire.ts"],"names":[],"mappings":";;AAAA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAQV;AARD,WAAU,CAAC;AAQX,CAAC,EARS,CAAC,KAAD,CAAC,QAQV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;;;;;;;;;;;;;;;ACflB,IAAU,CAAC,CAkBV;AAlBD,WAAU,CAAC;IAEV,mCAAmC;IACnC,SAAgB,SAAS,CACxB,MAAM,GAAG,CAAC,EACV,SAAmC,GAAE,EAAE,CAAC,KAAK;QAG7C,SAAQ,CAAC;YAER,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAE,EAAE,CAAE,CAAC,SAAS,CAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAE,CAAC,WAAW,EAAE,CAAA;YAC9E,IAAI,MAAM,CAAE,EAAE,CAAE;gBAAG,SAAQ;YAE3B,OAAO,EAAE,CAAA;QACV,CAAC;IAEF,CAAC;IAbe,WAAS,YAaxB,CAAA;AAEF,CAAC,EAlBS,CAAC,KAAD,CAAC,QAkBV;;;;AClBD,IAAU,CAAC,CAMV;AAND,WAAU,CAAC;IAEV,SAAgB,SAAS,C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","sourcesContent":["Error.stackTraceLimit = 50;\n\ndeclare let _$_: { new(): {} } & typeof globalThis\ndeclare class $ extends _$_ {}\n\nnamespace $ {\n\texport type $ = typeof $$\n\texport declare class $$ extends $ {\n\t\tstatic $: $\n\t}\n\tnamespace $$ {\n\t\texport type $$ = $\n\t}\n}\n\nmodule.exports = $\n","namespace $ {\n\n\t/** Generates unique identifier. */\n\texport function $mol_guid(\n\t\tlength = 8,\n\t\texists: ( id: string )=> boolean = ()=> false,\n\t) {\n\n\t\tfor(;;) {\n\n\t\t\tlet id = Math.random().toString( 36 ).substring( 2, length + 2 ).toUpperCase()\n\t\t\tif( exists( id ) ) continue\n\t\t\t\n\t\t\treturn id\n\t\t}\n\n\t}\n\n}\n","namespace $ {\n\n\texport function $mol_fail( error : any ) : never {\n\t\tthrow error\n\t}\n\n}\n","namespace $ {\n\t\n\t/** Special status statuses. */\n\texport enum $mol_wire_cursor {\n\t\t\n\t\t/** Update required. */\n\t\tstale = -1,\n\t\t\n\t\t/** Some of (transitive) pub update required. */\n\t\tdoubt = -2,\n\t\t\n\t\t/** Actual state but may be dropped. */\n\t\tfresh = -3,\n\t\t\n\t\t/** State will never be changed. */\n\t\tfinal = -4,\n\t\t\n\t}\n\t\n}\n","namespace $ {\n\t\n\t/**\n\t * Collects subscribers in compact array. 28B\n\t */\n\texport class $mol_wire_pub extends Object {\n\t\t\n\t\tconstructor( id = `$mol_wire_pub:${ $mol_guid() }` ) {\n\t\t\tsuper()\n\t\t\tthis[ Symbol.toStringTag ] = id\n\t\t}\n\t\t\n\t\t[ Symbol.toStringTag ]!: string\n\t\tdata = [] as unknown[]\n\t\t\n\t\t// Derived objects should be Arrays.\n\t\tstatic get [ Symbol.species ]() {\n\t\t\treturn Array\n\t\t}\n\t\t\n\t\t/**\n\t\t * Index of first subscriber.\n\t\t */\n\t\tprotected sub_from = 0 // 4B\n\t\t\n\t\t/**\n\t\t * All current subscribers.\n\t\t */\n\t\tget sub_list() {\n\t\t\tconst res = [] as $mol_wire_sub[]\n\t\t\tfor( let i = this.sub_from; i < this.data.length; i += 2 ) {\n\t\t\t\tres.push( this.data[i] as $mol_wire_sub )\n\t\t\t}\n\t\t\treturn res as readonly $mol_wire_sub[]\n\t\t}\n\t\t\n\t\t/**\n\t\t * Has any subscribers or not.\n\t\t */\n\t\tget sub_empty() {\n\t\t\treturn this.sub_from === this.data.length\n\t\t}\n\t\t\n\t\t/**\n\t\t * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.\n\t\t */\n\t\tsub_on( sub: $mol_wire_pub, pub_pos: number ) {\n\t\t\tconst pos = this.data.length\n\t\t\tthis.data.push( sub, pub_pos )\n\t\t\treturn pos\n\t\t}\n\t\t\n\t\t/**\n\t\t * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.\n\t\t */\n\t\tsub_off( sub_pos: number ) {\n\t\t\t\n\t\t\tif(!( sub_pos < this.data.length )) {\n\t\t\t\t$mol_fail( new Error( `Wrong pos ${ sub_pos }` ) )\n\t\t\t}\n\t\t\t\n\t\t\tconst end = this.data.length - 2\n\t\t\tif( sub_pos !== end ) {\n\t\t\t\tthis.peer_move( end, sub_pos )\n\t\t\t}\n\t\t\t\n\t\t\tthis.data.length = end\n\t\t\t\n\t\t\tif( end === this.sub_from ) this.reap()\n\t\t\t\n\t\t}\n\t\t\n\t\t/**\n\t\t * Called when last sub was unsubscribed.\n\t\t **/\n\t\treap() { }\n\t\t\n\t\t/**\n\t\t * Autowire this publisher with current subscriber.\n\t\t **/\n\t\tpromote() {\n\t\t\t$mol_wire_auto()?.track_next( this )\n\t\t}\n\t\t\n\t\t/**\n\t\t * Enforce actualization. Should not throw errors.\n\t\t */\n\t\tfresh() {}\n\t\t\n\t\t/**\n\t\t * Allow to put data to caches in the subtree.\n\t\t */\n\t\tcomplete() {}\n\t\t\n\t\tget incompleted() {\n\t\t\treturn false\n\t\t}\n\t\t\n\t\t/**\n\t\t * Notify subscribers about self changes.\n\t\t */\n\t\temit( quant = $mol_wire_cursor.stale ) {\n\t\t\tfor( let i = this.sub_from; i < this.data.length; i += 2 ) {\n\t\t\t\t;( this.data[i] as $mol_wire_sub ).absorb( quant, this.data[ i + 1 ] as number )\n\t\t\t}\n\t\t}\n\t\t\n\t\t/**\n\t\t * Moves peer from one position to another. Doesn't clear data at old position!\n\t\t */\n\t\tpeer_move( from_pos: number, to_pos: number ) {\n\t\t\t\n\t\t\tconst peer = this.data[ from_pos ] as $mol_wire_pub\n\t\t\tconst self_pos = this.data[ from_pos + 1 ] as number\n\t\t\t\n\t\t\tthis.data[ to_pos ] = peer\n\t\t\tthis.data[ to_pos + 1 ] = self_pos\n\t\t\t\n\t\t\tpeer.peer_repos( self_pos, to_pos )\n\t\t}\n\t\t\n\t\t/**\n\t\t * Updates self position in the peer.\n\t\t */\n\t\tpeer_repos( peer_pos: number, self_pos: number ) {\n\t\t\tthis.data[ peer_pos + 1 ] = self_pos\n\t\t}\n\t\t\n\t}\n\t\n}\n","namespace $ {\n\t\n\texport let $mol_wire_auto_sub: $mol_wire_sub | null = null\n\t\n\t/**\n\t * When fulfilled, all publishers are promoted to this subscriber on access to its.\n\t */\n\texport function $mol_wire_auto( next = $mol_wire_auto_sub ) {\n\t\treturn $mol_wire_auto_sub = next\n\t}\n\t\n\t/**\n\t * Affection queue. Used to prevent accidental stack overflow on emit.\n\t */\n\texport const $mol_wire_affected = [] as ( $mol_wire_sub | number )[]\n\t\n}\n"]}
|
package/package.json
CHANGED
package/web.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare namespace $ {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
declare namespace $ {
|
|
18
|
+
/** Generates unique identifier. */
|
|
18
19
|
function $mol_guid(length?: number, exists?: (id: string) => boolean): string;
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -23,53 +24,125 @@ declare namespace $ {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
declare namespace $ {
|
|
27
|
+
/** Special status statuses. */
|
|
26
28
|
enum $mol_wire_cursor {
|
|
29
|
+
/** Update required. */
|
|
27
30
|
stale = -1,
|
|
31
|
+
/** Some of (transitive) pub update required. */
|
|
28
32
|
doubt = -2,
|
|
33
|
+
/** Actual state but may be dropped. */
|
|
29
34
|
fresh = -3,
|
|
35
|
+
/** State will never be changed. */
|
|
30
36
|
final = -4
|
|
31
37
|
}
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
declare namespace $ {
|
|
41
|
+
/**
|
|
42
|
+
* Collects subscribers in compact array. 28B
|
|
43
|
+
*/
|
|
35
44
|
class $mol_wire_pub extends Object {
|
|
36
45
|
constructor(id?: string);
|
|
37
46
|
[Symbol.toStringTag]: string;
|
|
38
47
|
data: unknown[];
|
|
39
48
|
static get [Symbol.species](): ArrayConstructor;
|
|
49
|
+
/**
|
|
50
|
+
* Index of first subscriber.
|
|
51
|
+
*/
|
|
40
52
|
protected sub_from: number;
|
|
53
|
+
/**
|
|
54
|
+
* All current subscribers.
|
|
55
|
+
*/
|
|
41
56
|
get sub_list(): readonly $mol_wire_sub[];
|
|
57
|
+
/**
|
|
58
|
+
* Has any subscribers or not.
|
|
59
|
+
*/
|
|
42
60
|
get sub_empty(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
63
|
+
*/
|
|
43
64
|
sub_on(sub: $mol_wire_pub, pub_pos: number): number;
|
|
65
|
+
/**
|
|
66
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
67
|
+
*/
|
|
44
68
|
sub_off(sub_pos: number): void;
|
|
69
|
+
/**
|
|
70
|
+
* Called when last sub was unsubscribed.
|
|
71
|
+
**/
|
|
45
72
|
reap(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Autowire this publisher with current subscriber.
|
|
75
|
+
**/
|
|
46
76
|
promote(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Enforce actualization. Should not throw errors.
|
|
79
|
+
*/
|
|
47
80
|
fresh(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Allow to put data to caches in the subtree.
|
|
83
|
+
*/
|
|
48
84
|
complete(): void;
|
|
49
85
|
get incompleted(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Notify subscribers about self changes.
|
|
88
|
+
*/
|
|
50
89
|
emit(quant?: $mol_wire_cursor): void;
|
|
90
|
+
/**
|
|
91
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
92
|
+
*/
|
|
51
93
|
peer_move(from_pos: number, to_pos: number): void;
|
|
94
|
+
/**
|
|
95
|
+
* Updates self position in the peer.
|
|
96
|
+
*/
|
|
52
97
|
peer_repos(peer_pos: number, self_pos: number): void;
|
|
53
98
|
}
|
|
54
99
|
}
|
|
55
100
|
|
|
56
101
|
declare namespace $ {
|
|
102
|
+
/** Generic subscriber interface */
|
|
57
103
|
interface $mol_wire_sub extends $mol_wire_pub {
|
|
58
104
|
temp: boolean;
|
|
59
105
|
pub_list: $mol_wire_pub[];
|
|
106
|
+
/**
|
|
107
|
+
* Begin auto wire to publishers.
|
|
108
|
+
* Returns previous auto subscriber that must me transfer to the `end`.
|
|
109
|
+
*/
|
|
60
110
|
track_on(): $mol_wire_sub | null;
|
|
111
|
+
/**
|
|
112
|
+
* Returns next auto wired publisher. It can be easely repormoted.
|
|
113
|
+
* Or promotes next publisher to auto wire its togeter.
|
|
114
|
+
* Must be used only between `track_on` and `track_off`.
|
|
115
|
+
*/
|
|
61
116
|
track_next(pub?: $mol_wire_pub): $mol_wire_pub | null;
|
|
62
117
|
pub_off(pub_pos: number): void;
|
|
118
|
+
/**
|
|
119
|
+
* Unsubscribes from unpromoted publishers.
|
|
120
|
+
*/
|
|
63
121
|
track_cut(sub: $mol_wire_pub | null): void;
|
|
122
|
+
/**
|
|
123
|
+
* Ends auto wire to publishers.
|
|
124
|
+
*/
|
|
64
125
|
track_off(sub: $mol_wire_pub | null): void;
|
|
126
|
+
/**
|
|
127
|
+
* Receive notification about publisher changes.
|
|
128
|
+
*/
|
|
65
129
|
absorb(quant: $mol_wire_cursor, pos: number): void;
|
|
130
|
+
/**
|
|
131
|
+
* Unsubscribes from all publishers.
|
|
132
|
+
*/
|
|
66
133
|
destructor(): void;
|
|
67
134
|
}
|
|
68
135
|
}
|
|
69
136
|
|
|
70
137
|
declare namespace $ {
|
|
71
138
|
let $mol_wire_auto_sub: $mol_wire_sub | null;
|
|
139
|
+
/**
|
|
140
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
141
|
+
*/
|
|
72
142
|
function $mol_wire_auto(next?: $mol_wire_sub | null): $mol_wire_sub | null;
|
|
143
|
+
/**
|
|
144
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
145
|
+
*/
|
|
73
146
|
const $mol_wire_affected: ($mol_wire_sub | number)[];
|
|
74
147
|
}
|
|
75
148
|
|
package/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../mam.d.ts","../../../guid/guid.d.ts","../../../fail/fail.d.ts","../../cursor/cursor.d.ts","../pub.d.ts","../../sub/sub.d.ts","../../wire.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACfA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["../../../../mam.d.ts","../../../guid/guid.d.ts","../../../fail/fail.d.ts","../../cursor/cursor.d.ts","../pub.d.ts","../../sub/sub.d.ts","../../wire.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACfA;AACA;AACA;AACA;AACA;ACJA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AC5DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourcesContent":[null,null,null,null,null,null,null]}
|
package/web.js
CHANGED
|
@@ -32,6 +32,7 @@ $.$$ = $
|
|
|
32
32
|
"use strict";
|
|
33
33
|
var $;
|
|
34
34
|
(function ($) {
|
|
35
|
+
/** Generates unique identifier. */
|
|
35
36
|
function $mol_guid(length = 8, exists = () => false) {
|
|
36
37
|
for (;;) {
|
|
37
38
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -57,11 +58,16 @@ var $;
|
|
|
57
58
|
"use strict";
|
|
58
59
|
var $;
|
|
59
60
|
(function ($) {
|
|
61
|
+
/** Special status statuses. */
|
|
60
62
|
let $mol_wire_cursor;
|
|
61
63
|
(function ($mol_wire_cursor) {
|
|
64
|
+
/** Update required. */
|
|
62
65
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
66
|
+
/** Some of (transitive) pub update required. */
|
|
63
67
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
68
|
+
/** Actual state but may be dropped. */
|
|
64
69
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
70
|
+
/** State will never be changed. */
|
|
65
71
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
66
72
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
67
73
|
})($ || ($ = {}));
|
|
@@ -70,6 +76,9 @@ var $;
|
|
|
70
76
|
"use strict";
|
|
71
77
|
var $;
|
|
72
78
|
(function ($) {
|
|
79
|
+
/**
|
|
80
|
+
* Collects subscribers in compact array. 28B
|
|
81
|
+
*/
|
|
73
82
|
class $mol_wire_pub extends Object {
|
|
74
83
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
75
84
|
super();
|
|
@@ -77,10 +86,17 @@ var $;
|
|
|
77
86
|
}
|
|
78
87
|
[Symbol.toStringTag];
|
|
79
88
|
data = [];
|
|
89
|
+
// Derived objects should be Arrays.
|
|
80
90
|
static get [Symbol.species]() {
|
|
81
91
|
return Array;
|
|
82
92
|
}
|
|
83
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Index of first subscriber.
|
|
95
|
+
*/
|
|
96
|
+
sub_from = 0; // 4B
|
|
97
|
+
/**
|
|
98
|
+
* All current subscribers.
|
|
99
|
+
*/
|
|
84
100
|
get sub_list() {
|
|
85
101
|
const res = [];
|
|
86
102
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -88,14 +104,23 @@ var $;
|
|
|
88
104
|
}
|
|
89
105
|
return res;
|
|
90
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Has any subscribers or not.
|
|
109
|
+
*/
|
|
91
110
|
get sub_empty() {
|
|
92
111
|
return this.sub_from === this.data.length;
|
|
93
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
115
|
+
*/
|
|
94
116
|
sub_on(sub, pub_pos) {
|
|
95
117
|
const pos = this.data.length;
|
|
96
118
|
this.data.push(sub, pub_pos);
|
|
97
119
|
return pos;
|
|
98
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
123
|
+
*/
|
|
99
124
|
sub_off(sub_pos) {
|
|
100
125
|
if (!(sub_pos < this.data.length)) {
|
|
101
126
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -108,21 +133,39 @@ var $;
|
|
|
108
133
|
if (end === this.sub_from)
|
|
109
134
|
this.reap();
|
|
110
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Called when last sub was unsubscribed.
|
|
138
|
+
**/
|
|
111
139
|
reap() { }
|
|
140
|
+
/**
|
|
141
|
+
* Autowire this publisher with current subscriber.
|
|
142
|
+
**/
|
|
112
143
|
promote() {
|
|
113
144
|
$mol_wire_auto()?.track_next(this);
|
|
114
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Enforce actualization. Should not throw errors.
|
|
148
|
+
*/
|
|
115
149
|
fresh() { }
|
|
150
|
+
/**
|
|
151
|
+
* Allow to put data to caches in the subtree.
|
|
152
|
+
*/
|
|
116
153
|
complete() { }
|
|
117
154
|
get incompleted() {
|
|
118
155
|
return false;
|
|
119
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Notify subscribers about self changes.
|
|
159
|
+
*/
|
|
120
160
|
emit(quant = $mol_wire_cursor.stale) {
|
|
121
161
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
122
162
|
;
|
|
123
163
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
124
164
|
}
|
|
125
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
168
|
+
*/
|
|
126
169
|
peer_move(from_pos, to_pos) {
|
|
127
170
|
const peer = this.data[from_pos];
|
|
128
171
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -130,6 +173,9 @@ var $;
|
|
|
130
173
|
this.data[to_pos + 1] = self_pos;
|
|
131
174
|
peer.peer_repos(self_pos, to_pos);
|
|
132
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Updates self position in the peer.
|
|
178
|
+
*/
|
|
133
179
|
peer_repos(peer_pos, self_pos) {
|
|
134
180
|
this.data[peer_pos + 1] = self_pos;
|
|
135
181
|
}
|
|
@@ -145,10 +191,16 @@ var $;
|
|
|
145
191
|
var $;
|
|
146
192
|
(function ($) {
|
|
147
193
|
$.$mol_wire_auto_sub = null;
|
|
194
|
+
/**
|
|
195
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
196
|
+
*/
|
|
148
197
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
149
198
|
return $.$mol_wire_auto_sub = next;
|
|
150
199
|
}
|
|
151
200
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
201
|
+
/**
|
|
202
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
203
|
+
*/
|
|
152
204
|
$.$mol_wire_affected = [];
|
|
153
205
|
})($ || ($ = {}));
|
|
154
206
|
|
package/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["-","../../../../mam.ts","../../../../mol/guid/guid.ts","../../../../mol/fail/fail.ts","../../../../mol/wire/cursor/cursor.ts","../../../../mol/wire/pub/pub.ts","../../../../mol/wire/wire.ts"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;AAK3B,IAAU,CAAC,CAQV;AARD,WAAU,CAAC;AAQX,CAAC,EARS,CAAC,KAAD,CAAC,QAQV;AAED,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;;;ADflB;AACA;AACA;;;;;;;;;;;;;;;AEFA,IAAU,CAAC,CAkBV;AAlBD,WAAU,CAAC;
|
|
1
|
+
{"version":3,"sources":["-","../../../../mam.ts","../../../../mol/guid/guid.ts","../../../../mol/fail/fail.ts","../../../../mol/wire/cursor/cursor.ts","../../../../mol/wire/pub/pub.ts","../../../../mol/wire/wire.ts"],"names":[],"mappings":";;;AAAA;AACA;AACA;AACA;;ACHA,KAAK,CAAC,eAAe,GAAG,EAAE,CAAC;A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E,GAAG,IAAI,CAAA;YAC1B,IAAI,CAAC,IAAI,CAAE,MAAM,GAAG,CAAC,CAAE,GAAG,QAAQ,CAAA;YAElC,IAAI,CAAC,UAAU,CAAE,QAAQ,EAAE,MAAM,CAAE,CAAA;QACpC,CAAC;QAED;;WAEG;QACH,UAAU,CAAE,QAAgB,EAAE,QAAgB;YAC7C,IAAI,CAAC,IAAI,CAAE,QAAQ,GAAG,CAAC,CAAE,GAAG,QAAQ,CAAA;QACrC,CAAC;KAED;IA3HY,eAAa,gBA2HzB,CAAA;AAEF,CAAC,EAlIS,CAAC,KAAD,CAAC,QAkIV;;;;;;;AClID,IAAU,CAAC,CAgBV;AAhBD,WAAU,CAAC;IAEC,oBAAkB,GAAyB,IAAI,CAAA;IAE1D;;OAEG;IACH,SAAgB,cAAc,CAAE,IAAI,GAAG,EAAA,kBAAkB;QACxD,OAAO,EAAA,kBAAkB,GAAG,IAAI,CAAA;IACjC,CAAC;IAFe,gBAAc,iBAE7B,CAAA;IAED;;OAEG;IACU,oBAAkB,GAAG,EAAkC,CAAA;AAErE,CAAC,EAhBS,CAAC,KAAD,CAAC,QAgBV;;","sourcesContent":[null,"Error.stackTraceLimit = 50;\n\ndeclare let _$_: { new(): {} } & typeof globalThis\ndeclare class $ extends _$_ {}\n\nnamespace $ {\n\texport type $ = typeof $$\n\texport declare class $$ extends $ {\n\t\tstatic $: $\n\t}\n\tnamespace $$ {\n\t\texport type $$ = $\n\t}\n}\n\nmodule.exports = $\n","namespace $ {\n\n\t/** Generates unique identifier. */\n\texport function $mol_guid(\n\t\tlength = 8,\n\t\texists: ( id: string )=> boolean = ()=> false,\n\t) {\n\n\t\tfor(;;) {\n\n\t\t\tlet id = Math.random().toString( 36 ).substring( 2, length + 2 ).toUpperCase()\n\t\t\tif( exists( id ) ) continue\n\t\t\t\n\t\t\treturn id\n\t\t}\n\n\t}\n\n}\n","namespace $ {\n\n\texport function $mol_fail( error : any ) : never {\n\t\tthrow error\n\t}\n\n}\n","namespace $ {\n\t\n\t/** Special status statuses. */\n\texport enum $mol_wire_cursor {\n\t\t\n\t\t/** Update required. */\n\t\tstale = -1,\n\t\t\n\t\t/** Some of (transitive) pub update required. */\n\t\tdoubt = -2,\n\t\t\n\t\t/** Actual state but may be dropped. */\n\t\tfresh = -3,\n\t\t\n\t\t/** State will never be changed. */\n\t\tfinal = -4,\n\t\t\n\t}\n\t\n}\n","namespace $ {\n\t\n\t/**\n\t * Collects subscribers in compact array. 28B\n\t */\n\texport class $mol_wire_pub extends Object {\n\t\t\n\t\tconstructor( id = `$mol_wire_pub:${ $mol_guid() }` ) {\n\t\t\tsuper()\n\t\t\tthis[ Symbol.toStringTag ] = id\n\t\t}\n\t\t\n\t\t[ Symbol.toStringTag ]!: string\n\t\tdata = [] as unknown[]\n\t\t\n\t\t// Derived objects should be Arrays.\n\t\tstatic get [ Symbol.species ]() {\n\t\t\treturn Array\n\t\t}\n\t\t\n\t\t/**\n\t\t * Index of first subscriber.\n\t\t */\n\t\tprotected sub_from = 0 // 4B\n\t\t\n\t\t/**\n\t\t * All current subscribers.\n\t\t */\n\t\tget sub_list() {\n\t\t\tconst res = [] as $mol_wire_sub[]\n\t\t\tfor( let i = this.sub_from; i < this.data.length; i += 2 ) {\n\t\t\t\tres.push( this.data[i] as $mol_wire_sub )\n\t\t\t}\n\t\t\treturn res as readonly $mol_wire_sub[]\n\t\t}\n\t\t\n\t\t/**\n\t\t * Has any subscribers or not.\n\t\t */\n\t\tget sub_empty() {\n\t\t\treturn this.sub_from === this.data.length\n\t\t}\n\t\t\n\t\t/**\n\t\t * Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.\n\t\t */\n\t\tsub_on( sub: $mol_wire_pub, pub_pos: number ) {\n\t\t\tconst pos = this.data.length\n\t\t\tthis.data.push( sub, pub_pos )\n\t\t\treturn pos\n\t\t}\n\t\t\n\t\t/**\n\t\t * Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.\n\t\t */\n\t\tsub_off( sub_pos: number ) {\n\t\t\t\n\t\t\tif(!( sub_pos < this.data.length )) {\n\t\t\t\t$mol_fail( new Error( `Wrong pos ${ sub_pos }` ) )\n\t\t\t}\n\t\t\t\n\t\t\tconst end = this.data.length - 2\n\t\t\tif( sub_pos !== end ) {\n\t\t\t\tthis.peer_move( end, sub_pos )\n\t\t\t}\n\t\t\t\n\t\t\tthis.data.length = end\n\t\t\t\n\t\t\tif( end === this.sub_from ) this.reap()\n\t\t\t\n\t\t}\n\t\t\n\t\t/**\n\t\t * Called when last sub was unsubscribed.\n\t\t **/\n\t\treap() { }\n\t\t\n\t\t/**\n\t\t * Autowire this publisher with current subscriber.\n\t\t **/\n\t\tpromote() {\n\t\t\t$mol_wire_auto()?.track_next( this )\n\t\t}\n\t\t\n\t\t/**\n\t\t * Enforce actualization. Should not throw errors.\n\t\t */\n\t\tfresh() {}\n\t\t\n\t\t/**\n\t\t * Allow to put data to caches in the subtree.\n\t\t */\n\t\tcomplete() {}\n\t\t\n\t\tget incompleted() {\n\t\t\treturn false\n\t\t}\n\t\t\n\t\t/**\n\t\t * Notify subscribers about self changes.\n\t\t */\n\t\temit( quant = $mol_wire_cursor.stale ) {\n\t\t\tfor( let i = this.sub_from; i < this.data.length; i += 2 ) {\n\t\t\t\t;( this.data[i] as $mol_wire_sub ).absorb( quant, this.data[ i + 1 ] as number )\n\t\t\t}\n\t\t}\n\t\t\n\t\t/**\n\t\t * Moves peer from one position to another. Doesn't clear data at old position!\n\t\t */\n\t\tpeer_move( from_pos: number, to_pos: number ) {\n\t\t\t\n\t\t\tconst peer = this.data[ from_pos ] as $mol_wire_pub\n\t\t\tconst self_pos = this.data[ from_pos + 1 ] as number\n\t\t\t\n\t\t\tthis.data[ to_pos ] = peer\n\t\t\tthis.data[ to_pos + 1 ] = self_pos\n\t\t\t\n\t\t\tpeer.peer_repos( self_pos, to_pos )\n\t\t}\n\t\t\n\t\t/**\n\t\t * Updates self position in the peer.\n\t\t */\n\t\tpeer_repos( peer_pos: number, self_pos: number ) {\n\t\t\tthis.data[ peer_pos + 1 ] = self_pos\n\t\t}\n\t\t\n\t}\n\t\n}\n","namespace $ {\n\t\n\texport let $mol_wire_auto_sub: $mol_wire_sub | null = null\n\t\n\t/**\n\t * When fulfilled, all publishers are promoted to this subscriber on access to its.\n\t */\n\texport function $mol_wire_auto( next = $mol_wire_auto_sub ) {\n\t\treturn $mol_wire_auto_sub = next\n\t}\n\t\n\t/**\n\t * Affection queue. Used to prevent accidental stack overflow on emit.\n\t */\n\texport const $mol_wire_affected = [] as ( $mol_wire_sub | number )[]\n\t\n}\n"]}
|
package/web.mjs
CHANGED
|
@@ -32,6 +32,7 @@ $.$$ = $
|
|
|
32
32
|
"use strict";
|
|
33
33
|
var $;
|
|
34
34
|
(function ($) {
|
|
35
|
+
/** Generates unique identifier. */
|
|
35
36
|
function $mol_guid(length = 8, exists = () => false) {
|
|
36
37
|
for (;;) {
|
|
37
38
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -57,11 +58,16 @@ var $;
|
|
|
57
58
|
"use strict";
|
|
58
59
|
var $;
|
|
59
60
|
(function ($) {
|
|
61
|
+
/** Special status statuses. */
|
|
60
62
|
let $mol_wire_cursor;
|
|
61
63
|
(function ($mol_wire_cursor) {
|
|
64
|
+
/** Update required. */
|
|
62
65
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
66
|
+
/** Some of (transitive) pub update required. */
|
|
63
67
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
68
|
+
/** Actual state but may be dropped. */
|
|
64
69
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
70
|
+
/** State will never be changed. */
|
|
65
71
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
66
72
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
67
73
|
})($ || ($ = {}));
|
|
@@ -70,6 +76,9 @@ var $;
|
|
|
70
76
|
"use strict";
|
|
71
77
|
var $;
|
|
72
78
|
(function ($) {
|
|
79
|
+
/**
|
|
80
|
+
* Collects subscribers in compact array. 28B
|
|
81
|
+
*/
|
|
73
82
|
class $mol_wire_pub extends Object {
|
|
74
83
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
75
84
|
super();
|
|
@@ -77,10 +86,17 @@ var $;
|
|
|
77
86
|
}
|
|
78
87
|
[Symbol.toStringTag];
|
|
79
88
|
data = [];
|
|
89
|
+
// Derived objects should be Arrays.
|
|
80
90
|
static get [Symbol.species]() {
|
|
81
91
|
return Array;
|
|
82
92
|
}
|
|
83
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Index of first subscriber.
|
|
95
|
+
*/
|
|
96
|
+
sub_from = 0; // 4B
|
|
97
|
+
/**
|
|
98
|
+
* All current subscribers.
|
|
99
|
+
*/
|
|
84
100
|
get sub_list() {
|
|
85
101
|
const res = [];
|
|
86
102
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -88,14 +104,23 @@ var $;
|
|
|
88
104
|
}
|
|
89
105
|
return res;
|
|
90
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Has any subscribers or not.
|
|
109
|
+
*/
|
|
91
110
|
get sub_empty() {
|
|
92
111
|
return this.sub_from === this.data.length;
|
|
93
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
115
|
+
*/
|
|
94
116
|
sub_on(sub, pub_pos) {
|
|
95
117
|
const pos = this.data.length;
|
|
96
118
|
this.data.push(sub, pub_pos);
|
|
97
119
|
return pos;
|
|
98
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
123
|
+
*/
|
|
99
124
|
sub_off(sub_pos) {
|
|
100
125
|
if (!(sub_pos < this.data.length)) {
|
|
101
126
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -108,21 +133,39 @@ var $;
|
|
|
108
133
|
if (end === this.sub_from)
|
|
109
134
|
this.reap();
|
|
110
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Called when last sub was unsubscribed.
|
|
138
|
+
**/
|
|
111
139
|
reap() { }
|
|
140
|
+
/**
|
|
141
|
+
* Autowire this publisher with current subscriber.
|
|
142
|
+
**/
|
|
112
143
|
promote() {
|
|
113
144
|
$mol_wire_auto()?.track_next(this);
|
|
114
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Enforce actualization. Should not throw errors.
|
|
148
|
+
*/
|
|
115
149
|
fresh() { }
|
|
150
|
+
/**
|
|
151
|
+
* Allow to put data to caches in the subtree.
|
|
152
|
+
*/
|
|
116
153
|
complete() { }
|
|
117
154
|
get incompleted() {
|
|
118
155
|
return false;
|
|
119
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Notify subscribers about self changes.
|
|
159
|
+
*/
|
|
120
160
|
emit(quant = $mol_wire_cursor.stale) {
|
|
121
161
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
122
162
|
;
|
|
123
163
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
124
164
|
}
|
|
125
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
168
|
+
*/
|
|
126
169
|
peer_move(from_pos, to_pos) {
|
|
127
170
|
const peer = this.data[from_pos];
|
|
128
171
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -130,6 +173,9 @@ var $;
|
|
|
130
173
|
this.data[to_pos + 1] = self_pos;
|
|
131
174
|
peer.peer_repos(self_pos, to_pos);
|
|
132
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Updates self position in the peer.
|
|
178
|
+
*/
|
|
133
179
|
peer_repos(peer_pos, self_pos) {
|
|
134
180
|
this.data[peer_pos + 1] = self_pos;
|
|
135
181
|
}
|
|
@@ -145,10 +191,16 @@ var $;
|
|
|
145
191
|
var $;
|
|
146
192
|
(function ($) {
|
|
147
193
|
$.$mol_wire_auto_sub = null;
|
|
194
|
+
/**
|
|
195
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
196
|
+
*/
|
|
148
197
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
149
198
|
return $.$mol_wire_auto_sub = next;
|
|
150
199
|
}
|
|
151
200
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
201
|
+
/**
|
|
202
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
203
|
+
*/
|
|
152
204
|
$.$mol_wire_affected = [];
|
|
153
205
|
})($ || ($ = {}));
|
|
154
206
|
|