UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

131 lines (129 loc) • 4.78 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var nativeSourceWires_exports = {}; __export(nativeSourceWires_exports, { methodSubscribed: () => methodSubscribed, methodWired: () => methodWired, renderMethodCall: () => renderMethodCall, renderViewWires: () => renderViewWires, toNativeSourceStructs: () => toNativeSourceStructs }); module.exports = __toCommonJS(nativeSourceWires_exports); function toNativeSourceStructs(structs) { var out = {}; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = (structs !== null && structs !== void 0 ? structs : [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var struct = _step.value; out[struct.name] = { fields: struct.fields.map(function(field) { return field.wire === void 0 ? { name: field.name, optional: field.optional } : { name: field.name, optional: field.optional, wire: field.wire }; }) }; } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return out; } function methodWired(method) { return method.parameters.some(function(param) { return param.wire; }) || method.resultWire !== void 0; } function methodSubscribed(method) { return method.subscription !== void 0; } function renderMethodCall(target, method, hash) { var _method_resultWire; if (method.subscription) { var payload = method.subscription; var payloadWires = JSON.stringify(payload.payload.map(function(arg) { var _arg_wire; return (_arg_wire = arg.wire) !== null && _arg_wire !== void 0 ? _arg_wire : null; })); return `${method.name}: (listener) => subscribeNativeSourceEvent(${JSON.stringify(target)}, ${JSON.stringify(method.name)}, listener, ${JSON.stringify(hash)}, ${payloadWires}, nativeSourceStructs)`; } if (!methodWired(method)) { return `${method.name}: (...args) => callNativeSource(${JSON.stringify(target)}, ${JSON.stringify(method.name)}, args, ${JSON.stringify(hash)})`; } var paramWires = JSON.stringify(method.parameters.map(function(param) { var _param_wire; return (_param_wire = param.wire) !== null && _param_wire !== void 0 ? _param_wire : null; })); var resultWire = JSON.stringify((_method_resultWire = method.resultWire) !== null && _method_resultWire !== void 0 ? _method_resultWire : null); return `${method.name}: (...args) => callNativeSource(${JSON.stringify(target)}, ${JSON.stringify(method.name)}, encodeNativeSourceArgs(args, ${paramWires}, nativeSourceStructs), ${JSON.stringify(hash)}).then((value) => decodeNativeSourceResult(value, ${resultWire}, nativeSourceStructs))`; } function renderViewWires(view, structs) { var props = {}; var callbacks = {}; var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; try { for (var _iterator = view.props[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var prop = _step.value; if (prop.wire) props[prop.name] = prop.wire; if (prop.callback && prop.callback.some(function(arg) { return arg.wire; })) { callbacks[prop.name] = prop.callback.map(function(arg) { var _arg_wire; return (_arg_wire = arg.wire) !== null && _arg_wire !== void 0 ? _arg_wire : null; }); } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } if (Object.keys(props).length === 0 && Object.keys(callbacks).length === 0) return ""; return `, wires: ${JSON.stringify({ props, callbacks, structs: toNativeSourceStructs(structs) })}`; }