New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@remote-ui/core

Package Overview
Dependencies
Maintainers
3
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@remote-ui/core - npm Package Compare versions

Comparing version 0.0.31 to 0.0.32

6

build/cjs/index.js

@@ -78,2 +78,8 @@ "use strict";

});
Object.defineProperty(exports, "createRemoteChannel", {
enumerable: true,
get: function get() {
return _receiver.createRemoteChannel;
}
});
Object.defineProperty(exports, "isRemoteComponent", {

@@ -80,0 +86,0 @@ enumerable: true,

223

build/cjs/receiver.js

@@ -58,2 +58,3 @@ "use strict";

});
exports.createRemoteChannel = createRemoteChannel;
exports.RemoteReceiver = void 0;

@@ -71,2 +72,10 @@

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

@@ -80,10 +89,2 @@

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }

@@ -103,2 +104,18 @@

function createRemoteChannel(_ref) {
var mount = _ref.mount,
insertChild = _ref.insertChild,
removeChild = _ref.removeChild,
updateProps = _ref.updateProps,
updateText = _ref.updateText;
var messageMap = new Map([[_types.ACTION_MOUNT, mount], [_types.ACTION_REMOVE_CHILD, removeChild], [_types.ACTION_INSERT_CHILD, insertChild], [_types.ACTION_UPDATE_PROPS, updateProps], [_types.ACTION_UPDATE_TEXT, updateText]]);
return function (type) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return messageMap.get(type).apply(void 0, args);
};
}
var RemoteReceiver = /*#__PURE__*/function () {

@@ -114,139 +131,89 @@ function RemoteReceiver() {

};
this.attached = new Map([[ROOT_ID, this.root]]);
this.timeout = null;
this.queuedUpdates = new Set();
this.listeners = new Map();
this.receive = createRemoteChannel({
mount: function mount(children) {
_this.root.children = children;
this.receive = function (type) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var _iterator = _createForOfIteratorHelper(children),
_step;
switch (type) {
case _types.ACTION_MOUNT:
{
var children = args[0];
_this.root.children = children;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var child = _step.value;
(0, _rpc.retain)(child);
var _iterator = _createForOfIteratorHelper(children),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var child = _step.value;
(0, _rpc.retain)(child);
_this.attach(child);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
_this.enqueueUpdate(_this.root);
break;
_this.attach(child);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
case _types.ACTION_REMOVE_CHILD:
{
var _ref = args,
_ref2 = _slicedToArray(_ref, 2),
_ref2$ = _ref2[0],
id = _ref2$ === void 0 ? ROOT_ID : _ref2$,
index = _ref2[1];
_this.enqueueUpdate(_this.root);
},
insertChild: function insertChild(id, index, child) {
(0, _rpc.retain)(child);
var attached = _this.attached.get(id);
_this.attach(child);
var _children = _toConsumableArray(attached.children);
var attached = _this.attached.get(id !== null && id !== void 0 ? id : ROOT_ID);
var _children$splice = _children.splice(index, 1),
_children$splice2 = _slicedToArray(_children$splice, 1),
removed = _children$splice2[0];
var children = _toConsumableArray(attached.children);
_this.detach(removed);
if (index === children.length) {
children.push(child);
} else {
children.splice(index, 0, child);
}
attached.children = _children; // eslint-disable-next-line promise/catch-or-return
attached.children = children;
_this.enqueueUpdate(attached).then(function () {
(0, _rpc.release)(removed);
});
_this.enqueueUpdate(attached);
},
removeChild: function removeChild(id, index) {
var attached = _this.attached.get(id !== null && id !== void 0 ? id : ROOT_ID);
break;
}
var children = _toConsumableArray(attached.children);
case _types.ACTION_INSERT_CHILD:
{
var _ref3 = args,
_ref4 = _slicedToArray(_ref3, 3),
_ref4$ = _ref4[0],
_id = _ref4$ === void 0 ? ROOT_ID : _ref4$,
_index = _ref4[1],
_child = _ref4[2];
var _children$splice = children.splice(index, 1),
_children$splice2 = _slicedToArray(_children$splice, 1),
removed = _children$splice2[0];
(0, _rpc.retain)(_child);
_this.detach(removed);
_this.attach(_child);
attached.children = children; // eslint-disable-next-line promise/catch-or-return
var _attached = _this.attached.get(_id);
_this.enqueueUpdate(attached).then(function () {
(0, _rpc.release)(removed);
});
},
updateProps: function updateProps(id, newProps) {
var component = _this.attached.get(id);
var _children2 = _toConsumableArray(_attached.children);
var oldProps = component.props;
(0, _rpc.retain)(newProps);
if (_index === _children2.length) {
_children2.push(_child);
} else {
_children2.splice(_index, 0, _child);
}
var props = _objectSpread(_objectSpread({}, component.props), newProps);
_attached.children = _children2;
component.props = props; // eslint-disable-next-line promise/catch-or-return
_this.enqueueUpdate(_attached);
break;
_this.enqueueUpdate(component).then(function () {
for (var _i2 = 0, _Object$keys = Object.keys(newProps); _i2 < _Object$keys.length; _i2++) {
var key = _Object$keys[_i2];
(0, _rpc.release)(oldProps[key]);
}
});
},
updateText: function updateText(id, newText) {
var text = _this.attached.get(id);
case _types.ACTION_UPDATE_PROPS:
{
var _ref5 = args,
_ref6 = _slicedToArray(_ref5, 2),
_id2 = _ref6[0],
newProps = _ref6[1];
text.text = newText;
var component = _this.attached.get(_id2);
var oldProps = component.props;
(0, _rpc.retain)(newProps);
var props = _objectSpread(_objectSpread({}, component.props), newProps);
component.props = props; // eslint-disable-next-line promise/catch-or-return
_this.enqueueUpdate(component).then(function () {
for (var _i2 = 0, _Object$keys = Object.keys(newProps); _i2 < _Object$keys.length; _i2++) {
var key = _Object$keys[_i2];
(0, _rpc.release)(oldProps[key]);
}
});
break;
}
case _types.ACTION_UPDATE_TEXT:
{
var _ref7 = args,
_ref8 = _slicedToArray(_ref7, 2),
_id3 = _ref8[0],
newText = _ref8[1];
var text = _this.attached.get(_id3);
text.text = newText;
_this.enqueueUpdate(text);
break;
}
_this.enqueueUpdate(text);
}
};
});
this.attached = new Map([[ROOT_ID, this.root]]);
this.timeout = null;
this.queuedUpdates = new Set();
this.listeners = new Map();
}

@@ -256,4 +223,4 @@

key: "get",
value: function get(_ref9) {
var id = _ref9.id;
value: function get(_ref2) {
var id = _ref2.id;
return this.attached.get(id);

@@ -263,6 +230,6 @@ }

key: "listen",
value: function listen(_ref10, listener) {
value: function listen(_ref3, listener) {
var _this2 = this;
var id = _ref10.id;
var id = _ref3.id;
var listeners;

@@ -311,5 +278,5 @@

for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _attached2 = _step2.value;
var _attached = _step2.value;
var listeners = _this3.listeners.get(_attached2 === _this3.root ? ROOT_ID : _attached2.id);
var listeners = _this3.listeners.get(_attached === _this3.root ? ROOT_ID : _attached.id);

@@ -323,3 +290,3 @@ if (listeners) {

var listener = _step3.value;
listener(_attached2);
listener(_attached);
}

@@ -326,0 +293,0 @@ } catch (err) {

@@ -95,2 +95,3 @@ "use strict";

var currentId = 0;
var mounted = false;
var remoteRoot = {

@@ -195,2 +196,3 @@ get children() {

mount: function mount() {
mounted = true;
return Promise.resolve(channel(_types.ACTION_MOUNT, children.get(remoteRoot).map(serialize)));

@@ -233,3 +235,3 @@ }

if (element === remoteRoot || connected(element)) {
if (mounted && (element === remoteRoot || connected(element))) {
// should only create context once async queue is cleared

@@ -236,0 +238,0 @@ remote(channel); // technically, we should be waiting for the remote update to apply,

@@ -6,3 +6,3 @@ "use strict";

});
exports.RemoteComponentViolationType = exports.KIND_TEXT = exports.KIND_COMPONENT = exports.RemoteKind = exports.UPDATE_REMOVE = exports.UPDATE_INSERT = exports.ACTION_UPDATE_PROPS = exports.ACTION_UPDATE_TEXT = exports.ACTION_REMOVE_CHILD = exports.ACTION_INSERT_CHILD = exports.ACTION_MOUNT = void 0;
exports.KIND_TEXT = exports.KIND_COMPONENT = exports.RemoteKind = exports.UPDATE_REMOVE = exports.UPDATE_INSERT = exports.ACTION_UPDATE_PROPS = exports.ACTION_UPDATE_TEXT = exports.ACTION_REMOVE_CHILD = exports.ACTION_INSERT_CHILD = exports.ACTION_MOUNT = void 0;
var ACTION_MOUNT = 0;

@@ -33,10 +33,2 @@ exports.ACTION_MOUNT = ACTION_MOUNT;

var KIND_TEXT = 2;
exports.KIND_TEXT = KIND_TEXT;
var RemoteComponentViolationType;
exports.RemoteComponentViolationType = RemoteComponentViolationType;
(function (RemoteComponentViolationType) {
RemoteComponentViolationType[RemoteComponentViolationType["InsertChild"] = 0] = "InsertChild";
RemoteComponentViolationType[RemoteComponentViolationType["InsertRoot"] = 1] = "InsertRoot";
RemoteComponentViolationType[RemoteComponentViolationType["UpdateProps"] = 2] = "UpdateProps";
})(RemoteComponentViolationType || (exports.RemoteComponentViolationType = RemoteComponentViolationType = {}));
exports.KIND_TEXT = KIND_TEXT;

@@ -78,2 +78,8 @@ "use strict";

});
Object.defineProperty(exports, "createRemoteChannel", {
enumerable: true,
get: function () {
return _receiver.createRemoteChannel;
}
});
Object.defineProperty(exports, "isRemoteComponent", {

@@ -80,0 +86,0 @@ enumerable: true,

@@ -6,2 +6,3 @@ "use strict";

});
exports.createRemoteChannel = createRemoteChannel;
exports.RemoteReceiver = void 0;

@@ -15,2 +16,13 @@

function createRemoteChannel({
mount,
insertChild,
removeChild,
updateProps,
updateText
}) {
const messageMap = new Map([[_types.ACTION_MOUNT, mount], [_types.ACTION_REMOVE_CHILD, removeChild], [_types.ACTION_INSERT_CHILD, insertChild], [_types.ACTION_UPDATE_PROPS, updateProps], [_types.ACTION_UPDATE_TEXT, updateText]]);
return (type, ...args) => messageMap.get(type)(...args);
}
class RemoteReceiver {

@@ -22,88 +34,66 @@ constructor() {

};
this.attached = new Map([[ROOT_ID, this.root]]);
this.timeout = null;
this.queuedUpdates = new Set();
this.listeners = new Map();
this.receive = createRemoteChannel({
mount: children => {
this.root.children = children;
this.receive = (type, ...args) => {
switch (type) {
case _types.ACTION_MOUNT:
{
const children = args[0];
this.root.children = children;
for (const child of children) {
(0, _rpc.retain)(child);
this.attach(child);
}
for (const child of children) {
(0, _rpc.retain)(child);
this.attach(child);
}
this.enqueueUpdate(this.root);
},
insertChild: (id, index, child) => {
(0, _rpc.retain)(child);
this.attach(child);
const attached = this.attached.get(id !== null && id !== void 0 ? id : ROOT_ID);
const children = [...attached.children];
this.enqueueUpdate(this.root);
break;
}
if (index === children.length) {
children.push(child);
} else {
children.splice(index, 0, child);
}
case _types.ACTION_REMOVE_CHILD:
{
const [id = ROOT_ID, index] = args;
const attached = this.attached.get(id);
const children = [...attached.children];
const [removed] = children.splice(index, 1);
this.detach(removed);
attached.children = children; // eslint-disable-next-line promise/catch-or-return
attached.children = children;
this.enqueueUpdate(attached);
},
removeChild: (id, index) => {
const attached = this.attached.get(id !== null && id !== void 0 ? id : ROOT_ID);
const children = [...attached.children];
const [removed] = children.splice(index, 1);
this.detach(removed);
attached.children = children; // eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(attached).then(() => {
(0, _rpc.release)(removed);
});
break;
}
this.enqueueUpdate(attached).then(() => {
(0, _rpc.release)(removed);
});
},
updateProps: (id, newProps) => {
const component = this.attached.get(id);
const {
props: oldProps
} = component;
(0, _rpc.retain)(newProps);
const props = { ...component.props,
...newProps
};
component.props = props; // eslint-disable-next-line promise/catch-or-return
case _types.ACTION_INSERT_CHILD:
{
const [id = ROOT_ID, index, child] = args;
(0, _rpc.retain)(child);
this.attach(child);
const attached = this.attached.get(id);
const children = [...attached.children];
if (index === children.length) {
children.push(child);
} else {
children.splice(index, 0, child);
}
attached.children = children;
this.enqueueUpdate(attached);
break;
this.enqueueUpdate(component).then(() => {
for (const key of Object.keys(newProps)) {
(0, _rpc.release)(oldProps[key]);
}
case _types.ACTION_UPDATE_PROPS:
{
const [id, newProps] = args;
const component = this.attached.get(id);
const {
props: oldProps
} = component;
(0, _rpc.retain)(newProps);
const props = { ...component.props,
...newProps
};
component.props = props; // eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(component).then(() => {
for (const key of Object.keys(newProps)) {
(0, _rpc.release)(oldProps[key]);
}
});
break;
}
case _types.ACTION_UPDATE_TEXT:
{
const [id, newText] = args;
const text = this.attached.get(id);
text.text = newText;
this.enqueueUpdate(text);
break;
}
});
},
updateText: (id, newText) => {
const text = this.attached.get(id);
text.text = newText;
this.enqueueUpdate(text);
}
};
});
this.attached = new Map([[ROOT_ID, this.root]]);
this.timeout = null;
this.queuedUpdates = new Set();
this.listeners = new Map();
}

@@ -110,0 +100,0 @@

@@ -17,2 +17,3 @@ "use strict";

let currentId = 0;
let mounted = false;
const remoteRoot = {

@@ -103,2 +104,3 @@ get children() {

mount() {
mounted = true;
return Promise.resolve(channel(_types.ACTION_MOUNT, children.get(remoteRoot).map(serialize)));

@@ -132,3 +134,3 @@ }

}) {
if (element === remoteRoot || connected(element)) {
if (mounted && (element === remoteRoot || connected(element))) {
// should only create context once async queue is cleared

@@ -135,0 +137,0 @@ remote(channel); // technically, we should be waiting for the remote update to apply,

@@ -6,3 +6,3 @@ "use strict";

});
exports.RemoteComponentViolationType = exports.KIND_TEXT = exports.KIND_COMPONENT = exports.RemoteKind = exports.UPDATE_REMOVE = exports.UPDATE_INSERT = exports.ACTION_UPDATE_PROPS = exports.ACTION_UPDATE_TEXT = exports.ACTION_REMOVE_CHILD = exports.ACTION_INSERT_CHILD = exports.ACTION_MOUNT = void 0;
exports.KIND_TEXT = exports.KIND_COMPONENT = exports.RemoteKind = exports.UPDATE_REMOVE = exports.UPDATE_INSERT = exports.ACTION_UPDATE_PROPS = exports.ACTION_UPDATE_TEXT = exports.ACTION_REMOVE_CHILD = exports.ACTION_INSERT_CHILD = exports.ACTION_MOUNT = void 0;
const ACTION_MOUNT = 0;

@@ -33,10 +33,2 @@ exports.ACTION_MOUNT = ACTION_MOUNT;

const KIND_TEXT = 2;
exports.KIND_TEXT = KIND_TEXT;
let RemoteComponentViolationType;
exports.RemoteComponentViolationType = RemoteComponentViolationType;
(function (RemoteComponentViolationType) {
RemoteComponentViolationType[RemoteComponentViolationType["InsertChild"] = 0] = "InsertChild";
RemoteComponentViolationType[RemoteComponentViolationType["InsertRoot"] = 1] = "InsertRoot";
RemoteComponentViolationType[RemoteComponentViolationType["UpdateProps"] = 2] = "UpdateProps";
})(RemoteComponentViolationType || (exports.RemoteComponentViolationType = RemoteComponentViolationType = {}));
exports.KIND_TEXT = KIND_TEXT;

@@ -5,6 +5,6 @@ export type { RemoteComponentType, PropsForRemoteComponent, AllowedChildrenForRemoteComponent, IdentifierForRemoteComponent, } from '@remote-ui/types';

export { ACTION_MOUNT, ACTION_INSERT_CHILD, ACTION_REMOVE_CHILD, ACTION_UPDATE_PROPS, ACTION_UPDATE_TEXT, KIND_COMPONENT, KIND_TEXT, } from './types';
export type { RemoteRoot, RemoteChannel, RemoteComponent, RemoteText, RemoteChild, Serialized, } from './types';
export type { RemoteRoot, RemoteChannel, RemoteComponent, RemoteText, RemoteChild, Serialized, ActionArgumentMap, RemoteTextSerialization, RemoteComponentSerialization, } from './types';
export { createRemoteRoot } from './root';
export { RemoteReceiver } from './receiver';
export { RemoteReceiver, createRemoteChannel } from './receiver';
export { isRemoteComponent, isRemoteText } from './utilities';
//# sourceMappingURL=index.d.ts.map

@@ -20,4 +20,5 @@ "use strict";

Object.defineProperty(exports, "RemoteReceiver", { enumerable: true, get: function () { return receiver_1.RemoteReceiver; } });
Object.defineProperty(exports, "createRemoteChannel", { enumerable: true, get: function () { return receiver_1.createRemoteChannel; } });
var utilities_1 = require("./utilities");
Object.defineProperty(exports, "isRemoteComponent", { enumerable: true, get: function () { return utilities_1.isRemoteComponent; } });
Object.defineProperty(exports, "isRemoteText", { enumerable: true, get: function () { return utilities_1.isRemoteText; } });

@@ -1,2 +0,3 @@

import type { RemoteChannel, RemoteTextSerialization, RemoteComponentSerialization } from './types';
import { ACTION_MOUNT, ACTION_INSERT_CHILD, ACTION_UPDATE_PROPS, ACTION_UPDATE_TEXT } from './types';
import type { ActionArgumentMap, RemoteChannel, RemoteTextSerialization, RemoteComponentSerialization } from './types';
declare const ROOT_ID: unique symbol;

@@ -10,4 +11,13 @@ declare type Child = RemoteTextSerialization | RemoteComponentSerialization<any>;

declare type UpdateListener<T extends Attachable> = (updated: T) => void;
interface RemoteChannelRunner {
mount(...args: ActionArgumentMap[typeof ACTION_MOUNT]): void;
insertChild(...args: ActionArgumentMap[typeof ACTION_INSERT_CHILD]): void;
removeChild(...args: ActionArgumentMap[typeof ACTION_INSERT_CHILD]): void;
updateProps(...args: ActionArgumentMap[typeof ACTION_UPDATE_PROPS]): void;
updateText(...args: ActionArgumentMap[typeof ACTION_UPDATE_TEXT]): void;
}
export declare function createRemoteChannel({ mount, insertChild, removeChild, updateProps, updateText, }: RemoteChannelRunner): RemoteChannel;
export declare class RemoteReceiver {
readonly root: Root;
readonly receive: RemoteChannel;
private attached;

@@ -17,3 +27,2 @@ private timeout;

private readonly listeners;
readonly receive: RemoteChannel;
get<T extends Attachable>({ id }: T): T;

@@ -20,0 +29,0 @@ listen<T extends Attachable>({ id }: T, listener: UpdateListener<T>): () => void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoteReceiver = void 0;
exports.RemoteReceiver = exports.createRemoteChannel = void 0;
const rpc_1 = require("@remote-ui/rpc");
const types_1 = require("./types");
const ROOT_ID = Symbol('RootId');
function createRemoteChannel({ mount, insertChild, removeChild, updateProps, updateText, }) {
const messageMap = new Map([
[types_1.ACTION_MOUNT, mount],
[types_1.ACTION_REMOVE_CHILD, removeChild],
[types_1.ACTION_INSERT_CHILD, insertChild],
[types_1.ACTION_UPDATE_PROPS, updateProps],
[types_1.ACTION_UPDATE_TEXT, updateText],
]);
return (type, ...args) => messageMap.get(type)(...args);
}
exports.createRemoteChannel = createRemoteChannel;
class RemoteReceiver {
constructor() {
this.root = { id: ROOT_ID, children: [] };
this.receive = createRemoteChannel({
mount: (children) => {
this.root.children = children;
for (const child of children) {
rpc_1.retain(child);
this.attach(child);
}
this.enqueueUpdate(this.root);
},
insertChild: (id, index, child) => {
rpc_1.retain(child);
this.attach(child);
const attached = this.attached.get(id !== null && id !== void 0 ? id : ROOT_ID);
const children = [...attached.children];
if (index === children.length) {
children.push(child);
}
else {
children.splice(index, 0, child);
}
attached.children = children;
this.enqueueUpdate(attached);
},
removeChild: (id, index) => {
const attached = this.attached.get(id !== null && id !== void 0 ? id : ROOT_ID);
const children = [...attached.children];
const [removed] = children.splice(index, 1);
this.detach(removed);
attached.children = children;
// eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(attached).then(() => {
rpc_1.release(removed);
});
},
updateProps: (id, newProps) => {
const component = this.attached.get(id);
const { props: oldProps } = component;
rpc_1.retain(newProps);
const props = Object.assign(Object.assign({}, component.props), newProps);
component.props = props;
// eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(component).then(() => {
for (const key of Object.keys(newProps)) {
rpc_1.release(oldProps[key]);
}
});
},
updateText: (id, newText) => {
const text = this.attached.get(id);
text.text = newText;
this.enqueueUpdate(text);
},
});
this.attached = new Map([

@@ -16,67 +80,2 @@ [ROOT_ID, this.root],

this.listeners = new Map();
this.receive = (type, ...args) => {
switch (type) {
case types_1.ACTION_MOUNT: {
const children = args[0];
this.root.children = children;
for (const child of children) {
rpc_1.retain(child);
this.attach(child);
}
this.enqueueUpdate(this.root);
break;
}
case types_1.ACTION_REMOVE_CHILD: {
const [id = ROOT_ID, index,] = args;
const attached = this.attached.get(id);
const children = [...attached.children];
const [removed] = children.splice(index, 1);
this.detach(removed);
attached.children = children;
// eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(attached).then(() => {
rpc_1.release(removed);
});
break;
}
case types_1.ACTION_INSERT_CHILD: {
const [id = ROOT_ID, index, child,] = args;
rpc_1.retain(child);
this.attach(child);
const attached = this.attached.get(id);
const children = [...attached.children];
if (index === children.length) {
children.push(child);
}
else {
children.splice(index, 0, child);
}
attached.children = children;
this.enqueueUpdate(attached);
break;
}
case types_1.ACTION_UPDATE_PROPS: {
const [id, newProps] = args;
const component = this.attached.get(id);
const { props: oldProps } = component;
rpc_1.retain(newProps);
const props = Object.assign(Object.assign({}, component.props), newProps);
component.props = props;
// eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(component).then(() => {
for (const key of Object.keys(newProps)) {
rpc_1.release(oldProps[key]);
}
});
break;
}
case types_1.ACTION_UPDATE_TEXT: {
const [id, newText] = args;
const text = this.attached.get(id);
text.text = newText;
this.enqueueUpdate(text);
break;
}
}
};
}

