Skip to content

Instantly share code, notes, and snippets.

@nfcampos
Last active March 9, 2016 10:00
Show Gist options
  • Save nfcampos/855bfa9e62fe604b5fa8 to your computer and use it in GitHub Desktop.
Save nfcampos/855bfa9e62fe604b5fa8 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
const realCreateElement = React.createElement
const Components = new Set()
const patchPrototype = (Component) => {
Components.add(Component)
for (const method of Object.keys(Component.prototype)) {
if (typeof Component.prototype[method] == 'function') {
const bind = (ctx, ...boundArgs) => {
const fn = (...args) => {
return Component.prototype[method].call(ctx, ...boundArgs, ...args)
}
fn.bind = bind
return fn
}
Component.prototype[method].bind = bind
}
}
}
React.createElement = function createElement(type, ...args) {
if (React.Component.prototype.isPrototypeOf(type) && !Components.has(type)) {
patchPrototype(type)
}
return realCreateElement(type, ...args)
}
// actually this still doesn't work for eg. flux store listeners (I think)
// but I think I know how to make it work
// (ie. how to make sure Component.prototype[method] always points to the same reference)
{
"name": "esnextbin-sketch",
"version": "0.0.0"
}
/*
unknown: Property id of VariableDeclarator expected node to be of a type ["LVal"] but instead got null
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment