@remote-ui/core
Advanced tools
Comparing version 0.0.27 to 0.0.28
@@ -24,8 +24,44 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "Action", { | ||
Object.defineProperty(exports, "ACTION_MOUNT", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.Action; | ||
return _types.ACTION_MOUNT; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ACTION_INSERT_CHILD", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.ACTION_INSERT_CHILD; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ACTION_REMOVE_CHILD", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.ACTION_REMOVE_CHILD; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ACTION_UPDATE_PROPS", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.ACTION_UPDATE_PROPS; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ACTION_UPDATE_TEXT", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.ACTION_UPDATE_TEXT; | ||
} | ||
}); | ||
Object.defineProperty(exports, "KIND_COMPONENT", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.KIND_COMPONENT; | ||
} | ||
}); | ||
Object.defineProperty(exports, "KIND_TEXT", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.KIND_TEXT; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createRemoteRoot", { | ||
@@ -43,2 +79,14 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "isRemoteComponent", { | ||
enumerable: true, | ||
get: function get() { | ||
return _utilities.isRemoteComponent; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isRemoteText", { | ||
enumerable: true, | ||
get: function get() { | ||
return _utilities.isRemoteText; | ||
} | ||
}); | ||
@@ -53,2 +101,4 @@ var _rpc = require("@remote-ui/rpc"); | ||
var _receiver = require("./receiver"); | ||
var _receiver = require("./receiver"); | ||
var _utilities = require("./utilities"); |
@@ -121,3 +121,3 @@ "use strict"; | ||
switch (type) { | ||
case _types.Action.Mount: | ||
case _types.ACTION_MOUNT: | ||
{ | ||
@@ -148,3 +148,3 @@ var children = args[0]; | ||
case _types.Action.RemoveChild: | ||
case _types.ACTION_REMOVE_CHILD: | ||
{ | ||
@@ -176,3 +176,3 @@ var _ref = args, | ||
case _types.Action.InsertChild: | ||
case _types.ACTION_INSERT_CHILD: | ||
{ | ||
@@ -207,3 +207,3 @@ var _ref3 = args, | ||
case _types.Action.UpdateProps: | ||
case _types.ACTION_UPDATE_PROPS: | ||
{ | ||
@@ -234,3 +234,3 @@ var _ref5 = args, | ||
case _types.Action.UpdateText: | ||
case _types.ACTION_UPDATE_TEXT: | ||
{ | ||
@@ -237,0 +237,0 @@ var _ref7 = args, |
@@ -116,2 +116,4 @@ "use strict"; | ||
var component = _objectSpread({ | ||
kind: _types.KIND_COMPONENT, | ||
get children() { | ||
@@ -156,2 +158,4 @@ return children.get(component); | ||
var text = _objectSpread({ | ||
kind: _types.KIND_TEXT, | ||
get text() { | ||
@@ -187,3 +191,3 @@ return texts.get(text); | ||
_context.next = 2; | ||
return channel(_types.Action.Mount, children.get(remoteRoot).map(serialize)); | ||
return channel(_types.ACTION_MOUNT, children.get(remoteRoot).map(serialize)); | ||
@@ -254,3 +258,3 @@ case 2: | ||
remote: function remote(channel) { | ||
return channel(_types.Action.UpdateText, text.id, newText); | ||
return channel(_types.ACTION_UPDATE_TEXT, text.id, newText); | ||
}, | ||
@@ -266,3 +270,3 @@ local: function local() { | ||
remote: function remote(channel) { | ||
return channel(_types.Action.UpdateProps, component.id, newProps); | ||
return channel(_types.ACTION_UPDATE_PROPS, component.id, newProps); | ||
}, | ||
@@ -279,3 +283,3 @@ local: function local() { | ||
remote: function remote(channel) { | ||
return channel(_types.Action.InsertChild, container.id, container.children.length, serialize(normalizedChild)); | ||
return channel(_types.ACTION_INSERT_CHILD, container.id, container.children.length, serialize(normalizedChild)); | ||
}, | ||
@@ -308,3 +312,3 @@ local: function local() { | ||
remote: function remote(channel) { | ||
return channel(_types.Action.RemoveChild, container.id, container.children.indexOf(child)); | ||
return channel(_types.ACTION_REMOVE_CHILD, container.id, container.children.indexOf(child)); | ||
}, | ||
@@ -330,3 +334,3 @@ local: function local() { | ||
remote: function remote(channel) { | ||
return channel(_types.Action.InsertChild, container.id, container.children.indexOf(before), serialize(child)); | ||
return channel(_types.ACTION_INSERT_CHILD, container.id, container.children.indexOf(before), serialize(child)); | ||
}, | ||
@@ -333,0 +337,0 @@ local: function local() { |
@@ -6,22 +6,17 @@ "use strict"; | ||
}); | ||
exports.RemoteComponentViolationType = exports.RemoteKind = exports.UpdateOperation = exports.Action = void 0; | ||
var Action; | ||
exports.Action = Action; | ||
(function (Action) { | ||
Action[Action["UpdateText"] = 0] = "UpdateText"; | ||
Action[Action["UpdateProps"] = 1] = "UpdateProps"; | ||
Action[Action["InsertChild"] = 2] = "InsertChild"; | ||
Action[Action["RemoveChild"] = 3] = "RemoveChild"; | ||
Action[Action["Mount"] = 4] = "Mount"; | ||
})(Action || (exports.Action = Action = {})); | ||
var UpdateOperation; | ||
exports.UpdateOperation = UpdateOperation; | ||
(function (UpdateOperation) { | ||
UpdateOperation[UpdateOperation["Insert"] = 0] = "Insert"; | ||
UpdateOperation[UpdateOperation["Remove"] = 1] = "Remove"; | ||
})(UpdateOperation || (exports.UpdateOperation = UpdateOperation = {})); | ||
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; | ||
var ACTION_MOUNT = 0; | ||
exports.ACTION_MOUNT = ACTION_MOUNT; | ||
var ACTION_INSERT_CHILD = 1; | ||
exports.ACTION_INSERT_CHILD = ACTION_INSERT_CHILD; | ||
var ACTION_REMOVE_CHILD = 2; | ||
exports.ACTION_REMOVE_CHILD = ACTION_REMOVE_CHILD; | ||
var ACTION_UPDATE_TEXT = 3; | ||
exports.ACTION_UPDATE_TEXT = ACTION_UPDATE_TEXT; | ||
var ACTION_UPDATE_PROPS = 4; | ||
exports.ACTION_UPDATE_PROPS = ACTION_UPDATE_PROPS; | ||
var UPDATE_INSERT = 0; | ||
exports.UPDATE_INSERT = UPDATE_INSERT; | ||
var UPDATE_REMOVE = 1; | ||
exports.UPDATE_REMOVE = UPDATE_REMOVE; | ||
var RemoteKind; | ||
@@ -35,2 +30,6 @@ exports.RemoteKind = RemoteKind; | ||
var KIND_COMPONENT = 1; | ||
exports.KIND_COMPONENT = KIND_COMPONENT; | ||
var KIND_TEXT = 2; | ||
exports.KIND_TEXT = KIND_TEXT; | ||
var RemoteComponentViolationType; | ||
@@ -37,0 +36,0 @@ exports.RemoteComponentViolationType = RemoteComponentViolationType; |
@@ -24,8 +24,44 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "Action", { | ||
Object.defineProperty(exports, "ACTION_MOUNT", { | ||
enumerable: true, | ||
get: function () { | ||
return _types.Action; | ||
return _types.ACTION_MOUNT; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ACTION_INSERT_CHILD", { | ||
enumerable: true, | ||
get: function () { | ||
return _types.ACTION_INSERT_CHILD; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ACTION_REMOVE_CHILD", { | ||
enumerable: true, | ||
get: function () { | ||
return _types.ACTION_REMOVE_CHILD; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ACTION_UPDATE_PROPS", { | ||
enumerable: true, | ||
get: function () { | ||
return _types.ACTION_UPDATE_PROPS; | ||
} | ||
}); | ||
Object.defineProperty(exports, "ACTION_UPDATE_TEXT", { | ||
enumerable: true, | ||
get: function () { | ||
return _types.ACTION_UPDATE_TEXT; | ||
} | ||
}); | ||
Object.defineProperty(exports, "KIND_COMPONENT", { | ||
enumerable: true, | ||
get: function () { | ||
return _types.KIND_COMPONENT; | ||
} | ||
}); | ||
Object.defineProperty(exports, "KIND_TEXT", { | ||
enumerable: true, | ||
get: function () { | ||
return _types.KIND_TEXT; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createRemoteRoot", { | ||
@@ -43,2 +79,14 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "isRemoteComponent", { | ||
enumerable: true, | ||
get: function () { | ||
return _utilities.isRemoteComponent; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isRemoteText", { | ||
enumerable: true, | ||
get: function () { | ||
return _utilities.isRemoteText; | ||
} | ||
}); | ||
@@ -53,2 +101,4 @@ var _rpc = require("@remote-ui/rpc"); | ||
var _receiver = require("./receiver"); | ||
var _receiver = require("./receiver"); | ||
var _utilities = require("./utilities"); |
@@ -27,3 +27,3 @@ "use strict"; | ||
switch (type) { | ||
case _types.Action.Mount: | ||
case _types.ACTION_MOUNT: | ||
{ | ||
@@ -42,3 +42,3 @@ const children = args[0]; | ||
case _types.Action.RemoveChild: | ||
case _types.ACTION_REMOVE_CHILD: | ||
{ | ||
@@ -58,3 +58,3 @@ const [id = ROOT_ID, index] = args; | ||
case _types.Action.InsertChild: | ||
case _types.ACTION_INSERT_CHILD: | ||
{ | ||
@@ -78,3 +78,3 @@ const [id = ROOT_ID, index, child] = args; | ||
case _types.Action.UpdateProps: | ||
case _types.ACTION_UPDATE_PROPS: | ||
{ | ||
@@ -100,3 +100,3 @@ const [id, newProps] = args; | ||
case _types.Action.UpdateText: | ||
case _types.ACTION_UPDATE_TEXT: | ||
{ | ||
@@ -103,0 +103,0 @@ const [id, newText] = args; |
@@ -26,2 +26,4 @@ "use strict"; | ||
const component = { | ||
kind: _types.KIND_COMPONENT, | ||
get children() { | ||
@@ -61,2 +63,4 @@ return children.get(component); | ||
const text = { | ||
kind: _types.KIND_TEXT, | ||
get text() { | ||
@@ -82,3 +86,3 @@ return texts.get(text); | ||
async mount() { | ||
await channel(_types.Action.Mount, children.get(remoteRoot).map(serialize)); | ||
await channel(_types.ACTION_MOUNT, children.get(remoteRoot).map(serialize)); | ||
} | ||
@@ -131,3 +135,3 @@ | ||
return perform(text, { | ||
remote: channel => channel(_types.Action.UpdateText, text.id, newText), | ||
remote: channel => channel(_types.ACTION_UPDATE_TEXT, text.id, newText), | ||
local: () => texts.set(text, newText) | ||
@@ -139,3 +143,3 @@ }); | ||
return perform(component, { | ||
remote: channel => channel(_types.Action.UpdateProps, component.id, newProps), | ||
remote: channel => channel(_types.ACTION_UPDATE_PROPS, component.id, newProps), | ||
local: () => { | ||
@@ -152,3 +156,3 @@ props.set(component, Object.freeze({ ...props.get(component), | ||
return perform(container, { | ||
remote: channel => channel(_types.Action.InsertChild, container.id, container.children.length, serialize(normalizedChild)), | ||
remote: channel => channel(_types.ACTION_INSERT_CHILD, container.id, container.children.length, serialize(normalizedChild)), | ||
local: () => { | ||
@@ -177,3 +181,3 @@ var _children$get; | ||
return perform(container, { | ||
remote: channel => channel(_types.Action.RemoveChild, container.id, container.children.indexOf(child)), | ||
remote: channel => channel(_types.ACTION_REMOVE_CHILD, container.id, container.children.indexOf(child)), | ||
local: () => { | ||
@@ -193,3 +197,3 @@ var _children$get2; | ||
return perform(container, { | ||
remote: channel => channel(_types.Action.InsertChild, container.id, container.children.indexOf(before), serialize(child)), | ||
remote: channel => channel(_types.ACTION_INSERT_CHILD, container.id, container.children.indexOf(before), serialize(child)), | ||
local: () => { | ||
@@ -196,0 +200,0 @@ const newTop = container === remoteRoot ? remoteRoot : tops.get(container); |
@@ -6,22 +6,17 @@ "use strict"; | ||
}); | ||
exports.RemoteComponentViolationType = exports.RemoteKind = exports.UpdateOperation = exports.Action = void 0; | ||
let Action; | ||
exports.Action = Action; | ||
(function (Action) { | ||
Action[Action["UpdateText"] = 0] = "UpdateText"; | ||
Action[Action["UpdateProps"] = 1] = "UpdateProps"; | ||
Action[Action["InsertChild"] = 2] = "InsertChild"; | ||
Action[Action["RemoveChild"] = 3] = "RemoveChild"; | ||
Action[Action["Mount"] = 4] = "Mount"; | ||
})(Action || (exports.Action = Action = {})); | ||
let UpdateOperation; | ||
exports.UpdateOperation = UpdateOperation; | ||
(function (UpdateOperation) { | ||
UpdateOperation[UpdateOperation["Insert"] = 0] = "Insert"; | ||
UpdateOperation[UpdateOperation["Remove"] = 1] = "Remove"; | ||
})(UpdateOperation || (exports.UpdateOperation = UpdateOperation = {})); | ||
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; | ||
const ACTION_MOUNT = 0; | ||
exports.ACTION_MOUNT = ACTION_MOUNT; | ||
const ACTION_INSERT_CHILD = 1; | ||
exports.ACTION_INSERT_CHILD = ACTION_INSERT_CHILD; | ||
const ACTION_REMOVE_CHILD = 2; | ||
exports.ACTION_REMOVE_CHILD = ACTION_REMOVE_CHILD; | ||
const ACTION_UPDATE_TEXT = 3; | ||
exports.ACTION_UPDATE_TEXT = ACTION_UPDATE_TEXT; | ||
const ACTION_UPDATE_PROPS = 4; | ||
exports.ACTION_UPDATE_PROPS = ACTION_UPDATE_PROPS; | ||
const UPDATE_INSERT = 0; | ||
exports.UPDATE_INSERT = UPDATE_INSERT; | ||
const UPDATE_REMOVE = 1; | ||
exports.UPDATE_REMOVE = UPDATE_REMOVE; | ||
let RemoteKind; | ||
@@ -35,2 +30,6 @@ exports.RemoteKind = RemoteKind; | ||
const KIND_COMPONENT = 1; | ||
exports.KIND_COMPONENT = KIND_COMPONENT; | ||
const KIND_TEXT = 2; | ||
exports.KIND_TEXT = KIND_TEXT; | ||
let RemoteComponentViolationType; | ||
@@ -37,0 +36,0 @@ exports.RemoteComponentViolationType = RemoteComponentViolationType; |
export type { RemoteComponentType, PropsForRemoteComponent, AllowedChildrenForRemoteComponent, IdentifierForRemoteComponent, } from '@remote-ui/types'; | ||
export { retain, release } from '@remote-ui/rpc'; | ||
export { createRemoteComponent } from './component'; | ||
export { Action } from './types'; | ||
export type { RemoteRoot, RemoteChannel, RemoteComponent, RemoteText, Serialized, } from './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 { createRemoteRoot } from './root'; | ||
export { RemoteReceiver } from './receiver'; | ||
export { isRemoteComponent, isRemoteText } from './utilities'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -9,3 +9,9 @@ "use strict"; | ||
var types_1 = require("./types"); | ||
Object.defineProperty(exports, "Action", { enumerable: true, get: function () { return types_1.Action; } }); | ||
Object.defineProperty(exports, "ACTION_MOUNT", { enumerable: true, get: function () { return types_1.ACTION_MOUNT; } }); | ||
Object.defineProperty(exports, "ACTION_INSERT_CHILD", { enumerable: true, get: function () { return types_1.ACTION_INSERT_CHILD; } }); | ||
Object.defineProperty(exports, "ACTION_REMOVE_CHILD", { enumerable: true, get: function () { return types_1.ACTION_REMOVE_CHILD; } }); | ||
Object.defineProperty(exports, "ACTION_UPDATE_PROPS", { enumerable: true, get: function () { return types_1.ACTION_UPDATE_PROPS; } }); | ||
Object.defineProperty(exports, "ACTION_UPDATE_TEXT", { enumerable: true, get: function () { return types_1.ACTION_UPDATE_TEXT; } }); | ||
Object.defineProperty(exports, "KIND_COMPONENT", { enumerable: true, get: function () { return types_1.KIND_COMPONENT; } }); | ||
Object.defineProperty(exports, "KIND_TEXT", { enumerable: true, get: function () { return types_1.KIND_TEXT; } }); | ||
var root_1 = require("./root"); | ||
@@ -15,1 +21,4 @@ Object.defineProperty(exports, "createRemoteRoot", { enumerable: true, get: function () { return root_1.createRemoteRoot; } }); | ||
Object.defineProperty(exports, "RemoteReceiver", { enumerable: true, get: function () { return receiver_1.RemoteReceiver; } }); | ||
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,2 @@ | ||
import { RemoteChannel, RemoteTextSerialization, RemoteComponentSerialization } from './types'; | ||
import type { RemoteChannel, RemoteTextSerialization, RemoteComponentSerialization } from './types'; | ||
declare const ROOT_ID: unique symbol; | ||
@@ -3,0 +3,0 @@ declare type Child = RemoteTextSerialization | RemoteComponentSerialization<any>; |
@@ -18,3 +18,3 @@ "use strict"; | ||
switch (type) { | ||
case types_1.Action.Mount: { | ||
case types_1.ACTION_MOUNT: { | ||
const children = args[0]; | ||
@@ -29,4 +29,4 @@ this.root.children = children; | ||
} | ||
case types_1.Action.RemoveChild: { | ||
const [id = ROOT_ID, index] = args; | ||
case types_1.ACTION_REMOVE_CHILD: { | ||
const [id = ROOT_ID, index,] = args; | ||
const attached = this.attached.get(id); | ||
@@ -43,3 +43,3 @@ const children = [...attached.children]; | ||
} | ||
case types_1.Action.InsertChild: { | ||
case types_1.ACTION_INSERT_CHILD: { | ||
const [id = ROOT_ID, index, child,] = args; | ||
@@ -60,3 +60,3 @@ rpc_1.retain(child); | ||
} | ||
case types_1.Action.UpdateProps: { | ||
case types_1.ACTION_UPDATE_PROPS: { | ||
const [id, newProps] = args; | ||
@@ -76,3 +76,3 @@ const component = this.attached.get(id); | ||
} | ||
case types_1.Action.UpdateText: { | ||
case types_1.ACTION_UPDATE_TEXT: { | ||
const [id, newText] = args; | ||
@@ -79,0 +79,0 @@ const text = this.attached.get(id); |
import { RemoteComponentType } from '@remote-ui/types'; | ||
import { RemoteRoot, RemoteChannel } from './types'; | ||
import type { RemoteRoot, RemoteChannel } from './types'; | ||
export interface Options<AllowedComponents extends RemoteComponentType<string, any>> { | ||
@@ -4,0 +4,0 @@ readonly components: readonly AllowedComponents[]; |
@@ -19,3 +19,3 @@ "use strict"; | ||
const id = `${currentId++}`; | ||
const component = Object.assign({ get children() { | ||
const component = Object.assign({ kind: types_1.KIND_COMPONENT, get children() { | ||
return children.get(component); | ||
@@ -39,3 +39,3 @@ }, get props() { | ||
const id = `${currentId++}`; | ||
const text = Object.assign({ get text() { | ||
const text = Object.assign({ kind: types_1.KIND_TEXT, get text() { | ||
return texts.get(text); | ||
@@ -52,3 +52,3 @@ }, updateText: (newText) => updateText(text, newText) }, {}); | ||
async mount() { | ||
await channel(types_1.Action.Mount, children.get(remoteRoot).map(serialize)); | ||
await channel(types_1.ACTION_MOUNT, children.get(remoteRoot).map(serialize)); | ||
}, | ||
@@ -92,3 +92,3 @@ }; | ||
return perform(text, { | ||
remote: (channel) => channel(types_1.Action.UpdateText, text.id, newText), | ||
remote: (channel) => channel(types_1.ACTION_UPDATE_TEXT, text.id, newText), | ||
local: () => texts.set(text, newText), | ||
@@ -99,3 +99,3 @@ }); | ||
return perform(component, { | ||
remote: (channel) => channel(types_1.Action.UpdateProps, component.id, newProps), | ||
remote: (channel) => channel(types_1.ACTION_UPDATE_PROPS, component.id, newProps), | ||
local: () => { | ||
@@ -109,3 +109,3 @@ props.set(component, Object.freeze(Object.assign(Object.assign({}, props.get(component)), newProps))); | ||
return perform(container, { | ||
remote: (channel) => channel(types_1.Action.InsertChild, container.id, container.children.length, serialize(normalizedChild)), | ||
remote: (channel) => channel(types_1.ACTION_INSERT_CHILD, container.id, container.children.length, serialize(normalizedChild)), | ||
local: () => { | ||
@@ -132,3 +132,3 @@ var _a; | ||
return perform(container, { | ||
remote: (channel) => channel(types_1.Action.RemoveChild, container.id, container.children.indexOf(child)), | ||
remote: (channel) => channel(types_1.ACTION_REMOVE_CHILD, container.id, container.children.indexOf(child)), | ||
local: () => { | ||
@@ -146,3 +146,3 @@ var _a; | ||
return perform(container, { | ||
remote: (channel) => channel(types_1.Action.InsertChild, container.id, container.children.indexOf(before), serialize(child)), | ||
remote: (channel) => channel(types_1.ACTION_INSERT_CHILD, container.id, container.children.indexOf(before), serialize(child)), | ||
local: () => { | ||
@@ -149,0 +149,0 @@ const newTop = container === remoteRoot ? remoteRoot : tops.get(container); |
@@ -8,23 +8,19 @@ import { RemoteComponentType, IdentifierForRemoteComponent, PropsForRemoteComponent } from '@remote-ui/types'; | ||
} ? If : Else; | ||
export declare enum Action { | ||
UpdateText = 0, | ||
UpdateProps = 1, | ||
InsertChild = 2, | ||
RemoveChild = 3, | ||
Mount = 4 | ||
} | ||
export declare enum UpdateOperation { | ||
Insert = 0, | ||
Remove = 1 | ||
} | ||
export declare const ACTION_MOUNT = 0; | ||
export declare const ACTION_INSERT_CHILD = 1; | ||
export declare const ACTION_REMOVE_CHILD = 2; | ||
export declare const ACTION_UPDATE_TEXT = 3; | ||
export declare const ACTION_UPDATE_PROPS = 4; | ||
export declare const UPDATE_INSERT = 0; | ||
export declare const UPDATE_REMOVE = 1; | ||
export declare type Id = string; | ||
export interface MessageMap { | ||
[Action.UpdateText]: [Id, string]; | ||
[Action.UpdateProps]: [Id, object]; | ||
[Action.InsertChild]: [Id | undefined, number, RemoteTextSerialization | RemoteComponentSerialization]; | ||
[Action.RemoveChild]: [Id | undefined, number]; | ||
[Action.Mount]: [(RemoteTextSerialization | RemoteComponentSerialization)[]]; | ||
[ACTION_UPDATE_TEXT]: [Id, string]; | ||
[ACTION_UPDATE_PROPS]: [Id, object]; | ||
[ACTION_INSERT_CHILD]: [Id | undefined, number, RemoteTextSerialization | RemoteComponentSerialization]; | ||
[ACTION_REMOVE_CHILD]: [Id | undefined, number]; | ||
[ACTION_MOUNT]: [(RemoteTextSerialization | RemoteComponentSerialization)[]]; | ||
} | ||
export interface RemoteChannel { | ||
<T extends Action>(type: T, ...payload: MessageMap[T]): void | Promise<void>; | ||
<T extends keyof MessageMap>(type: T, ...payload: MessageMap[T]): void | Promise<void>; | ||
} | ||
@@ -48,3 +44,6 @@ export declare enum RemoteKind { | ||
} | ||
export declare const KIND_COMPONENT = 1; | ||
export declare const KIND_TEXT = 2; | ||
export interface RemoteComponent<Type extends RemoteComponentType<string, any>, Root extends RemoteRoot<any, any>> { | ||
readonly kind: typeof KIND_COMPONENT; | ||
readonly id: string; | ||
@@ -63,2 +62,3 @@ readonly type: IdentifierForRemoteComponent<Type>; | ||
export interface RemoteText<Root extends RemoteRoot<any, any>> { | ||
readonly kind: typeof KIND_TEXT; | ||
readonly id: string; | ||
@@ -71,2 +71,3 @@ readonly text: string; | ||
} | ||
export declare type RemoteChild<Root extends RemoteRoot<any, any>> = RemoteComponent<any, Root> | RemoteText<Root>; | ||
export declare type RemoteComponentSerialization<Type extends RemoteComponentType<string, any> = RemoteComponentType<string, any>> = { | ||
@@ -73,0 +74,0 @@ -readonly [K in 'id' | 'type' | 'props']: RemoteComponent<Type, any>[K]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RemoteComponentViolationType = exports.RemoteKind = exports.UpdateOperation = exports.Action = void 0; | ||
var Action; | ||
(function (Action) { | ||
Action[Action["UpdateText"] = 0] = "UpdateText"; | ||
Action[Action["UpdateProps"] = 1] = "UpdateProps"; | ||
Action[Action["InsertChild"] = 2] = "InsertChild"; | ||
Action[Action["RemoveChild"] = 3] = "RemoveChild"; | ||
Action[Action["Mount"] = 4] = "Mount"; | ||
})(Action = exports.Action || (exports.Action = {})); | ||
var UpdateOperation; | ||
(function (UpdateOperation) { | ||
UpdateOperation[UpdateOperation["Insert"] = 0] = "Insert"; | ||
UpdateOperation[UpdateOperation["Remove"] = 1] = "Remove"; | ||
})(UpdateOperation = exports.UpdateOperation || (exports.UpdateOperation = {})); | ||
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.ACTION_MOUNT = 0; | ||
exports.ACTION_INSERT_CHILD = 1; | ||
exports.ACTION_REMOVE_CHILD = 2; | ||
exports.ACTION_UPDATE_TEXT = 3; | ||
exports.ACTION_UPDATE_PROPS = 4; | ||
exports.UPDATE_INSERT = 0; | ||
exports.UPDATE_REMOVE = 1; | ||
var RemoteKind; | ||
@@ -22,2 +16,4 @@ (function (RemoteKind) { | ||
})(RemoteKind = exports.RemoteKind || (exports.RemoteKind = {})); | ||
exports.KIND_COMPONENT = 1; | ||
exports.KIND_TEXT = 2; | ||
var RemoteComponentViolationType; | ||
@@ -24,0 +20,0 @@ (function (RemoteComponentViolationType) { |
{ | ||
"name": "@remote-ui/core", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"publishConfig": { | ||
@@ -13,3 +13,3 @@ "access": "public", | ||
}, | ||
"gitHead": "45d7f08ef45b89ae23b33111bbc2afa91152cd48" | ||
"gitHead": "118d0e51945ee649e060b0bdb1e186bb52235909" | ||
} |
@@ -11,3 +11,11 @@ export type { | ||
export {createRemoteComponent} from './component'; | ||
export {Action} from './types'; | ||
export { | ||
ACTION_MOUNT, | ||
ACTION_INSERT_CHILD, | ||
ACTION_REMOVE_CHILD, | ||
ACTION_UPDATE_PROPS, | ||
ACTION_UPDATE_TEXT, | ||
KIND_COMPONENT, | ||
KIND_TEXT, | ||
} from './types'; | ||
export type { | ||
@@ -18,2 +26,3 @@ RemoteRoot, | ||
RemoteText, | ||
RemoteChild, | ||
Serialized, | ||
@@ -23,1 +32,2 @@ } from './types'; | ||
export {RemoteReceiver} from './receiver'; | ||
export {isRemoteComponent, isRemoteText} from './utilities'; |
import {retain, release} from '@remote-ui/rpc'; | ||
import { | ||
Action, | ||
ACTION_MOUNT, | ||
ACTION_INSERT_CHILD, | ||
ACTION_REMOVE_CHILD, | ||
ACTION_UPDATE_PROPS, | ||
ACTION_UPDATE_TEXT, | ||
} from './types'; | ||
import type { | ||
MessageMap, | ||
@@ -39,4 +45,4 @@ RemoteChannel, | ||
switch (type) { | ||
case Action.Mount: { | ||
const children = (args as MessageMap[Action.Mount])[0]; | ||
case ACTION_MOUNT: { | ||
const children = (args as MessageMap[typeof ACTION_MOUNT])[0]; | ||
@@ -54,4 +60,7 @@ this.root.children = children; | ||
} | ||
case Action.RemoveChild: { | ||
const [id = ROOT_ID, index] = args as MessageMap[Action.RemoveChild]; | ||
case ACTION_REMOVE_CHILD: { | ||
const [ | ||
id = ROOT_ID, | ||
index, | ||
] = args as MessageMap[typeof ACTION_REMOVE_CHILD]; | ||
@@ -72,3 +81,3 @@ const attached = this.attached.get(id) as Root; | ||
} | ||
case Action.InsertChild: { | ||
case ACTION_INSERT_CHILD: { | ||
const [ | ||
@@ -78,3 +87,3 @@ id = ROOT_ID, | ||
child, | ||
] = args as MessageMap[Action.InsertChild]; | ||
] = args as MessageMap[typeof ACTION_INSERT_CHILD]; | ||
@@ -98,4 +107,4 @@ retain(child); | ||
} | ||
case Action.UpdateProps: { | ||
const [id, newProps] = args as MessageMap[Action.UpdateProps]; | ||
case ACTION_UPDATE_PROPS: { | ||
const [id, newProps] = args as MessageMap[typeof ACTION_UPDATE_PROPS]; | ||
@@ -119,4 +128,4 @@ const component = this.attached.get(id) as RemoteComponentSerialization; | ||
} | ||
case Action.UpdateText: { | ||
const [id, newText] = args as MessageMap[Action.UpdateText]; | ||
case ACTION_UPDATE_TEXT: { | ||
const [id, newText] = args as MessageMap[typeof ACTION_UPDATE_TEXT]; | ||
@@ -123,0 +132,0 @@ const text = this.attached.get(id) as RemoteTextSerialization; |
import {RemoteComponentType} from '@remote-ui/types'; | ||
import { | ||
Action, | ||
ACTION_MOUNT, | ||
ACTION_INSERT_CHILD, | ||
ACTION_REMOVE_CHILD, | ||
ACTION_UPDATE_PROPS, | ||
ACTION_UPDATE_TEXT, | ||
KIND_COMPONENT, | ||
KIND_TEXT, | ||
} from './types'; | ||
import type { | ||
Serialized, | ||
@@ -50,2 +58,3 @@ RemoteRoot, | ||
const component: RemoteComponent<AllowedComponents, Root> = { | ||
kind: KIND_COMPONENT, | ||
get children() { | ||
@@ -87,2 +96,3 @@ return children.get(component); | ||
const text: RemoteText<Root> = { | ||
kind: KIND_TEXT, | ||
get text() { | ||
@@ -108,3 +118,3 @@ return texts.get(text)!; | ||
async mount() { | ||
await channel(Action.Mount, children.get(remoteRoot)!.map(serialize)); | ||
await channel(ACTION_MOUNT, children.get(remoteRoot)!.map(serialize)); | ||
}, | ||
@@ -169,3 +179,3 @@ }; | ||
return perform(text, { | ||
remote: (channel) => channel(Action.UpdateText, text.id, newText), | ||
remote: (channel) => channel(ACTION_UPDATE_TEXT, text.id, newText), | ||
local: () => texts.set(text, newText), | ||
@@ -177,3 +187,3 @@ }); | ||
return perform(component, { | ||
remote: (channel) => channel(Action.UpdateProps, component.id, newProps), | ||
remote: (channel) => channel(ACTION_UPDATE_PROPS, component.id, newProps), | ||
local: () => { | ||
@@ -195,3 +205,3 @@ props.set( | ||
channel( | ||
Action.InsertChild, | ||
ACTION_INSERT_CHILD, | ||
(container as any).id, | ||
@@ -232,3 +242,3 @@ container.children.length, | ||
channel( | ||
Action.RemoveChild, | ||
ACTION_REMOVE_CHILD, | ||
(container as any).id, | ||
@@ -258,3 +268,3 @@ container.children.indexOf(child as any), | ||
channel( | ||
Action.InsertChild, | ||
ACTION_INSERT_CHILD, | ||
(container as any).id, | ||
@@ -261,0 +271,0 @@ container.children.indexOf(before as any), |
@@ -17,14 +17,10 @@ import { | ||
export enum Action { | ||
UpdateText, | ||
UpdateProps, | ||
InsertChild, | ||
RemoveChild, | ||
Mount, | ||
} | ||
export const ACTION_MOUNT = 0; | ||
export const ACTION_INSERT_CHILD = 1; | ||
export const ACTION_REMOVE_CHILD = 2; | ||
export const ACTION_UPDATE_TEXT = 3; | ||
export const ACTION_UPDATE_PROPS = 4; | ||
export enum UpdateOperation { | ||
Insert, | ||
Remove, | ||
} | ||
export const UPDATE_INSERT = 0; | ||
export const UPDATE_REMOVE = 1; | ||
@@ -34,5 +30,5 @@ export type Id = string; | ||
export interface MessageMap { | ||
[Action.UpdateText]: [Id, string]; | ||
[Action.UpdateProps]: [Id, object]; | ||
[Action.InsertChild]: [ | ||
[ACTION_UPDATE_TEXT]: [Id, string]; | ||
[ACTION_UPDATE_PROPS]: [Id, object]; | ||
[ACTION_INSERT_CHILD]: [ | ||
Id | undefined, | ||
@@ -42,8 +38,11 @@ number, | ||
]; | ||
[Action.RemoveChild]: [Id | undefined, number]; | ||
[Action.Mount]: [(RemoteTextSerialization | RemoteComponentSerialization)[]]; | ||
[ACTION_REMOVE_CHILD]: [Id | undefined, number]; | ||
[ACTION_MOUNT]: [(RemoteTextSerialization | RemoteComponentSerialization)[]]; | ||
} | ||
export interface RemoteChannel { | ||
<T extends Action>(type: T, ...payload: MessageMap[T]): void | Promise<void>; | ||
<T extends keyof MessageMap>( | ||
type: T, | ||
...payload: MessageMap[T] | ||
): void | Promise<void>; | ||
} | ||
@@ -136,2 +135,5 @@ | ||
export const KIND_COMPONENT = 1; | ||
export const KIND_TEXT = 2; | ||
export interface RemoteComponent< | ||
@@ -141,2 +143,3 @@ Type extends RemoteComponentType<string, any>, | ||
> { | ||
readonly kind: typeof KIND_COMPONENT; | ||
readonly id: string; | ||
@@ -165,2 +168,3 @@ readonly type: IdentifierForRemoteComponent<Type>; | ||
export interface RemoteText<Root extends RemoteRoot<any, any>> { | ||
readonly kind: typeof KIND_TEXT; | ||
readonly id: string; | ||
@@ -174,2 +178,6 @@ readonly text: string; | ||
export type RemoteChild<Root extends RemoteRoot<any, any>> = | ||
| RemoteComponent<any, Root> | ||
| RemoteText<Root>; | ||
export type RemoteComponentSerialization< | ||
@@ -176,0 +184,0 @@ Type extends RemoteComponentType<string, any> = RemoteComponentType< |
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
363709
58
2582