UNPKG

pandora-hub

Version:

pandora.js messenge hub

48 lines 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ObjectProxyBehaviourManager_1 = require("./ObjectProxyBehaviourManager"); const OBJECT_CONSUMER = Symbol(); const BEHAVIOUR = Symbol(); /** * DefaultObjectProxy * To make a Object Proxy by Introspection for Remote Object */ class DefaultObjectProxy { constructor(objectConsumer, introspection) { this[OBJECT_CONSUMER] = objectConsumer; this[BEHAVIOUR] = ObjectProxyBehaviourManager_1.ObjectProxyBehaviourManager.getInstance().getBehaviour(objectConsumer.objectDescription); const methods = introspection.methods; for (const method of methods) { this[method.name] = (...params) => { return this[BEHAVIOUR].proxy.invoke(this, objectConsumer, method.name, params); }; } const properties = introspection.properties; for (const property of properties) { Object.defineProperty(this, property.name, { get: function () { throw new Error(`Use 'await proxy.getProperty('${property.name}')' to replace 'proxy.${property.name}' when using IPC Object Proxy`); }, set: function () { throw new Error(`Use 'await proxy.getProperty('${property.name}')' to replace 'proxy.${property.name}' when using IPC Object Proxy`); } }); } } /** * Get a property from Remote Object * @param {string} name * @return {Promise<any>} */ getProperty(name) { return this[BEHAVIOUR].proxy.getProperty(this, this[OBJECT_CONSUMER], name); } subscribe(register, fn) { return this[BEHAVIOUR].proxy.subscribe(this, this[OBJECT_CONSUMER], register, fn); } unsubscribe(register, fn) { return this[BEHAVIOUR].proxy.unsubscribe(this, this[OBJECT_CONSUMER], register, fn); } } exports.DefaultObjectProxy = DefaultObjectProxy; //# sourceMappingURL=DefaultObjectProxy.js.map