Skip to content

Commit 97fbbf5

Browse files
author
pemrouz
committed
doc: update component signatures
1 parent f6588cf commit 97fbbf5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

README.md

+16-12
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,24 @@ Use it on the page:
3030
Ripple is agnostic to _how_ you write your components, they should just be idempotent (a single render function). This is fine:
3131

3232
```js
33-
ripple('my-app', (d, i, el) => el.innerHTML = 'Hello World')
33+
ripple('my-app', (node, data) => node.innerHTML = 'Hello World')
3434
```
3535

3636
Or using some DOM-diff helper:
3737

3838
```js
39-
ripple('my-app', (d, i, el) => diff(el)`<h1>Hello World</h1>`)
39+
ripple('my-app', (node, data) => jsx(node)`<h1>Hello World</h1>`)
4040
```
4141

4242
Or using [once](https://github.com/utilise/once#once)/D3 joins:
4343

4444
```js
45-
ripple('my-app', (d, i, el) => {
46-
once(el)
45+
ripple('my-app', (node, data) => {
46+
47+
once(node)
4748
('h1', 1)
4849
.text('Hello World')
50+
4951
})
5052
```
5153

@@ -54,10 +56,12 @@ For more info about writing idempotent components, see [this spec](https://githu
5456
<br>
5557
## State/Data
5658

57-
The first parameter of the component contains all the state and data the component needs to render:
59+
The first parameter of the component is the node to update.
60+
61+
The second parameter contains all the state and data the component needs to render:
5862

5963
```js
60-
export default function component(data){ ... }
64+
export default function component(node, data){ ... }
6165
```
6266

6367
You can pass down data by adding the name of the resources to the data attribute:
@@ -161,13 +165,13 @@ Dispatch an event on the root element to communicate changes to parents (`node.d
161165
Just invoke a redraw of your application when the route has changed:
162166

163167
```js
164-
export function app(d, i, el){
165-
const o = once(el)
168+
export function app(node, data){
169+
const o = once(node)
166170

167171
o('h1', 1)
168172
.text('You are currently on: ' + location.pathname)
169173

170-
window.on('change', d => el.draw())
174+
window.on('change', d => node.draw())
171175
}
172176
```
173177

@@ -232,12 +236,12 @@ By default the draw function just invokes the function on an element. You can ex
232236

233237
```js
234238
// in component
235-
export default function component(d, i, el){
239+
export default function component(node, data){
236240
middleware(d, i, el)
237241
}
238242

239243
// around component
240-
export default middleware(function component(d, i, el){
244+
export default middleware(function component(node, data){
241245

242246
})
243247

@@ -288,7 +292,7 @@ ripple('some.css', `:host { background: red }`)
288292
<br>
289293
## Fullstack
290294

291-
If you have a backed for your frontend, checkout [rijs/fullstack](https://github.com/rijs/fullstack) which transparently adds a few more modules to synchronise state between client-server or for more docs.
295+
If you have a backend for your frontend, checkout [rijs/fullstack](https://github.com/rijs/fullstack) which transparently adds a few more modules to synchronise state between client-server or for more docs.
292296

293297
You can also adjust your own framework by [adding/removing modules](https://github.com/rijs/minimal/blob/master/src/index.js#L1-L11).
294298

0 commit comments

Comments
 (0)