cantierecreativo / redux-bees

A nice, short and declarative way to interact with JSON APIs
592 stars 41 forks source link

Update baseUrl to also accept a function #15

Closed ifiokjr closed 7 years ago

ifiokjr commented 7 years ago

This allows apps to dynamically update the baseUrl within the application runtime.

Customize baseUrl

In some applications, the URL Endpoint may change during runtime. To help with this scenario the baseUrl config option can either be a String or Function.

import store from './store';

const config = {
  baseUrl() {
    return `${store.getState().app.endpoint}`
  }
};

This is a requirement for our application which has multiple staging servers that can be dynamically updated during usage. Trying to manage that without enabling the URL to be passed in as a function, would have required an extensive code refactor.

ifiokjr commented 7 years ago

@danbovey any updates on whether this can be merged?

ifiokjr commented 7 years ago

I've added a second commit which now encodes the URL placeholders being sent to the server. There is a problem when using libraries like fortune.js which generates models with id's like id: /f9XL5u+VDM426bToRc1.

Currently, redux-bees implements the placeholder as-is and it seems like a good idea to either provide an option on whether to encode the placeholder or, do it by default. This is quite an urgent fix for me, so I just did it by default. However, I'm happy to add it as an option so that it is not a breaking change.

stefanoverna commented 7 years ago

Released in 0.1.3