Git Product home page Git Product logo

redux-tools's Introduction

Redux Tools

🛠 💪 💉

Maintaining large Redux applications with ease.

A collection of tools for maintaining large Redux applications by enabling dependency injection of Redux code and development of multi-instance components by namespacing their state.

MIT License Downloads Version

Redux Tools consist mainly of:

  • Store enhancers for injecting reducers, middleware, and epics into your Redux store after the store is created.
  • Utility functions for less verbose definitions of action creators and reducers.
  • Logic for managing your state via namespaces.

Documentation & API Reference

See redux-tools.js.org, powered by Docsify.

Installation

The @redux-tools/react package contains everything you'll need to get started with using Redux Tools in a React application. Use either of these commands, depending on the package manager you prefer:

yarn add @redux-tools/react

npm i @redux-tools/react

Please visit redux-tools.js.org to see all available packages.

Changelog

See the CHANGELOG.md file.

Resources

Contributing

We are open to all ideas and suggestions, feel free to open an issue or a pull request!

See the contribution guide for guidelines.

Related Projects

  • validarium – Validations done right.
  • lundium – Beautiful React component library.
  • react-union – Integrate React apps into various CMSs seamlessly.

License

All packages are distributed under the MIT license. See the license here.

redux-tools's People

Contributors

aizerin avatar dependabot[bot] avatar dunaevskiy avatar greenkeeper[bot] avatar mmaarrttyy avatar tommmyy avatar vwerne avatar wafflepie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

redux-tools's Issues

Redux store should remove reducer's data after ejecting

CleanShot 2019-10-29 at 3 35 27 PM@2x

Is this an expected behavior? I would expect that after ejecting reducer (in other words, once the component which contains withReducers() is unmounted), reducer data from store should be removed, right? And if not so, there should be at least option to do so.
Because otherwise, if there is an middleware which adds items on fired action, it will created duplicated data.

Thanks in advance.

update to react-redux v6

The current version is incompatible with react-redux v6. Because of HOC withInjectorContext, where the store is passed down the props.

move Provider to namespaces-react

Provider is not something we depend on for the injection mechanism anymore (because we use the React Redux context instead)

because the Provider is tied to namespacing only, it should be moved to its own package

replace `combineReducers` with custom implementation

The Redux implementation is too opinionated, because it assumes that the state structure is always static – if we inject/eject reducers dynamically, state can be lost. Furthermore, combineReducers does not allow any other keys (they are ignored), which is especially painful for rehydration of state when the appropriate reducers are not mounted yet (state gets lost)

fix passing namespace to actions in middleware

Currently, whenever an action goes through a namespaced middleware, it is immediately associated with that namespace, which doesn't make sense. Only actions dispatched within the middleware should do so.

The fix is either to somehow wrap dispatch to assoc the action, or expose attachNamespace more and make it more aggressive.

