Skip to content

Pass an arrow function as a parameter to the reducer instead of an action #3739

@jesusprz1997

Description

@jesusprz1997

I would like to know if it would be possible to receive, as a parameter in a reducer, an arrow function instead of an action, so the switch can be omitted and it would be only necesary to execute the mentioned function.

If this were possible, switch cases could be avoided, resulting in improved performance of reducers with many different actions.

Example:

Before: 
	function reducer(previousState, action) {
		switch(action.type) {
			case 'ACTION1':
			  return { ..1.. };
			  
			case 'ACTION2':
			  return { ..2.. };
			  
			case 'ACTION3':
			  return { ..3.. };
		}
	}

After:
	action1(previousState) => { ..1.. }
	action2(previousState) => { ..2.. }
	action3(previousState) => { ..3.. }

	function reducer(previousState, arrowFunction) {
		return arrowFunction(previousState);
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions