UNPKG

@builder.io/mitosis

Version:

Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io

26 lines (25 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processHttpRequests = void 0; function processHttpRequests(json) { var _a, _b; const httpRequests = (_b = (_a = json === null || json === void 0 ? void 0 : json.meta) === null || _a === void 0 ? void 0 : _a.useMetadata) === null || _b === void 0 ? void 0 : _b.httpRequests; if (httpRequests) { for (const key in httpRequests) { if (!json.state[key]) { json.state[key] = { code: 'null', type: 'property', propertyType: 'normal' }; } const value = httpRequests[key]; // TODO: unravel our proxy. aka parse out methods, header, etc // and remove our proxy from being used anymore json.hooks.onMount.push({ code: ` fetch("${value}").then(res => res.json()).then(result => { state.${key} = result; }) `, }); } } } exports.processHttpRequests = processHttpRequests;