Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Add a page to demonstrate HTTP #27

Open
SteveALee opened this issue Aug 16, 2017 · 0 comments
Open

[Suggestion] Add a page to demonstrate HTTP #27

SteveALee opened this issue Aug 16, 2017 · 0 comments

Comments

@SteveALee
Copy link
Contributor

Another FAQ is using HTTP to fetch data so it would be good to add a 'Fetcher' component as a 3rd page.

  • Just a suimple 'Fetch Button
  • Call a simple API - @staltz used one tha twas a list of starwrs characters or similar
  • Display results - possibly as a child list of collapsable so addressing another FAQ
  • Handle errors

Some code suggestions (assuming JSON payload)

    const request$ = action$.map(accessToken => ({
        url: <API_CALL>,
        method: 'get',
        category: 'request'
    }))

    const response$$ = HTTP.select('request-photos')
    const photos$ = response$$
        .map(response$ =>
            response$.replaceError((error: any) => {
                return xs.of(
                    error.response ? error.reponse : { error, body: {} }
                )
            })
        )
        .flatten()
        .map<Reducer>(({ error, body }) => state => ({
            ...state,
            error: error.message,
            body
        }))

function view(state$: Stream<State>): Stream<VNode> {
    return state$
        .map(state => (state.error ? state.error : state.body))
        .map(result =>
            <div>
               <div className="result">
                    {result}
                </div>
            </div>
        )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants