@remote-ui/core
Advanced tools
Comparing version
@@ -39,2 +39,4 @@ "use strict"; | ||
require("core-js/modules/es.set"); | ||
require("core-js/modules/es.string.iterator"); | ||
@@ -46,2 +48,4 @@ | ||
require("core-js/modules/web.timers"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -99,2 +103,3 @@ value: true | ||
this.attached = new Map([[ROOT_ID, this.root]]); | ||
this.queuedUpdates = new Set(); | ||
this.listeners = new Map(); | ||
@@ -138,8 +143,4 @@ | ||
var listener = _this.listeners.get(ROOT_ID); | ||
_this.enqueueUpdate(_this.root); | ||
if (listener) { | ||
listener(_this.root); | ||
} | ||
break; | ||
@@ -170,8 +171,4 @@ } | ||
var _listener = _this.listeners.get(id); | ||
_this.enqueueUpdate(_this.root); | ||
if (_listener) { | ||
_listener(attached); | ||
} | ||
break; | ||
@@ -205,8 +202,4 @@ } | ||
var _listener2 = _this.listeners.get(_id); | ||
_this.enqueueUpdate(_attached); | ||
if (_listener2) { | ||
_listener2(_attached); | ||
} | ||
break; | ||
@@ -236,8 +229,4 @@ } | ||
var _listener3 = _this.listeners.get(_id2); | ||
_this.enqueueUpdate(component); | ||
if (_listener3) { | ||
_listener3(component); | ||
} | ||
break; | ||
@@ -257,6 +246,6 @@ } | ||
var _listener4 = _this.listeners.get(_id3); | ||
var listener = _this.listeners.get(_id3); | ||
if (_listener4) { | ||
_listener4(text); | ||
if (listener) { | ||
listener(text); | ||
} | ||
@@ -284,2 +273,46 @@ | ||
}, { | ||
key: "enqueueUpdate", | ||
value: function enqueueUpdate(attached) { | ||
var _this3 = this; | ||
if (this.timeout == null) { | ||
this.timeout = setTimeout(function () { | ||
var queuedUpdates = _toConsumableArray(_this3.queuedUpdates); | ||
_this3.timeout = null; | ||
_this3.queuedUpdates.clear(); | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = queuedUpdates[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _attached2 = _step2.value; | ||
var listener = _this3.listeners.get(_attached2 === _this3.root ? ROOT_ID : _attached2.id); | ||
listener === null || listener === void 0 ? void 0 : listener(_attached2); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
}, 0); | ||
} | ||
this.queuedUpdates.add(attached); | ||
} | ||
}, { | ||
key: "attach", | ||
@@ -290,22 +323,22 @@ value: function attach(child) { | ||
if ('children' in child) { | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator2 = child.children[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var grandChild = _step2.value; | ||
for (var _iterator3 = child.children[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var grandChild = _step3.value; | ||
this.attach(grandChild); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) { | ||
_iterator3["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
@@ -322,22 +355,22 @@ } | ||
if ('children' in child) { | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
try { | ||
for (var _iterator3 = child.children[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var grandChild = _step3.value; | ||
for (var _iterator4 = child.children[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var grandChild = _step4.value; | ||
this.detach(grandChild); | ||
} | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) { | ||
_iterator3["return"](); | ||
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) { | ||
_iterator4["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
} | ||
@@ -344,0 +377,0 @@ } |
@@ -21,2 +21,3 @@ "use strict"; | ||
this.attached = new Map([[ROOT_ID, this.root]]); | ||
this.queuedUpdates = new Set(); | ||
this.listeners = new Map(); | ||
@@ -36,8 +37,3 @@ | ||
const listener = this.listeners.get(ROOT_ID); | ||
if (listener) { | ||
listener(this.root); | ||
} | ||
this.enqueueUpdate(this.root); | ||
break; | ||
@@ -55,8 +51,3 @@ } | ||
attached.children = children; | ||
const listener = this.listeners.get(id); | ||
if (listener) { | ||
listener(attached); | ||
} | ||
this.enqueueUpdate(this.root); | ||
break; | ||
@@ -80,8 +71,3 @@ } | ||
attached.children = children; | ||
const listener = this.listeners.get(id); | ||
if (listener) { | ||
listener(attached); | ||
} | ||
this.enqueueUpdate(attached); | ||
break; | ||
@@ -107,8 +93,3 @@ } | ||
component.props = props; | ||
const listener = this.listeners.get(id); | ||
if (listener) { | ||
listener(component); | ||
} | ||
this.enqueueUpdate(component); | ||
break; | ||
@@ -145,2 +126,19 @@ } | ||
enqueueUpdate(attached) { | ||
if (this.timeout == null) { | ||
this.timeout = setTimeout(() => { | ||
const queuedUpdates = [...this.queuedUpdates]; | ||
this.timeout = null; | ||
this.queuedUpdates.clear(); | ||
for (const attached of queuedUpdates) { | ||
const listener = this.listeners.get(attached === this.root ? ROOT_ID : attached.id); | ||
listener === null || listener === void 0 ? void 0 : listener(attached); | ||
} | ||
}, 0); | ||
} | ||
this.queuedUpdates.add(attached); | ||
} | ||
attach(child) { | ||
@@ -147,0 +145,0 @@ this.attached.set(child.id, child); |
@@ -13,5 +13,8 @@ import { Dispatch, RemoteTextSerialization, RemoteComponentSerialization } from './types'; | ||
private attached; | ||
private timeout; | ||
private queuedUpdates; | ||
private readonly listeners; | ||
readonly dispatch: Dispatch; | ||
on<T extends Attachable>({ id }: T, listener: UpdateListener<T>): () => void; | ||
private enqueueUpdate; | ||
private attach; | ||
@@ -18,0 +21,0 @@ private detach; |
@@ -12,2 +12,3 @@ "use strict"; | ||
]); | ||
this.queuedUpdates = new Set(); | ||
this.listeners = new Map(); | ||
@@ -23,6 +24,3 @@ this.dispatch = (type, ...args) => { | ||
} | ||
const listener = this.listeners.get(ROOT_ID); | ||
if (listener) { | ||
listener(this.root); | ||
} | ||
this.enqueueUpdate(this.root); | ||
break; | ||
@@ -38,6 +36,3 @@ } | ||
attached.children = children; | ||
const listener = this.listeners.get(id); | ||
if (listener) { | ||
listener(attached); | ||
} | ||
this.enqueueUpdate(this.root); | ||
break; | ||
@@ -58,6 +53,3 @@ } | ||
attached.children = children; | ||
const listener = this.listeners.get(id); | ||
if (listener) { | ||
listener(attached); | ||
} | ||
this.enqueueUpdate(attached); | ||
break; | ||
@@ -75,6 +67,3 @@ } | ||
component.props = props; | ||
const listener = this.listeners.get(id); | ||
if (listener) { | ||
listener(component); | ||
} | ||
this.enqueueUpdate(component); | ||
break; | ||
@@ -103,2 +92,17 @@ } | ||
} | ||
enqueueUpdate(attached) { | ||
if (this.timeout == null) { | ||
this.timeout = setTimeout(() => { | ||
var _a; | ||
const queuedUpdates = [...this.queuedUpdates]; | ||
this.timeout = null; | ||
this.queuedUpdates.clear(); | ||
for (const attached of queuedUpdates) { | ||
const listener = this.listeners.get(attached === this.root ? ROOT_ID : attached.id); | ||
(_a = listener) === null || _a === void 0 ? void 0 : _a(attached); | ||
} | ||
}, 0); | ||
} | ||
this.queuedUpdates.add(attached); | ||
} | ||
attach(child) { | ||
@@ -105,0 +109,0 @@ this.attached.set(child.id, child); |
{ | ||
"name": "@remote-ui/core", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"publishConfig": { | ||
@@ -13,3 +13,3 @@ "access": "public", | ||
}, | ||
"gitHead": "da58c9b3754eaef09fa623f9c5a75784e6c69ddd" | ||
"gitHead": "4c8a98663c7a2144c22698090fb9ffc50fdafa51" | ||
} |
@@ -29,2 +29,5 @@ import {retain, release} from 'remote-call'; | ||
private timeout: any; | ||
private queuedUpdates = new Set<Attachable>(); | ||
private readonly listeners = new Map< | ||
@@ -47,8 +50,4 @@ string | typeof ROOT_ID, | ||
const listener = this.listeners.get(ROOT_ID); | ||
this.enqueueUpdate(this.root); | ||
if (listener) { | ||
listener(this.root); | ||
} | ||
break; | ||
@@ -67,8 +66,4 @@ } | ||
const listener = this.listeners.get(id); | ||
this.enqueueUpdate(this.root); | ||
if (listener) { | ||
listener(attached); | ||
} | ||
break; | ||
@@ -96,8 +91,4 @@ } | ||
const listener = this.listeners.get(id); | ||
this.enqueueUpdate(attached); | ||
if (listener) { | ||
listener(attached); | ||
} | ||
break; | ||
@@ -121,8 +112,4 @@ } | ||
const listener = this.listeners.get(id); | ||
this.enqueueUpdate(component); | ||
if (listener) { | ||
listener(component); | ||
} | ||
break; | ||
@@ -157,2 +144,23 @@ } | ||
private enqueueUpdate(attached: Attachable) { | ||
if (this.timeout == null) { | ||
this.timeout = setTimeout(() => { | ||
const queuedUpdates = [...this.queuedUpdates]; | ||
this.timeout = null; | ||
this.queuedUpdates.clear(); | ||
for (const attached of queuedUpdates) { | ||
const listener = this.listeners.get( | ||
attached === this.root ? ROOT_ID : attached.id, | ||
); | ||
listener?.(attached); | ||
} | ||
}, 0); | ||
} | ||
this.queuedUpdates.add(attached); | ||
} | ||
private attach(child: Child) { | ||
@@ -159,0 +167,0 @@ this.attached.set(child.id, child); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
266660
0.83%2690
1.62%