rangle / redux-beacon

Analytics integration for Redux and ngrx/store
https://rangle.gitbook.io/redux-beacon/
MIT License
668 stars 73 forks source link

Cannot use both ensure() and debounceEvent()? #286

Open julienma opened 6 years ago

julienma commented 6 years ago

This is a...

Note: for support questions, please use stackoverflow with the redux-beacon tag. This repository's issues are reserved for feature requests and bug reports.

Which version of Redux Beacon are you using?

Which target(s) are you using?

(If this is a bug report, feel free to delete the :scroll: and :rocket: sections. Likewise, if this is a documentation or feature request, feel free to delete the :beetle: sections)

:beetle: What are the steps to reproduce your issue?

const validator = event => {
  // validate event...
  return true;
}

const emitEvent1 = ensure(validator, emitEvent1Debounced);
const emitEvent1Debounced = debounceEvent(60*1000,
  logEvent((action) => ({
    type: 'My Event'
  }))
);

export default (action) => {
  switch (action.type) {
    case MY_ACTION:
      return [emitEvent1, emitEvent2];
    default:
      return [];
  }
}

Please note that when using only ensure() or debounceEvent(), it works as expected. This only happens when trying to use both on the same event.

:beetle: What did you expect to happen?

Event would be debounced, then validated before being sent to target. Or the other way around: validated first, then debounced.

:beetle: What happened instead?

Error:

Uncaught TypeError: eventDef is not a function
    at ensure.js:4
    at debounce-event.js:11
    at wrapped (raven.js:351)

Can you help out?

ttmarek commented 6 years ago

Hey @julienma.

I would peg this as both a bug and a feature request. The ensure event was never updated to handle asynchronous events when that was introduced to redux-beacon.

If you like I could write up some test cases that we'd need to pass in order for us to add support for them.

Also if you think it's worth adding a note in the docs that we don't currently support async events that would be very helpful.

julienma commented 6 years ago

Hey @ttmarek, thanks for the answer. I made some changes to my code logic, and don't need this anymore.

However yes, that'd probably be a good idea to add a note in the docs. I've opened https://github.com/rangle/redux-beacon/pull/288 for this.