skortchmark9 / reselect-tools

Debugging Tools for Reselect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

immediate selectorGraph() change logging

MattCowski opened this issue · comments

commented

Currently, changes in state will not immediately be reflected in reselect-tools unless selectorGraph() is fired (i.e. on clicking "refresh" in the extension). I've overcome this by adding some redux middleware:

const reselectTools = store => next => action =>{

  const nodes = selectorGraph().nodes

  let result = next(action)
  
  if (typeof action === "function") return result

  const nextNodes = selectorGraph().nodes

  const nnKeys = Object.keys(nextNodes) // ["data$", "ui$"]

  // log if action changed any selectors
  nnKeys.forEach(k=>{
    if (nextNodes[k].recomputations!= nodes[k].recomputations) console.log({
      ...checkSelector(k), action
    })

  })

  return result

}

image

Now I can at least search in the console for a selector and see the action that triggered it whenever it's recomputed. It'd be great to combine this with the extension search filter.
It seems like this should be the default, or maybe there is a better way to do this? Also, any way to remotely update the extension?

Hey Matt - your solution looks good to me! Technically this library does not depend on redux, so I'd be reluctant to add any kind of redux-specific middleware. However, this looks like a simple recipe for getting the desired behavior.

I'm not sure I understand your question about 'remotely updating the extension'. Could you clarify?