Support `exceptionPatterns` in `reactotron-redux` #318

Open
wants to merge 3 commits into
from

Projects

None yet

2 participants

@g6ling
g6ling commented Jan 7, 2017

This PR adds exceptionPatterns which is exception for Function. I think this make except more simple.

example

const REACT_NATIVE_ROUTER_FLUX = (type) => type.includes('REACT_NATIVE_ROUTER_FLUX');
const REDUX_SAGA_REQUEST = (type) => type.includes('request');

Reactotron
  .use(reactotronRedux({
    except: [],
    exceptPattern: [
      REACT_NATIVE_ROUTER_FLUX,
      REDUX_SAGA_REQUEST,
    ],
  }))
@skellock
Member
skellock commented Jan 9, 2017

Hey! Thanks man.

I like this feature. Now that I see this in action, though, I'm thinking we add this to except instead of introducing a new property. I totally get why you did, and I appreciate it.

Let's make except an array that accepts 3 things:

  • a string (exact match)
  • a regex (to uh... regex match)
  • a function (to invoke -- just like you wrote)

That way, we get your new goodies, we get a regex, and we keep the old way, all without breaking the interface!

Thoughts?

@g6ling
g6ling commented Jan 9, 2017

Thanks. I update my PR. I think this code will work as you want.
Should I update this(https://github.com/reactotron/reactotron/blob/master/docs/plugin-redux.md)?

@skellock

Thanks! Just a few changes if you don't mind.

+ const checkException = (exception, actionType) => {
+ switch (typeof exception) {
+ case 'string':
+ return actionType === exception;
@skellock
skellock Jan 9, 2017 Member

We use the standard standard. If you run npm run lint you'll see it won't like semi-colons.

+ return actionType === exception;
+ case 'function':
+ return exception(actionType);
+ case 'object':
@skellock
skellock Jan 9, 2017 Member

Too bad we couldn't detect regexp's! Oh well. You win this time JavaScript.

+ return exception(actionType);
+ case 'object':
+ return exception.test(actionType);
+ break;
@skellock
skellock Jan 9, 2017 Member

You can nuke this break. The return just above it will take care of this case.

+ }
+ }
+
+ const checkExceptions = exceptions.reduce((prev, exception) => checkExcpetion(exception, unwrappedAction.type) || prev, false);
@skellock
skellock Jan 9, 2017 Member

The function checkExcpetion might not exist.

// action not blacklisted?
- if (!exceptionPattern && !contains(unwrappedAction.type, exceptions)) {
+ if (!checkExcpetions) {
@skellock
skellock Jan 9, 2017 Member

Looks like this variable should be checkExceptions?

@g6ling
g6ling commented Jan 9, 2017

thanks for your review. How can I test my code in reactotron?

@skellock
Member
skellock commented Jan 9, 2017
cd packages/reactotron-redux
npm test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment