CodeYellowBV / mobx-spine

MobX with support for models, relations and an external API.
31 stars 14 forks source link

Make it easier to use backend filters #48

Open SpaceK33z opened 7 years ago

SpaceK33z commented 7 years ago

Sometimes you want to fetch a store from the backend but with some filters applied.

Our Django-Binder stack has a lot of auto-generated filters. To filter a store on a customer id we can do something like this:

const store = new Store();

store.params = {'.customer': customer.id };
store.fetch();

For a customer filter the backend has defined it looks about the same;

const store = new Store();

store.params = {'.leaves_for_customer': customer.id };
store.fetch();

The syntax for defining this is a bit weird + doesn't use camelCasing. We can perhaps fix it to look like this;

store.addFilter('leavesForCustomer', customer.id);
store.removeFilter('leavesForCustomer');
SpaceK33z commented 7 years ago

Note: think about how to implement filters like '.customer:isnull': true

SpaceK33z commented 7 years ago

Some other notes:

SpaceK33z commented 7 years ago

Another idea, taking into account the notes above:

store.setParam(Params.FILTER_RANGE, 'startDate', [moment(), moment()]);
store.setParam(Params.FILTER_CUSTOM, 'deleted', true);
store.setParam(Params.SORT_ASC, 'pastOwner.lastName');

Problem with this;