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

adding custom methods #18

Open
jasonvillalon opened this issue Jun 23, 2017 · 1 comment
Open

adding custom methods #18

jasonvillalon opened this issue Jun 23, 2017 · 1 comment

Comments

@jasonvillalon
Copy link

jasonvillalon commented Jun 23, 2017

Hi,

can we add feature for adding custom methods that does not communicate with the server?

for example, right now. my work arround is to edit the feathers-redux and add something like this for me to achieve what i need.

custom/posts.js - for custom methods in post

import _ from 'lodash';

const SERVICES_POSTS_EDIT = 'SERVICES_POSTS_EDIT';
export default [
  {
    name: 'edit',
    createAction: () => id => ({ id }),
    reducer: { [SERVICES_POSTS_EDIT]: (state, action) => {
      const postIndex = _.findIndex(state.queryResult.data, { id: action.payload.id });
      const queryResult = state.queryResult;
      queryResult.data[postIndex].isEditing = true;
      return {
        ...state,
        queryResult,
      };
    },
    },
  },
];

then in when reduxifying the services i added the custom methods

import posts from './custom/posts.js';
export const feathersServices = reduxifyServices(app, mapServicePathsToNames, {}, {
  posts,
});

just to call something like this on my component

onEdit: (id) => {
    dispatch(feathersServices.posts.edit(id));
  },

maybe we can add some feature like this? not sure if good idea. but i think someone like me needed it.

Best Regards,
Jason Villalon

@eddyystop
Copy link
Collaborator

eddyystop commented Jun 23, 2017

Thanks for bringing this up.

Like you, I'm not sure if this should coreside with the service actions & reducers. Perhaps this is a special case of interfacing custom services with Redux. The trick there would be to provide access to the service's state.

I'm tied up doing feathers-react docs ATM. Let me think on it.

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