-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const React = require('react') | ||
const ReactDOM = require('react-dom') | ||
const decamelize = require('decamelize') | ||
const htmlModuleLoader = require('./htmlModuleLoader') | ||
const syncEvent = require('./syncEvent') | ||
|
||
module.exports = function(tagName, url) { | ||
return class ReactComponent extends React.Component { | ||
static displayName = tagName | ||
|
||
componentDidMount() { | ||
this.componentWillReceiveProps(this.props) | ||
htmlModuleLoader(url, () => { | ||
this.componentWillReceiveProps(this.props) | ||
}, function(e) { | ||
console.err('Load html module failed:', e) | ||
}) | ||
} | ||
|
||
componentWillReceiveProps(props) { | ||
const node = ReactDOM.findDOMNode(this) | ||
Object.keys(props).forEach(key => { | ||
if (key === 'children' || key === 'style') return | ||
|
||
if (props[key] === node[key]) return | ||
|
||
if (key.indexOf('on') === 0 && key[2] === key[2].toUpperCase()) { | ||
syncEvent(node, decamelize(key.substring(2), '-'), props[key]) | ||
} else { | ||
node[key] = props[key] | ||
} | ||
}) | ||
} | ||
|
||
render() { | ||
return React.createElement(tagName, { style: this.props.style }, this.props.children) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = function(meta) { | ||
return ("var React = require('react')\nvar ReactDOM = require('react-dom')\nvar syncEvent = require('html-imports-loader/react/syncEvent')\nvar htmlModuleLoader = require('html-imports-loader/react/htmlModuleLoader')\n\nmodule.exports = (function (superclass) {\n function ReactComponent () {\n superclass.apply(this, arguments);\n }\n\n if ( superclass ) ReactComponent.__proto__ = superclass;\n ReactComponent.prototype = Object.create( superclass && superclass.prototype );\n ReactComponent.prototype.constructor = ReactComponent;\n\n var staticAccessors = { displayName: {} };\n\n staticAccessors.displayName.get = function () {\n return '" + (meta.tagName) + "';\n };\n ReactComponent.prototype.componentDidMount = function componentDidMount () {\n var this$1 = this;\n\t this$1.componentWillReceiveProps(this$1.props);\n htmlModuleLoader(['" + (meta.url) + "'], function () {\n this$1.componentWillReceiveProps(this$1.props);\n }, function(e) {\n console.err('Load html module failed:', e)\n });\n };\n ReactComponent.prototype.componentWillReceiveProps = function componentWillReceiveProps (props) {\n var node = ReactDOM.findDOMNode(this);\n Object.keys(props).forEach(function (name) {\n if (name === 'children' || name === 'style') {\n return;\n }\n\n if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {\n syncEvent(node, name.substring(2), props[name]);\n } else {\n node[name] = props[name];\n }\n });\n };\n ReactComponent.prototype.render = function render () {\n return React.createElement('" + (meta.tagName) + "', { style: this.props.style }, this.props.children);\n };\n\n Object.defineProperties( ReactComponent, staticAccessors );\n\n return ReactComponent;\n}(React.Component))") | ||
return ("var componentGenerator = require('babel-loader!html-imports-loader/react/componentGenerator'); module.exports = componentGenerator(\"" + meta.tagName + "\", \"" + meta.url + "\")") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters