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

Feature: make getters generator functions #7

Open
Romms opened this issue Mar 25, 2018 · 2 comments
Open

Feature: make getters generator functions #7

Romms opened this issue Mar 25, 2018 · 2 comments

Comments

@Romms
Copy link

Romms commented Mar 25, 2018

What about an idea to make getter methods be a generator function? It can allow us to do this for example:

const todos = map({
  addActionTypes: ['ADD_FEW_TODOS'],
  *keyGetter(action) {
    yield* action.payload.map(todo => todo.id);
  },
  *itemGetter(action) {
    yield* action.payload;
  },
});

I think it is an easy way to solve the problem described here #5 (comment)

@Romms
Copy link
Author

Romms commented Mar 25, 2018

This idea will be better if keep in mind this issue #8 what allow us to describe getters only for one action type. Than we can write like that

const todos = map({
  addActionTypes: [
    {
      todo: 'ADD_ONE_TODO',
      keyGetter: action => action.payload.uuid,
    },
    {
      todo: 'ADD_FEW_TODOS',
      * keyGetter(action) { yield* action.payload.map(todo => todo.uuid); },
      * itemGetter(action) { yield* action.payload; },
    },
  ],
});

@adrienjt
Copy link
Owner

Those are great suggestions @Romms ! (this and #8)
Getters would not only be specific to action types, but also to "sub-reducers" (add/change/remove). That would make the design more flexible, and we wouldn't have to add confusing parameters like manyItemsGetter in #6. However, simple use cases might become more verbose.
I'll definitely consider your suggestions for v1. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants