Update Component.md

This commit is contained in:
Gaëtan Renaudeau 2015-08-28 11:29:55 +02:00
parent ab7677f53a
commit adf86f73d5

View File

@ -13,12 +13,28 @@ class MyEffect extends GL.Component {
`GL.Component` allows to **compose** effects:
it tells the `gl-react-core` algorithm to "unfold" the `render()` looking for a `GL.View` to merge with.
> Technically, this is not required to extend `GL.Component` (you can still use `React.Component`),
but this is generally a good idea (you always want to make a component "composable").
> Although it is technically not required to extend `GL.Component` (you can still use `React.Component`),
this is generally a good idea because you always want to make a component "composable".
## Composing effects
Once you have defined your component that inject children, you can then compose it with another.
Effects component can be implemented as follow:
```js
// Assuming we have defined a shaders.myEffect, where the frag have:
// a `tex` sampler2D uniform
// a `someParam` uniform
class MyEffect extends GL.Component {
render () {
const { width, height, children, someParam } = this.props;
return <GL.View shader={shaders.myEffect} width={width} height={height} uniforms={{ someParam }}>
<GL.Target uniform="tex">{children}</GL.Target>
</GL.View>;
}
}
```
Once you have defined effect components that inject `children` (let's say `Blur` and `Negative`), you can compose them together.
**Example:**
@ -30,7 +46,7 @@ Once you have defined your component that inject children, you can then compose
</Blur>
```
and you can make generic component out of it:
and define another generic component out of it:
```js
class BlurNegative extends GL.Component {