Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var riot = require('riot');
var curry = _interopDefault(require('curri'));
var jsDOMGlobal = _interopDefault(require('jsdom-global'));
const {addHook} = require('pirates');
const {transform} = require('@babel/core');
const {compile} = require('@riotjs/compiler');
const { CSS_BY_NAME } = riot.__.cssManager;
/**
* Create the renderer function that can produce different types of output from the DOM rendered
* @param {Function} renderer - rendering function
* @param {string} tagName - tag name of the root node
* @param {RiotComponentShell} componentAPI - component shell object
* @param {Object} props - initial props
* @returns {*} output generated by the renderer function
*/
function createRenderer(renderer, tagName, componentAPI, props = {}) {
const cleanup = jsDOMGlobal();
const root = document.createElement(tagName);
const element = riot.component(componentAPI)(root, props);
const result = renderer({
// serialize the component outer html
html: root.outerHTML,
tags.forEach((tag) => {
const component = tag.module.default;
if (component.exports) {
component.exports.state = STATE[component.exports.id || component.name] || component.exports.state;
}
if (!riot.__.globals.COMPONENTS_IMPLEMENTATION_MAP.has(component.name)) {
const rendered = document.querySelector('section[is]')
riot.register(component.name, component)
}
})
const riot = require('riot')
const {SheetsRegistry} = require('jss')
const xss = require("xss")
const DOM = require('jsdom-global')
const {CSS_BY_NAME} = riot.__.cssManager;
/**
* Render a riot tag.
* This method resolves all `fetch()` operations including components children
* TODO: A global store, maybe Mobx?
* @return {Promise<{output: String, state: Object, layout: string}>}
* */
module.exports = async function renderAsync(tagName, component, props, sharedAttributes) {
const cleanup = DOM()
try {
const root = document.createElement(tagName)
const element = riot.component(component)(root, props)
const prop = riot.__.globals.DOM_COMPONENT_INSTANCE_PROPERTY
const stylesheet = new SheetsRegistry()
module.exports = async function renderAsync(tagName, component, props, sharedAttributes) {
const cleanup = DOM()
try {
const root = document.createElement(tagName)
const element = riot.component(component)(root, props)
const prop = riot.__.globals.DOM_COMPONENT_INSTANCE_PROPERTY
const stylesheet = new SheetsRegistry()
let state = {}
let shared = {}
const getShared = (inst) => sharedAttributes.concat(inst.shared || [])
if (element) {
element.req = props.req;
element.res = props.res;
if (element.fetch)
await element.fetch(props);
if (element.onServer)
element.onServer(props.req, props.res, props.next);
state[element.id || component.name] = element.state