Created
April 16, 2018 20:06
-
-
Save lmatteis/f9cd438e0908722ec5a1b0de72bbb1e5 to your computer and use it in GitHub Desktop.
Behavioral programming React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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