redux-logic icon indicating copy to clipboard operation
redux-logic copied to clipboard

Order of logics in array followup #82

Open cyrilchapon opened this issue 7 years ago • 1 comments

Hey :) expanding on #82

I'm writing some kind of chat bot, and I got the following use case :

User types something and hit "submit" I dispatch a specific action (say "ANSWER/SUBMIT_SURNAME")

Then I'd like to grab it like this

  • Add a logic that prints user answer
  • Make some validations about it
  • Process it

So I naturaly thought about 2 logics on the same action :

pseudo-code

const printAnswerLogic = createLogic({
  type: ANSWER__SUBMIT_PATTERN,
  process: ({ getState, action }) => {
    //Print answer (typically dispatch a new action)
    //Go to next logic
  }
})

const submitAnswerLogic = createLogic({
  type: ANSWER__SUBMIT_PATTERN,
  validate: ({ getState, action }, allow, reject) => {
    if(!some.checks) {
      reject()
    }

    allow()
  },
  process: ({ getState, action }) => {
    //Process data
  }
})

What I'm facing is order doesn't seem very consistent (console.logging just blew my mind) As well as I don't know how to "go to next logic" within the first logic.

Is this a common use case ?

NOTA-BENE: I don't want to extract "typing" logic inside my raw action body, because the whole point of starting with redux-logic is to manage hard-to-maintain that whole typing / validation concept. (this is a simplified example, since my bot also type some stuff after validation, and custom messages)

cyrilchapon avatar May 02 '18 15:05 cyrilchapon

That's an interesting use case which could work well since we have access to the action observable stream. I'll think about how we might implement and see if any additional features are needed to support this.

jeffbski avatar May 07 '18 17:05 jeffbski