Skip to content

Commit

Permalink
update() must return an Array, no ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejewski committed Jul 12, 2017
1 parent 6ff50ee commit d1c5ffd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/make-n-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export function update (msg, state) {
loadModelsForMake(id, ReceiveModels)
]
},
ReceiveModels, models => ({
ReceiveModels, models => [{
...state,
models,
isLoading: false
})
}]
])
}

Expand Down
12 changes: 6 additions & 6 deletions examples/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import message from 'raj/message'
import react from 'raj/react'

export function init () {
return {
return [{
searchQuery: '',
searchResults: [],
isLoading: false,
error: null
}
}]
}

export const ChangeQuery = message()
Expand All @@ -27,17 +27,17 @@ export function update (msg, state) {
searchQuery: query,
isLoading: true
}, fetchResults(query)],
ReceiveResults, results => ({
ReceiveResults, results => [{
...state,
searchResults: results,
isLoading: false,
error: null
}),
ReceiveError, error => ({
}],
ReceiveError, error => [{
...state,
error,
isLoading: false
})
}]
])
}

Expand Down
12 changes: 2 additions & 10 deletions react.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
function marshal (result) {
if (Array.isArray(result)) {
return result
} else {
return [result]
}
}

function program (React, {init, update, view, flags}) {
return class Program extends React.Component {
constructor (props) {
super(props)
this._dispatch = this.dispatch.bind(this)
const [state, effect] = marshal(init(flags, props))
const [state, effect] = init(flags, props)
this.state = state
if (effect) {
this.command(effect)
Expand All @@ -24,7 +16,7 @@ function program (React, {init, update, view, flags}) {

dispatch (message) {
this.setState(oldState => {
const [state, effect] = marshal(update(message, oldState))
const [state, effect] = update(message, oldState)
if (effect) {
this.command(effect)
}
Expand Down

0 comments on commit d1c5ffd

Please sign in to comment.