one
Version:
One is a React framework for web, iOS, and Android apps.
103 lines (101 loc) • 3.79 kB
JavaScript
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)
})}`;
}
export { methodSubscribed, methodWired, renderMethodCall, renderViewWires, toNativeSourceStructs };
//# sourceMappingURL=nativeSourceWires.native.js.map