Skip to content

Instantly share code, notes, and snippets.

@lysenkooo
Created August 12, 2019 08:05
Show Gist options
  • Save lysenkooo/252ae36bbf390bab0064db9dac7fd96c to your computer and use it in GitHub Desktop.
Save lysenkooo/252ae36bbf390bab0064db9dac7fd96c to your computer and use it in GitHub Desktop.
import React from 'react'
const originalCreateElement = React.createElement
React.createElement = (el, props, ...children) => {
if (el.name === 'Provider') {
React.createElement.cond_stack = []
} else if (props) {
if (props.hasOwnProperty('if')) {
React.createElement.cond_stack.push(props['if'])
if (props['if']) {
delete props['if']
return originalCreateElement(el, props, ...children)
} else {
return null
}
} else if (props.hasOwnProperty('else')) {
if (React.createElement.cond_stack.pop()) {
return null
} else {
delete props['else']
return originalCreateElement(el, props, ...children)
}
} else if (props.hasOwnProperty('show-if')) {
if (props['show-if']) {
delete props['show-if']
return originalCreateElement(el, props, ...children)
} else {
return null
}
} else if (props.hasOwnProperty('do-case')) {
React.createElement.cond_stack.push(props['do-case'])
if (props['do-case']) {
delete props['do-case']
return originalCreateElement(el, props, ...children)
} else {
return null
}
} else if (props.hasOwnProperty('case')) {
if (!React.createElement.cond_stack[React.createElement.cond_stack.length - 1] && props['case']) {
React.createElement.cond_stack[React.createElement.cond_stack.length - 1] = true
delete props['case']
return originalCreateElement(el, props, ...children)
} else {
return null
}
} else if (props.hasOwnProperty('end-case')) {
if (!React.createElement.cond_stack.pop() && props['end-case']) {
delete props['end-case']
return originalCreateElement(el, props, ...children)
} else {
return null
}
}
}
return originalCreateElement(el, props, ...children)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment