redux-saga-routines icon indicating copy to clipboard operation
redux-saga-routines copied to clipboard

createRoutines?

Open victordidenko opened this issue 7 years ago • 7 comments

I think it would be nice to have createRoutines method, like createActions in 'redux-actions', to create routines in batch, and not one by one

victordidenko avatar Feb 22 '18 13:02 victordidenko

@victordidenko good idea! PR are welcome :)

afitiskin avatar Feb 23 '18 10:02 afitiskin

Made an PR #38, first approach (don't like very much), to hear your opinion

victordidenko avatar Mar 13 '18 17:03 victordidenko

Proposals

Nested example:

const routines = createRoutines({ people: { search: name => ({ name }) } });
routines.people.search('Ada');
// { type: 'routines/people/search/TRIGGER', payload: { name: 'Ada' } }

We can access to the stage with underscore prefix and for example to overwrite the default payloadCreator:

const routines = createRoutines({ 
  people: {
    search: {
      _TRIGGER: ({ phone }) => parseInt(phone, 2)
     },
    add: null // maybe as well or something other to say `default`,
    remove: null
  }
 });
routines.people.search({ name: 'Ada', phone: 010010 });
// { type: 'routines/people/search/TRIGGER',  payload: 42 }

Or add custom routines with createRoutineCreator:

const routines = createRoutines({ 
  people: {
    search: {
      more_info: {
        _OPEN: null,
        _HIDE: null,
     }
    }
  }
});
routines.people.search.moreInfo.open({ id: 42 });
// { type: 'routines/people/search/OPEN',  payload: { id: 42 } }
routines.people.search.moreInfo.hide({ id: 42 });
// { type: 'routines/people/search/HIDE',  payload: { id: 42 } }

And maybe even create extended routines with default stages and like in that package

shapkarin avatar Jul 31 '19 11:07 shapkarin

I think to implement that. Not sure how long that it takes, hope I will provide some first version soon.

shapkarin avatar May 10 '20 23:05 shapkarin

Not sure about underscore before the stage (for example _TRIGGER) And now I realise that maybe better is to implement that in my package, because I will definitely need createCustomRoutine functionality inside createRoutines.

shapkarin avatar May 10 '20 23:05 shapkarin

Today I will release the first version.

shapkarin avatar May 11 '20 12:05 shapkarin

Here is createRoutines first version https://github.com/shapkarin/extend-saga-routines#create-routines

shapkarin avatar May 11 '20 15:05 shapkarin