Created
June 2, 2019 07:38
-
-
Save zenius/a622acb5125448fcb2ce4e480104dc7e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const Feact = { | |
createElement(type, props, children) { | |
const element = { | |
type, | |
props: props || {} | |
}; | |
if (children) { | |
element.props.children = children; | |
} | |
return element; | |
}, | |
render(element, container) { | |
const componentInstance = new FeactDOMComponent(element); | |
return componentInstance.mountComponent(container); | |
} | |
}; | |
Elements are just simple objects representing something we want rendered. | |
class FeactDOMComponent { | |
constructor(element) { | |
this._currentElement = element; | |
} | |
mountComponent(container) { | |
const domElement = | |
document.createElement(this._currentElement.type); | |
const text = this._currentElement.props.children; | |
const textNode = document.createTextNode(text); | |
domElement.appendChild(textNode); | |
container.appendChild(domElement); | |
this._hostNode = domElement; | |
return domElement; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment