Skip to content

Instantly share code, notes, and snippets.

@lmatteis
Created April 16, 2018 20:06
Show Gist options
  • Save lmatteis/f9cd438e0908722ec5a1b0de72bbb1e5 to your computer and use it in GitHub Desktop.
Save lmatteis/f9cd438e0908722ec5a1b0de72bbb1e5 to your computer and use it in GitHub Desktop.
Behavioral programming React
const Comments = behavior([
function* () {
const comments = yield fetchComments()
yield { request: FETCH_COMMENTS_SUCCESS, payload: comments }
}
])(Comments)
const CommentsCount = behavior([
function* () {
yield { request: FETCH_COMMENTS_COUNT }
const comments = yield fetchComments()
yield { request: UPDATE_COUNT, payload: comments.length }
}
])(CommentsCount)
// request, wait, block
const CommentsCount = behavior([
function* () {
yield { block: FETCH_COMMENTS_COUNT }
},
function* () {
const comments = yield { wait: FETCH_COMMENTS_SUCCESS }
yield { request: UPDATE_COUNT, payload: comments.length }
}
])(CommentsCount)
function App() {
return [
<Comments />,
<CommentsCount />
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment