Functionnal React-like.
TO-DO:
- finish API
change_fiber
to_ref
- add examples
- add tests
- add boilerplate (with JSX support) on another repo
rewritepatchNode
algorithm in order to optimized it- benchmarking
import Composant, { render } from 'composant'
const App = (props) => (
<div>
Hello {props.name}!!
</div>
)
render(<App name="world" />, document.querySelector('#app'))
Lifecycle events are props that can be implemented only on component.
import Composant from 'composant'
const Header = (props) => (
<header>
<h3>{props.title}</h3>
</header>
)
const App = (props) => (
<div>
<Header
onMount={initialProps => console.log('initialProps:', initialProps)}
onUpdate={(lastProps, nextProps) => console.log(lastProps, nextProps)}
onUnmount={finalProps => console.log('finalProps:', initialProps)}
/>
Hello {props.name}!!
</div>
)
...
To avoid declaring lifecycle events in the parent rendering an HOC
can wrap your component.
import Composant from 'composant'
const withLifecycles = lifecycles => ComponentToWrap => props => (
<ComponenToWrap
{...lifecycles}
{...props}
/>
)
const Header = (props) => (
<header>
<h3>{props.title}</h3>
</header>
)
const HeaderWithLifecycles = withLifecycles({
onMount: initialProps => console.log('initialProps:', initialProps),
onUpdate: (lastProps, nextProps) => console.log(lastProps, nextProps),
onUnmount: finalProps => console.log('finalProps:', initialProps)
})(Header)
const App = (props) => (
<div>
<HeaderWithLifecycles />
Hello {props.name}!!
</div>
)
...
JSX is an XML-like syntax extension to ECMAScript without any defined semantics.
To implement JSX
to your project the babel
plugin transform-react-jsx
have to be configured with the pragma
property set to Composant
Example:
"plugins": [
[
"transform-react-jsx",
{
"pragma": "Composant"
}
]
]