Better code structure

This commit is contained in:
Nordine M'LISSA 2018-09-06 21:03:19 +02:00
parent 47ed43ba42
commit 6b5292d342

View File

@ -8,23 +8,28 @@ import icons from './icons.json';
class IconInner extends PureComponent {
createMarkup(markup) {
// sanitize markup first:
let sanitizedMarkup = DOMPurify.sanitize(markup);
// handling server rendering
if (!window) {
// We create a window out of JSDOM
const window = (new JSDOM('')).window;
// Plug it to DOMPurify
const DOMPurifyServer = DOMPurify(window);
// and then sanitize markup
sanitizedMarkup = DOMPurifyServer.sanitize(markup);
}
const sanitizedMarkup = this.sanitizeMarkup(markup);
// now do the weird thing for dangerouslySetInnerHTML
return { __html: sanitizedMarkup };
}
sanitizeMarkup(markup) {
// For server environement
if (!window) {
// We create a window out of JSDOM
const window = (new JSDOM('')).window;
// Then we plug it to DOMPurify
const DOMPurifyServer = DOMPurify(window);
// and finally sanitize the markup
return DOMPurifyServer.sanitize(markup);
}
// Sanitize the markup
return DOMPurify.sanitize(markup);
}
render() {
// <g> is just a wrapper it does nothing except let me use valid JSX markup
// icons are based on generated icons.json from feather lib