@@ -83,0 +82,0 @@ get({ id }) {

@@ -12,2 +12,3 @@ "use strict";

let currentId = 0;
let mounted = false;
const remoteRoot = {

@@ -69,2 +70,3 @@ get children() {

mount() {
mounted = true;
return Promise.resolve(channel(types_1.ACTION_MOUNT, children.get(remoteRoot).map(serialize)));

@@ -90,3 +92,3 @@ },

function perform(element, { remote, local, }) {
if (element === remoteRoot || connected(element)) {
if (mounted && (element === remoteRoot || connected(element))) {
// should only create context once async queue is cleared

@@ -93,0 +95,0 @@ remote(channel);

@@ -16,3 +16,3 @@ import { RemoteComponentType, IdentifierForRemoteComponent, PropsForRemoteComponent } from '@remote-ui/types';

export declare type Id = string;
export interface MessageMap {
export interface ActionArgumentMap {
[ACTION_UPDATE_TEXT]: [Id, string];

@@ -25,3 +25,3 @@ [ACTION_UPDATE_PROPS]: [Id, object];

export interface RemoteChannel {
<T extends keyof MessageMap>(type: T, ...payload: MessageMap[T]): void | Promise<void>;
<T extends keyof ActionArgumentMap>(type: T, ...payload: ActionArgumentMap[T]): void | Promise<void>;
}

@@ -80,8 +80,3 @@ export declare enum RemoteKind {

export declare type Serialized<T> = T extends RemoteComponent<infer Type, any> ? RemoteComponentSerialization<Type> : T extends RemoteText<any> ? RemoteTextSerialization : never;
export declare enum RemoteComponentViolationType {
InsertChild = 0,
InsertRoot = 1,
UpdateProps = 2
}
export {};
//# sourceMappingURL=types.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoteComponentViolationType = exports.KIND_TEXT = exports.KIND_COMPONENT = exports.RemoteKind = exports.UPDATE_REMOVE = exports.UPDATE_INSERT = exports.ACTION_UPDATE_PROPS = exports.ACTION_UPDATE_TEXT = exports.ACTION_REMOVE_CHILD = exports.ACTION_INSERT_CHILD = exports.ACTION_MOUNT = void 0;
exports.KIND_TEXT = exports.KIND_COMPONENT = exports.RemoteKind = exports.UPDATE_REMOVE = exports.UPDATE_INSERT = exports.ACTION_UPDATE_PROPS = exports.ACTION_UPDATE_TEXT = exports.ACTION_REMOVE_CHILD = exports.ACTION_INSERT_CHILD = exports.ACTION_MOUNT = void 0;
exports.ACTION_MOUNT = 0;

@@ -18,7 +18,1 @@ exports.ACTION_INSERT_CHILD = 1;

exports.KIND_TEXT = 2;
var RemoteComponentViolationType;
(function (RemoteComponentViolationType) {
RemoteComponentViolationType[RemoteComponentViolationType["InsertChild"] = 0] = "InsertChild";
RemoteComponentViolationType[RemoteComponentViolationType["InsertRoot"] = 1] = "InsertRoot";
RemoteComponentViolationType[RemoteComponentViolationType["UpdateProps"] = 2] = "UpdateProps";
})(RemoteComponentViolationType = exports.RemoteComponentViolationType || (exports.RemoteComponentViolationType = {}));
{
"name": "@remote-ui/core",
"version": "0.0.31",
"version": "0.0.32",
"publishConfig": {

@@ -5,0 +5,0 @@ "access": "public",

@@ -27,5 +27,8 @@ export type {

Serialized,
ActionArgumentMap,
RemoteTextSerialization,
RemoteComponentSerialization,
} from './types';
export {createRemoteRoot} from './root';
export {RemoteReceiver} from './receiver';
export {RemoteReceiver, createRemoteChannel} from './receiver';
export {isRemoteComponent, isRemoteText} from './utilities';

@@ -10,3 +10,3 @@ import {retain, release} from '@remote-ui/rpc';

import type {
MessageMap,
ActionArgumentMap,
RemoteChannel,

@@ -30,109 +30,106 @@ RemoteTextSerialization,

export class RemoteReceiver {
readonly root: Root = {id: ROOT_ID, children: []};
private attached = new Map<string | typeof ROOT_ID, Attachable>([
[ROOT_ID, this.root],
interface RemoteChannelRunner {
mount(...args: ActionArgumentMap[typeof ACTION_MOUNT]): void;
insertChild(...args: ActionArgumentMap[typeof ACTION_INSERT_CHILD]): void;
removeChild(...args: ActionArgumentMap[typeof ACTION_INSERT_CHILD]): void;
updateProps(...args: ActionArgumentMap[typeof ACTION_UPDATE_PROPS]): void;
updateText(...args: ActionArgumentMap[typeof ACTION_UPDATE_TEXT]): void;
}
export function createRemoteChannel({
mount,
insertChild,
removeChild,
updateProps,
updateText,
}: RemoteChannelRunner): RemoteChannel {
const messageMap = new Map<number, Function>([
[ACTION_MOUNT, mount],
[ACTION_REMOVE_CHILD, removeChild],
[ACTION_INSERT_CHILD, insertChild],
[ACTION_UPDATE_PROPS, updateProps],
[ACTION_UPDATE_TEXT, updateText],
]);
private timeout: Promise<void> | null = null;
private queuedUpdates = new Set<Attachable>();
return (type, ...args) => (messageMap.get(type) as any)(...args);
}
private readonly listeners = new Map<
string | typeof ROOT_ID,
Set<UpdateListener<any>>
>();
export class RemoteReceiver {
readonly root: Root = {id: ROOT_ID, children: []};
readonly receive: RemoteChannel = (type, ...args) => {
switch (type) {
case ACTION_MOUNT: {
const children = (args as MessageMap[typeof ACTION_MOUNT])[0];
readonly receive = createRemoteChannel({
mount: (children) => {
this.root.children = children;
this.root.children = children;
for (const child of children) {
retain(child);
this.attach(child);
}
this.enqueueUpdate(this.root);
break;
for (const child of children) {
retain(child);
this.attach(child);
}
case ACTION_REMOVE_CHILD: {
const [
id = ROOT_ID,
index,
] = args as MessageMap[typeof ACTION_REMOVE_CHILD];
const attached = this.attached.get(id) as Root;
const children = [...attached.children];
const [removed] = children.splice(index, 1);
this.enqueueUpdate(this.root);
},
insertChild: (id, index, child) => {
retain(child);
this.attach(child);
const attached = this.attached.get(id ?? ROOT_ID) as Root;
const children = [...attached.children];
this.detach(removed);
attached.children = children;
// eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(attached).then(() => {
release(removed);
});
break;
if (index === children.length) {
children.push(child);
} else {
children.splice(index, 0, child);
}
case ACTION_INSERT_CHILD: {
const [
id = ROOT_ID,
index,
child,
] = args as MessageMap[typeof ACTION_INSERT_CHILD];
retain(child);
this.attach(child);
const attached = this.attached.get(id) as Root;
const children = [...attached.children];
attached.children = children;
if (index === children.length) {
children.push(child);
} else {
children.splice(index, 0, child);
}
this.enqueueUpdate(attached);
},
removeChild: (id, index) => {
const attached = this.attached.get(id ?? ROOT_ID) as Root;
const children = [...attached.children];
const [removed] = children.splice(index, 1);
attached.children = children;
this.detach(removed);
attached.children = children;
this.enqueueUpdate(attached);
// eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(attached).then(() => {
release(removed);
});
},
updateProps: (id, newProps) => {
const component = this.attached.get(id) as RemoteComponentSerialization;
const {props: oldProps} = component;
break;
}
case ACTION_UPDATE_PROPS: {
const [id, newProps] = args as MessageMap[typeof ACTION_UPDATE_PROPS];
retain(newProps);
const component = this.attached.get(id) as RemoteComponentSerialization;
const {props: oldProps} = component;
const props = {...(component.props as any), ...newProps};
component.props = props;
retain(newProps);
// eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(component).then(() => {
for (const key of Object.keys(newProps)) {
release((oldProps as any)[key]);
}
});
},
updateText: (id, newText) => {
const text = this.attached.get(id) as RemoteTextSerialization;
text.text = newText;
this.enqueueUpdate(text);
},
});
const props = {...(component.props as any), ...newProps};
component.props = props;
private attached = new Map<string | typeof ROOT_ID, Attachable>([
[ROOT_ID, this.root],
]);
// eslint-disable-next-line promise/catch-or-return
this.enqueueUpdate(component).then(() => {
for (const key of Object.keys(newProps)) {
release((oldProps as any)[key]);
}
});
private timeout: Promise<void> | null = null;
private queuedUpdates = new Set<Attachable>();
break;
}
case ACTION_UPDATE_TEXT: {
const [id, newText] = args as MessageMap[typeof ACTION_UPDATE_TEXT];
private readonly listeners = new Map<
string | typeof ROOT_ID,
Set<UpdateListener<any>>
>();
const text = this.attached.get(id) as RemoteTextSerialization;
text.text = newText;
this.enqueueUpdate(text);
break;
}
}
};
get<T extends Attachable>({id}: T) {

@@ -139,0 +136,0 @@ return this.attached.get(id) as T;

@@ -48,2 +48,3 @@ import {RemoteComponentType} from '@remote-ui/types';

let currentId = 0;
let mounted = false;

@@ -135,2 +136,3 @@ const remoteRoot: Root = {

mount() {
mounted = true;
return Promise.resolve(

@@ -176,3 +178,3 @@ channel(ACTION_MOUNT, children.get(remoteRoot)!.map(serialize)),

) {
if (element === remoteRoot || connected(element as any)) {
if (mounted && (element === remoteRoot || connected(element as any))) {
// should only create context once async queue is cleared

@@ -179,0 +181,0 @@ remote(channel);

@@ -28,3 +28,3 @@ import {

export interface MessageMap {
export interface ActionArgumentMap {
[ACTION_UPDATE_TEXT]: [Id, string];

@@ -42,5 +42,5 @@ [ACTION_UPDATE_PROPS]: [Id, object];

export interface RemoteChannel {
<T extends keyof MessageMap>(
<T extends keyof ActionArgumentMap>(
type: T,
...payload: MessageMap[T]
...payload: ActionArgumentMap[T]
): void | Promise<void>;

@@ -198,7 +198,1 @@ }

: never;
export enum RemoteComponentViolationType {
InsertChild,
InsertRoot,
UpdateProps,
}

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc