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

RFC #79

Open
1 of 8 tasks
lexich opened this issue Jun 6, 2016 · 6 comments
Open
1 of 8 tasks

RFC #79

lexich opened this issue Jun 6, 2016 · 6 comments
Assignees

Comments

@lexich
Copy link
Owner

lexich commented Jun 6, 2016

Typical cases.

  • authorization chain
  • integration with redux-persist
  • websockets
  • Internal api in helpers
  • integration with 3d party serialization

Feature requests.

@lexich lexich changed the title Describe typical cases. RFC: Describe typical cases. Jun 6, 2016
@lexich lexich self-assigned this Jun 6, 2016
@lexich
Copy link
Owner Author

lexich commented Jun 16, 2016

c6b2eb0 JWT authorization

@wvengen
Copy link
Contributor

wvengen commented Oct 10, 2016

Performing multiple calls to the same endpoint may also be a useful case. I've documented my approach here, for anyone interested: https://gist.github.com/wvengen/39b561607691e33bc0db050264ebc1e7

@lexich
Copy link
Owner Author

lexich commented Oct 10, 2016

@wvengen very good example. Would you like to move you example to docs/MultipleCalls.md?

@lexich
Copy link
Owner Author

lexich commented Oct 10, 2016

@wvengen
What do you think about more complicated way?

// a basic redux-api rest store
import reduxApi from 'redux-api';
import adapterFetch from "redux-api/lib/adapters/fetch";

export default ReduxApi({
  productCategories: {
    url: '/api/v1/products/categories',
    postfetch: [
        function({data, actions, dispatch, getState, request}) {
            if (!data) { return [];}
            const { categories } = data;
            if (!categories) { return [];}
            const requests = categories.map(({id}) => {
                const requestParams = { .... };    
                return actions.productHistogram.request(requestParams);
            });

            // It very interesting place, maybe postfetch should process Promise
            // This allow save all products information in categories
            Promise.all(requests).then((data)=> {
                dispatch({ type: "PRODUCTS_UPTATES", data })
            });
        }
    ]

  },
  productHistogram: {
    url: '/api/v1/products/histogram',
    virtual: true,
    transformer: (data) => (data || {}).products_histogram,
  },
}).use('fetch', adapterFetch(fetch));

@lexich lexich changed the title RFC: Describe typical cases. RFC Aug 10, 2017
@mkoppanen
Copy link

mkoppanen commented Aug 21, 2017

My typical use-case includes chaining update and fetching a full list after the update. I can achieve this currently with helpers but having something like postfetch that would delay resolving the original action would simplify the code a lot.

I have "list" and "update" actions separately and currently I need to have the "updateAndFetchList" helper under the "list", which makes it a bit confusing. Currently postfetch is not blocking the resolution of the original action and thus there is a small race condition between update and list being refetched.

I have considered using one reducer but then I lose being able to separate "what" is loading / having error.

@lexich
Copy link
Owner Author

lexich commented Aug 21, 2017

Hi @mkoppanen can you create new issue with example of you code. I'll try to help you.

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

3 participants