Skip to content

Expose currentReducer from store through getReducer() #4107

Closed
@smeng9

Description

@smeng9

This is not a duplicate of #1246 because we have a different type of use case

New Features

I would like to get the currentReducer using the store.getReducer()

What is the new or updated feature that you are suggesting?

The createStore in https://github.com/reduxjs/redux/blob/master/src/createStore.ts will have a new method

function getReducer(): Reducer<S, A> {

  return currentReducer as Reducer<S, A>;

}

and get exposed in store object

Why should this feature be included?

Our project uses a closed source proprietary library which initializes the redux context for us.
However we would like to override some part of the reducer logic, but we cannot modify the source because we don't have it or use other libraries to do it.

Since we cannot initialize the reducer by ourselves, we can only resort to extracting the reducer from the store. This is a different situation than #1246 as they have the full access of the reducer when passing into createStore.
So we would like to add this method to get the currentReducer out, and wrap it to change some behavior, and pass it back to replaceReducer.

What docs changes are needed to explain this?

We will need to modify the Store Methods part of the document to explain the new method https://redux.js.org/api/store#store-methods

Also I can add some of the example code in the documentation to illustrate how to use together with replaceReducer to override some of the reducer logic.

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