Skip to content

Group changes based on action.params (or allow filtered actions to reset history.group) #289

@josephmturner

Description

@josephmturner

Thank you for redux-undo!

I'd like to group changes based not only on a comparison of prior/current action.type but also prior/current action.params.

Data model:

interface DraftState {
  message: DraftMessageI
  points: {
    [url: string]: PointI
  }
}

Stream of actions looks like:
{ type: 'draftPointCreate', params: { url: 'point1' } }
{ type: 'draftPointUpdate', params: { url: 'point1', content: 'h' } }
{ type: 'draftPointUpdate', params: { url: 'point1', content: 'he' } }
{ type: 'draftPointUpdate', params: { url: 'point1', content: 'hel' } }
{ type: 'draftPointUpdate', params: { url: 'point1', content: 'hell' } }
{ type: 'draftPointUpdate', params: { url: 'point1', content: 'hello' } }
{ type: 'draftPointCreate', params: { url: 'point2' } }
{ type: 'draftPointUpdate', params: { url: 'point2', content: 'w' } }
{ type: 'draftPointUpdate', params: { url: 'point2', content: 'wo' } }
{ type: 'draftPointUpdate', params: { url: 'point2', content: 'wor' } }
{ type: 'draftPointUpdate', params: { url: 'point2', content: 'worl' } }
{ type: 'draftPointUpdate', params: { url: 'point2', content: 'world' } }

I want to filter out changes which result from draftPointCreate actions since there's no need to store empty points in history.past. Additionally, I want to group changes which result from draftPointUpdate actions if and only if their action.params.url are the same. I tried this config:

export default undoable(draftReducer, {
  filter: excludeAction('draftPointCreate'),
  groupBy: groupByActionTypes('draftPointUpdate')
})

If the filtered draftPointCreate actions caused history.group to reset to null, this would work as intended. However, since #171 and #167, history.group is not modified on filtered actions (I agree that redux-undo current behavior makes sense).

Perhaps there's some other solution for my use case!

Thank you for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions