Skip to content

Commit

Permalink
Merge pull request #7 from andrejewski/all-view
Browse files Browse the repository at this point in the history
Align runtime and React view functions
  • Loading branch information
andrejewski authored Jul 22, 2017
2 parents ce363aa + b2f34f2 commit c1d27ef
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ npm install raj
- `effect.map(mapper, effect)`: transforms the dispatched values of `effect` using the function `mapper`
- `effect.batch(effects)`: group an array of effects into a single effect
- `raj/runtime`: create generic runtimes
- `program({init, update, renderer})`
- `program({init, update, view})`
- `init`: the initial state and optional effect
- `update(message, state)`: return the new state and optional effect
- `renderer(state, dispatch)`: use the state and dispatch messages
- `view(state, dispatch)`: use the state and dispatch messages

#### Integrations
- `raj/react`: React bindings
Expand Down
2 changes: 1 addition & 1 deletion react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function reactProgram (Component, {init, update, view}) {
program({
init: init(props),
update,
renderer: (dispatch, state) => {
view: (state, dispatch) => {
this._dispatch = dispatch
if (initial) {
this.state = {state}
Expand Down
4 changes: 2 additions & 2 deletions runtime.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function program ({init, update, renderer}) {
function program ({init, update, view}) {
let state

function change ([newState, effect]) {
state = newState
if (effect) {
setTimeout(() => effect(dispatch), 0)
}
renderer(dispatch, state)
view(state, dispatch)
}

function dispatch (message) {
Expand Down
8 changes: 4 additions & 4 deletions test/runtime.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import test from 'ava'
import {program} from '../runtime'

test('program() should call renderer() initially', t => {
test('program() should call view() initially', t => {
const initialState = 1
return new Promise(resolve => {
program({
init: [initialState],
renderer (dispatch, state) {
view (state) {
t.is(state, initialState)
resolve()
}
})
})
})

test('program() should call renderer() after dispatch', t => {
test('program() should call view() after dispatch', t => {
let count = 0
return new Promise(resolve => {
program({
init: ['init'],
update (msg) {
return [msg]
},
renderer (dispatch, state) {
view (state, dispatch) {
count++
if (state === 'init') {
return dispatch('next')
Expand Down

0 comments on commit c1d27ef

Please sign in to comment.