Improve utility functions arsenal

  • Add support for variadic action creators (makeBinaryActionCreator)
  • Add makeMiddleware and composeMiddleware to middleware (makeMiddleware will not be added because it is too specific, perhaps in another issue)
  • Add scopeReducer to reducers (not added, but no longer necessary due to #155)
  • Add useNamespacedSelector (optional feature arg) to @redux-tools/namespaces-react

improve the defaulting of features

Instead of using feature = "namespaces" everywhere, it should at least be a constant (or make sure to only default possible user entry points).

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

How to set initial state for dynamically added reducer?

Hey, it seems that with usage of withReducers(), the initial state passed during store initialization is ignored.

Typical use case is for reason of local storage to set reducer state:
CleanShot 2019-10-21 at 3 21 24 PM@2x

Instead, I should be doing something like this:

CleanShot 2019-10-21 at 3 22 16 PM@2x

Ideally, there could be api to provide initial state together withReducers() HOC?

Thanks in advance.

investigate `makeActionTypes` autocompletion

use of makeActionTypes is discouraged because of no IDE autocompletion. can this be solved by TS typings in Vanilla JS apps?

if not, makeActionTypes should be deprecated imo

Add note to README about bug in redux-devtools-extension

After injecting either a reducer or a middleware redux-devtools-extension stops the logging of actions.
Fix is to set options to devtools like that:

	const composeEnhancers = composeWithDevTools({
		// NOTE: if not set the extension breaks after injecting reducers
		latency: 0,
		// NOTE: if `true` extension breaks after injecting reducers
		shouldHotReload: false,
	});

I think it would be useful to warn our precious users about that.

revise injecting in `componentDidMount`

Mainly wrt. async mode.

Suppose a component's constructor was called, but the component isn't mounted after all (possible situation in async mode). It is not yet known if componentWillUnmount will fire. This would make it impossible to reliably eject injectables without any leaks.

Injecting in componentDidMount has a single disadvantage: inner components' componentDidMount methods are fired first, so a common pattern of e.g. fetching data would not work, because the reducer/epic/middleware would not have been mounted yet.

Microsoft's solution uses state to delay rendering of inner components, which would also work in our case.

There are a couple of possible problems:

  1. Using refs from a parent component can break, but this isn't a likely scenario, because refs are rarely used to access containers. (If we were to use refs in parent's componentDidMount, we would've expected the child component to be mounted, but the mount is actually delayed.)
  2. Performance, white flashes, etc., especially with regards to SSR and hydration:
    1. static render
    2. first React render
    3. statically rendered content is removed (due to change in state)
    4. second React render
    5. content is rendered

In order to have preloading of content in SSR possible at all, the injectables have to be defined statically and mounted in e.g. async getInitialProps. Because of our entry system, we do not have to worry about duplicates. When rendering on the client, injectable IDs have to be passed to from the server (somehow) and then injected BEFORE rendering the React application. The injector state (whether componentDidMount should be delayed) should thus depend on whether the injectable is already injected (resulting in no flashes).

It should also be noted that regardless of async mode behaviour, this approach is cleaner, because no side effects happen in the constructor (and everything can be rewritten to use hooks... perhaps). We'll also be able to get rid of all the versions (finally).

provide a clear way to dispatch a global action from a namespaced injectable

this is useful for affecting all widgets from a single widget (must be mentioned in the docs!)

attachNamespace(null, action) might work, but i think there should be an explicit function for this.

we should ensure that any mechanism where the namespace can be overridden is using defaultNamespace (notably actions dispatched via namespacedConnect, injected middleware, epics)

defaultNamespace should include tests checking that if an action has namespace: null, it won't be changed

is namespace: null sufficient? perhaps a constant would be better.

proposed names for the function:

  • unsetNamespace
  • removeNamespace
  • dissocNamespace
  • detachNamespace

the issue with these names is that the behaviour is not reflected in the name. we are not unsetting a present namespace. we are preventing a namespace to be set automatically.

maybe something like

  • globalizeAction
  • preventNamespace

i'm inclining towards preventNamespace having an explicit constant (NAMESPACE_PREVENTED)

fix middleware initialization

We call middleware(reduxAPI)(next) per each action. This is wrong, each middleware should only be initialized once and then we should only call something(action)

Minor logo adjustment

Would be possible to have both words of the title of the library "Redux Tools" on the same line?
I think it would be nicer on the web.
If you provide a source file I can change it myself.

Also, the transparent background would be more flexible.

add invariant to `makeSimpleActionCreator` if argument is not passed

currently, its way too easy to do const updateSomething = makeSimpleActionCreator(UPDATE_SOMETHING) and dispatch updateSomething() accidentally.

this will just break stuff. the user should be notified with the following message

You did not pass an argument to an action creator created by `"makeSimpleActionCreator(${type})"`. Did you mean to use `"makeConstantActionCreator(${type})"`?

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

ensure proper dependency ranges

redux-tools might have problems wrt. building application bundles – if a redux-tools package requires e.g. ^0.26.1 version of ramda, and an application has 0.25.0 as a dependency, two copies of ramda will be included in the final bundle

Refactor monorepo structure

The actual state of packages is just proof of concept that rollup can be used within monorepo.

Please provide real packages and remove old ones.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Nested reducer injection

Copy pasted from an internal project:

{ 
  someModule: {
    common: {}, // App bound
    someView: {}, // View bound
  }
}

but when you navigate from SomeView to OtherView, you would get

{ 
  someModule: {
    common: {}, // App bound - preserved across navigation
    otherView: {}, // View bound - fresh initialized
    // someView gets dropped
  }
}

Of course the same can be achieved by using prefixed names like someModuleCommon or someModuleSomeView, but the nested variant looks nicer.😃

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.