Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((responseText) => {
if (typeof this.props.onParseBefore === 'function') {
this.props.onParseBefore(url);
}
let doc = this.parser.parseFromString(responseText);
let error = false;
const stylesheets = Stylesheets.createStylesheets(doc);
this.navigation.setRouteKey(url, routeKey);
// Make sure the XML has the required elements: , , .
const docElement = getFirstTag(doc, 'doc');
if (!docElement) {
console.error(`No tag found in the response from ${url}.`);
doc = null;
error = true;
} else {
const screenElement = getFirstTag(docElement, 'screen');
if (!screenElement) {
console.error(`No tag found in the tag from ${url}.`);
doc = null;
error = true;
} else {
const bodyElement = getFirstTag(screenElement, 'body');
if (!bodyElement) {
console.error(`No tag found in the tag from ${url}.`);
doc = null;
error = true;
this.navigation.setRouteKey(url, routeKey);
// Make sure the XML has the required elements: , , .
const docElement = getFirstTag(doc, 'doc');
if (!docElement) {
console.error(`No tag found in the response from ${url}.`);
doc = null;
error = true;
} else {
const screenElement = getFirstTag(docElement, 'screen');
if (!screenElement) {
console.error(`No tag found in the tag from ${url}.`);
doc = null;
error = true;
} else {
const bodyElement = getFirstTag(screenElement, 'body');
if (!bodyElement) {
console.error(`No tag found in the tag from ${url}.`);
doc = null;
error = true;
}
}
}
this.setState({
doc,
styles: stylesheets,
error,
});
if (typeof this.props.onParseAfter === 'function') {
this.props.onParseAfter(url);
}
if (typeof this.props.onParseBefore === 'function') {
this.props.onParseBefore(url);
}
let doc = this.parser.parseFromString(responseText);
let error = false;
const stylesheets = Stylesheets.createStylesheets(doc);
this.navigation.setRouteKey(url, routeKey);
// Make sure the XML has the required elements: , , .
const docElement = getFirstTag(doc, 'doc');
if (!docElement) {
console.error(`No tag found in the response from ${url}.`);
doc = null;
error = true;
} else {
const screenElement = getFirstTag(docElement, 'screen');
if (!screenElement) {
console.error(`No tag found in the tag from ${url}.`);
doc = null;
error = true;
} else {
const bodyElement = getFirstTag(screenElement, 'body');
if (!bodyElement) {
console.error(`No tag found in the tag from ${url}.`);
doc = null;
error = true;
}
}
}
this.setState({
doc,
function createStylesheet(
document: Document,
modifiers = {},
): StyleSheetType<*> {
const styles = getFirstTag(document, 'styles');
const stylesheet = {};
if (styles) {
const styleElements = styles.getElementsByTagNameNS(
Namespaces.HYPERVIEW,
'style',
);
for (let i = 0; i < styleElements.length; i += 1) {
const styleElement = styleElements.item(i);
const hasModifier =
styleElement.parentNode &&
styleElement.parentNode.tagName === 'modifier';
let styleId = styleElement.getAttribute('id');
if (hasModifier) {
// TODO(adam): Use less hacky way to get id of parent style element.
return (templateName: string, render: any) => {
const templatePath = `${componentPath}/stories/${templateName}.xml`;
const storyName = humps.pascalize(templateName);
const parser = new DOMParser();
const document = parser.parseFromString(templates[templatePath]);
const element = getFirstTag(document, Component.localName);
const stylesheets = Stylesheets.createStylesheets(document);
s.add(storyName, () => render({ element, stylesheets }));
};
};