feathersjs-ecosystem / feathers-redux

Integrate Feathers with your Redux store
MIT License
114 stars 23 forks source link

Export action types #29

Closed amaury1093 closed 7 years ago

amaury1093 commented 7 years ago

Summary

This PR exports all the action types used by the reduxified services, and put them in the types field.

const services = reduxifyServices(app, ['messages']);
console.log(services.types);

// Will output:
{
  SERVICES_MESSAGES_FIND: 'SERVICES_MESSAGES_FIND',
  SERVICES_MESSAGES_FIND_PENDING: 'SERVICES_MESSAGES_FIND_PENDING',
  SERVICES_MESSAGES_FIND_FULFILLED: 'SERVICES_MESSAGES_FIND_FULFILLED',
  SERVICES_MESSAGES_FIND_REJECTED: 'SERVICES_MESSAGES_FIND_REJECTED',
 // ... same for CREATE, GET etc
}

Why is this useful?

In some apps, it might be useful to listen to actions dispatched by feathers-redux, for example for managing side-effects.

Right now, to listen to actions dispatched by feathers-redux, we listen to the string directly. An example with redux-saga would be: yield take('SERVICES_MESSAGES_CREATE_FULFILLED', doSomethingSaga);

After this PR, it would be yield take(services.types.SERVICES_MESSAGES_CREATE_FULFILLED, doSomethingSaga)

The big advantage is to avoid putting raw strings everywhere in the code (bad practice).

Other Information

If this is useful, I'll update some docs too.

eddyystop commented 7 years ago

I guess this repo is reaching some level of maturity. :) Thanks.

I'll merge it with your PR for the docs. No use having "hidden" features.

amaury1093 commented 7 years ago

@eddyystop Ready to be merged.

eddyystop commented 7 years ago

Thanks!

eddyystop commented 7 years ago

Published as v1.0.0