FormidableLabs / freactal

Clean and robust state management for React and React-like libs.
MIT License
1.65k stars 46 forks source link

Fix example effects in README.md. #21

Closed zebulonj closed 7 years ago

zebulonj commented 7 years ago

If I’m reading the documentation correctly, and an effect is a “(1) function that … returns (2) a promise that resolves to (3) a function that takes in state and returns (4) the updated state,” then I think the second and third examples are wrapping the state transform in the Promise in the wrong order… reversing (2) and (3).

See: https://github.com/FormidableLabs/freactal#transforming-state-cont

My changes are consistent with the subsequent README example:

updatePosts: () => fetch("/api/posts")
  .then(result => result.json())
  .then(({ posts }) => state => Object.assign({}, state, { posts }))

... in that the state => transform( state ) is what the Promise resolves to.

I'm brand new to this repo, so forgive me if this pull request is premature.

divmain commented 7 years ago

Thank you!