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

Lifted actions should have IDs

Open gaearon opened this issue 11 years ago • 5 comments

Currently, lifted PERFORM_ACTION actions don't have any IDs. This causes the lifted state to be awkwardly denormalized: skippedActions stores indexes from stagedActions and has to be adjust whenever stagedActions is reordered, timestamps suffers from the same problem. Moreover it's hard to annotate actions like requested in https://github.com/gaearon/redux-devtools/issues/60 because indexes just aren't stable.

If all lifted actions with PERFORM_ACTION type included an ID generated in performAction() lifted action creator, https://github.com/gaearon/redux-devtools/issues/60 would be solvable by the monitor storing something like collapsedByActionId: { 42: true, 100: false, etc }.

I propose the following breaking change to the lifted state shape as part of #132:

Before

{
  stagedActions: [...actions],
  timestamps: [...timestamps],
  skippedActions: { index -> bool },

  committedState: state,
  computedStates: [...{ state, error }],
  currentStateIndex: int,
  monitorState: monitorState
}

After

{
  actionsById: { id -> liftedAction }, // only for PERFORM_ACTION actions
  stagedActions: [...actionIds],
  skippedActions: { actionId -> bool },
  // note there's no need for timestamps anymore—look into actionsById[id].timestamp

  committedState: state,
  computedStates: [...{ state, error }],
  currentStateIndex: int,
  monitorState: monitorState
}

I don't think there's any point to normalizing states because that's just derived data from DevTools point of view. But for actions, it feels important to enable use cases like #60 and make code inside devTools() simpler.

@ellbee @ioss @calesce What do you think? Am I making sense?

gaearon avatar Sep 27 '15 18:09 gaearon

Makes totally sense to me!

Just one question: If I understand correctly collapsedByActionId would be stored on the Monitor (state) right? How would monitors be able to share "action meta state"?

ioss avatar Sep 28 '15 10:09 ioss

:+1: Makes sense to me, nice to enable these use cases without increasing the complexity of the devtools API.

ellbee avatar Sep 28 '15 11:09 ellbee

How would monitors be able to share "action meta state"?

Each monitor would be responsible for maintaining the state it's interested in. With #132, monitors can export reducers which will receive all the same actions devTools() receives. This lets them implement custom logic on top of it.

gaearon avatar Sep 28 '15 12:09 gaearon

Nice!

ioss avatar Sep 28 '15 12:09 ioss

Fixed in vNext branch.

gaearon avatar Oct 17 '15 00:10 gaearon