isomorfeus-redux 4.0.23 → 4.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +27 -0
- data/lib/isomorfeus/core_ext/kernel.rb +1 -1
- data/lib/isomorfeus/execution_environment.rb +17 -10
- data/lib/isomorfeus/{redux_config.rb → redux/config.rb} +0 -0
- data/lib/isomorfeus/redux/imports.rb +17 -0
- data/lib/isomorfeus-redux.rb +7 -4
- data/lib/redux/version.rb +1 -1
- data/node_modules/.package-lock.json +31 -0
- data/node_modules/@babel/runtime/LICENSE +22 -0
- data/node_modules/@babel/runtime/README.md +19 -0
- data/node_modules/@babel/runtime/helpers/AsyncGenerator.js +99 -0
- data/node_modules/@babel/runtime/helpers/AwaitValue.js +6 -0
- data/node_modules/@babel/runtime/helpers/applyDecoratedDescriptor.js +31 -0
- data/node_modules/@babel/runtime/helpers/arrayLikeToArray.js +12 -0
- data/node_modules/@babel/runtime/helpers/arrayWithHoles.js +6 -0
- data/node_modules/@babel/runtime/helpers/arrayWithoutHoles.js +8 -0
- data/node_modules/@babel/runtime/helpers/assertThisInitialized.js +10 -0
- data/node_modules/@babel/runtime/helpers/asyncGeneratorDelegate.js +57 -0
- data/node_modules/@babel/runtime/helpers/asyncIterator.js +16 -0
- data/node_modules/@babel/runtime/helpers/asyncToGenerator.js +38 -0
- data/node_modules/@babel/runtime/helpers/awaitAsyncGenerator.js +8 -0
- data/node_modules/@babel/runtime/helpers/checkPrivateRedeclaration.js +8 -0
- data/node_modules/@babel/runtime/helpers/classApplyDescriptorDestructureSet.js +23 -0
- data/node_modules/@babel/runtime/helpers/classApplyDescriptorGet.js +10 -0
- data/node_modules/@babel/runtime/helpers/classApplyDescriptorSet.js +14 -0
- data/node_modules/@babel/runtime/helpers/classCallCheck.js +8 -0
- data/node_modules/@babel/runtime/helpers/classCheckPrivateStaticAccess.js +8 -0
- data/node_modules/@babel/runtime/helpers/classCheckPrivateStaticFieldDescriptor.js +8 -0
- data/node_modules/@babel/runtime/helpers/classExtractFieldDescriptor.js +10 -0
- data/node_modules/@babel/runtime/helpers/classNameTDZError.js +6 -0
- data/node_modules/@babel/runtime/helpers/classPrivateFieldDestructureSet.js +11 -0
- data/node_modules/@babel/runtime/helpers/classPrivateFieldGet.js +11 -0
- data/node_modules/@babel/runtime/helpers/classPrivateFieldInitSpec.js +9 -0
- data/node_modules/@babel/runtime/helpers/classPrivateFieldLooseBase.js +10 -0
- data/node_modules/@babel/runtime/helpers/classPrivateFieldLooseKey.js +8 -0
- data/node_modules/@babel/runtime/helpers/classPrivateFieldSet.js +12 -0
- data/node_modules/@babel/runtime/helpers/classPrivateMethodGet.js +10 -0
- data/node_modules/@babel/runtime/helpers/classPrivateMethodInitSpec.js +9 -0
- data/node_modules/@babel/runtime/helpers/classPrivateMethodSet.js +6 -0
- data/node_modules/@babel/runtime/helpers/classStaticPrivateFieldDestructureSet.js +14 -0
- data/node_modules/@babel/runtime/helpers/classStaticPrivateFieldSpecGet.js +14 -0
- data/node_modules/@babel/runtime/helpers/classStaticPrivateFieldSpecSet.js +15 -0
- data/node_modules/@babel/runtime/helpers/classStaticPrivateMethodGet.js +9 -0
- data/node_modules/@babel/runtime/helpers/classStaticPrivateMethodSet.js +6 -0
- data/node_modules/@babel/runtime/helpers/construct.js +26 -0
- data/node_modules/@babel/runtime/helpers/createClass.js +18 -0
- data/node_modules/@babel/runtime/helpers/createForOfIteratorHelper.js +61 -0
- data/node_modules/@babel/runtime/helpers/createForOfIteratorHelperLoose.js +25 -0
- data/node_modules/@babel/runtime/helpers/createSuper.js +25 -0
- data/node_modules/@babel/runtime/helpers/decorate.js +401 -0
- data/node_modules/@babel/runtime/helpers/defaults.js +17 -0
- data/node_modules/@babel/runtime/helpers/defineEnumerableProperties.js +25 -0
- data/node_modules/@babel/runtime/helpers/defineProperty.js +17 -0
- data/node_modules/@babel/runtime/helpers/esm/AsyncGenerator.js +95 -0
- data/node_modules/@babel/runtime/helpers/esm/AwaitValue.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/applyDecoratedDescriptor.js +28 -0
- data/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js +9 -0
- data/node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js +4 -0
- data/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/asyncGeneratorDelegate.js +54 -0
- data/node_modules/@babel/runtime/helpers/esm/asyncIterator.js +13 -0
- data/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js +35 -0
- data/node_modules/@babel/runtime/helpers/esm/awaitAsyncGenerator.js +4 -0
- data/node_modules/@babel/runtime/helpers/esm/checkPrivateRedeclaration.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/classApplyDescriptorDestructureSet.js +20 -0
- data/node_modules/@babel/runtime/helpers/esm/classApplyDescriptorGet.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/classApplyDescriptorSet.js +11 -0
- data/node_modules/@babel/runtime/helpers/esm/classCallCheck.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/classCheckPrivateStaticAccess.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/classCheckPrivateStaticFieldDescriptor.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/classExtractFieldDescriptor.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/classNameTDZError.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldDestructureSet.js +6 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldGet.js +6 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldInitSpec.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldLooseBase.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldLooseKey.js +4 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateFieldSet.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateMethodGet.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateMethodInitSpec.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/classPrivateMethodSet.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateFieldDestructureSet.js +8 -0
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateFieldSpecGet.js +8 -0
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateFieldSpecSet.js +9 -0
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateMethodGet.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/classStaticPrivateMethodSet.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/construct.js +18 -0
- data/node_modules/@babel/runtime/helpers/esm/createClass.js +15 -0
- data/node_modules/@babel/runtime/helpers/esm/createForOfIteratorHelper.js +57 -0
- data/node_modules/@babel/runtime/helpers/esm/createForOfIteratorHelperLoose.js +21 -0
- data/node_modules/@babel/runtime/helpers/esm/createSuper.js +19 -0
- data/node_modules/@babel/runtime/helpers/esm/decorate.js +396 -0
- data/node_modules/@babel/runtime/helpers/esm/defaults.js +14 -0
- data/node_modules/@babel/runtime/helpers/esm/defineEnumerableProperties.js +22 -0
- data/node_modules/@babel/runtime/helpers/esm/defineProperty.js +14 -0
- data/node_modules/@babel/runtime/helpers/esm/extends.js +17 -0
- data/node_modules/@babel/runtime/helpers/esm/get.js +20 -0
- data/node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js +6 -0
- data/node_modules/@babel/runtime/helpers/esm/inherits.js +15 -0
- data/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +6 -0
- data/node_modules/@babel/runtime/helpers/esm/initializerDefineProperty.js +9 -0
- data/node_modules/@babel/runtime/helpers/esm/initializerWarningHelper.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/instanceof.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/interopRequireDefault.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/interopRequireWildcard.js +51 -0
- data/node_modules/@babel/runtime/helpers/esm/isNativeFunction.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/isNativeReflectConstruct.js +12 -0
- data/node_modules/@babel/runtime/helpers/esm/iterableToArray.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js +29 -0
- data/node_modules/@babel/runtime/helpers/esm/iterableToArrayLimitLoose.js +14 -0
- data/node_modules/@babel/runtime/helpers/esm/jsx.js +46 -0
- data/node_modules/@babel/runtime/helpers/esm/maybeArrayLike.js +9 -0
- data/node_modules/@babel/runtime/helpers/esm/newArrowCheck.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/nonIterableRest.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/objectDestructuringEmpty.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/objectSpread.js +19 -0
- data/node_modules/@babel/runtime/helpers/esm/objectSpread2.js +39 -0
- data/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js +19 -0
- data/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +14 -0
- data/node_modules/@babel/runtime/helpers/esm/package.json +3 -0
- data/node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js +11 -0
- data/node_modules/@babel/runtime/helpers/esm/readOnlyError.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/set.js +51 -0
- data/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +8 -0
- data/node_modules/@babel/runtime/helpers/esm/skipFirstGeneratorNext.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/slicedToArray.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/slicedToArrayLoose.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/superPropBase.js +9 -0
- data/node_modules/@babel/runtime/helpers/esm/taggedTemplateLiteral.js +11 -0
- data/node_modules/@babel/runtime/helpers/esm/taggedTemplateLiteralLoose.js +8 -0
- data/node_modules/@babel/runtime/helpers/esm/tdz.js +3 -0
- data/node_modules/@babel/runtime/helpers/esm/temporalRef.js +5 -0
- data/node_modules/@babel/runtime/helpers/esm/temporalUndefined.js +1 -0
- data/node_modules/@babel/runtime/helpers/esm/toArray.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js +7 -0
- data/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +13 -0
- data/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +6 -0
- data/node_modules/@babel/runtime/helpers/esm/typeof.js +15 -0
- data/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js +9 -0
- data/node_modules/@babel/runtime/helpers/esm/wrapAsyncGenerator.js +6 -0
- data/node_modules/@babel/runtime/helpers/esm/wrapNativeSuper.js +37 -0
- data/node_modules/@babel/runtime/helpers/esm/wrapRegExp.js +65 -0
- data/node_modules/@babel/runtime/helpers/esm/writeOnlyError.js +3 -0
- data/node_modules/@babel/runtime/helpers/extends.js +21 -0
- data/node_modules/@babel/runtime/helpers/get.js +27 -0
- data/node_modules/@babel/runtime/helpers/getPrototypeOf.js +10 -0
- data/node_modules/@babel/runtime/helpers/inherits.js +19 -0
- data/node_modules/@babel/runtime/helpers/inheritsLoose.js +10 -0
- data/node_modules/@babel/runtime/helpers/initializerDefineProperty.js +12 -0
- data/node_modules/@babel/runtime/helpers/initializerWarningHelper.js +6 -0
- data/node_modules/@babel/runtime/helpers/instanceof.js +10 -0
- data/node_modules/@babel/runtime/helpers/interopRequireDefault.js +8 -0
- data/node_modules/@babel/runtime/helpers/interopRequireWildcard.js +54 -0
- data/node_modules/@babel/runtime/helpers/isNativeFunction.js +6 -0
- data/node_modules/@babel/runtime/helpers/isNativeReflectConstruct.js +15 -0
- data/node_modules/@babel/runtime/helpers/iterableToArray.js +6 -0
- data/node_modules/@babel/runtime/helpers/iterableToArrayLimit.js +32 -0
- data/node_modules/@babel/runtime/helpers/iterableToArrayLimitLoose.js +17 -0
- data/node_modules/@babel/runtime/helpers/jsx.js +50 -0
- data/node_modules/@babel/runtime/helpers/maybeArrayLike.js +13 -0
- data/node_modules/@babel/runtime/helpers/newArrowCheck.js +8 -0
- data/node_modules/@babel/runtime/helpers/nonIterableRest.js +6 -0
- data/node_modules/@babel/runtime/helpers/nonIterableSpread.js +6 -0
- data/node_modules/@babel/runtime/helpers/objectDestructuringEmpty.js +6 -0
- data/node_modules/@babel/runtime/helpers/objectSpread.js +23 -0
- data/node_modules/@babel/runtime/helpers/objectSpread2.js +42 -0
- data/node_modules/@babel/runtime/helpers/objectWithoutProperties.js +23 -0
- data/node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js +17 -0
- data/node_modules/@babel/runtime/helpers/possibleConstructorReturn.js +16 -0
- data/node_modules/@babel/runtime/helpers/readOnlyError.js +6 -0
- data/node_modules/@babel/runtime/helpers/set.js +55 -0
- data/node_modules/@babel/runtime/helpers/setPrototypeOf.js +12 -0
- data/node_modules/@babel/runtime/helpers/skipFirstGeneratorNext.js +10 -0
- data/node_modules/@babel/runtime/helpers/slicedToArray.js +14 -0
- data/node_modules/@babel/runtime/helpers/slicedToArrayLoose.js +14 -0
- data/node_modules/@babel/runtime/helpers/superPropBase.js +13 -0
- data/node_modules/@babel/runtime/helpers/taggedTemplateLiteral.js +14 -0
- data/node_modules/@babel/runtime/helpers/taggedTemplateLiteralLoose.js +11 -0
- data/node_modules/@babel/runtime/helpers/tdz.js +6 -0
- data/node_modules/@babel/runtime/helpers/temporalRef.js +10 -0
- data/node_modules/@babel/runtime/helpers/temporalUndefined.js +4 -0
- data/node_modules/@babel/runtime/helpers/toArray.js +14 -0
- data/node_modules/@babel/runtime/helpers/toConsumableArray.js +14 -0
- data/node_modules/@babel/runtime/helpers/toPrimitive.js +17 -0
- data/node_modules/@babel/runtime/helpers/toPropertyKey.js +11 -0
- data/node_modules/@babel/runtime/helpers/typeof.js +22 -0
- data/node_modules/@babel/runtime/helpers/unsupportedIterableToArray.js +13 -0
- data/node_modules/@babel/runtime/helpers/wrapAsyncGenerator.js +10 -0
- data/node_modules/@babel/runtime/helpers/wrapNativeSuper.js +45 -0
- data/node_modules/@babel/runtime/helpers/wrapRegExp.js +72 -0
- data/node_modules/@babel/runtime/helpers/writeOnlyError.js +6 -0
- data/node_modules/@babel/runtime/package.json +848 -0
- data/node_modules/@babel/runtime/regenerator/index.js +1 -0
- data/node_modules/redux/LICENSE.md +21 -0
- data/node_modules/redux/README.md +322 -0
- data/node_modules/redux/dist/redux.js +735 -0
- data/node_modules/redux/dist/redux.min.js +1 -0
- data/node_modules/redux/es/redux.js +684 -0
- data/node_modules/redux/es/redux.mjs +1 -0
- data/node_modules/redux/index.d.ts +676 -0
- data/node_modules/redux/lib/redux.js +697 -0
- data/node_modules/redux/package.json +108 -0
- data/node_modules/redux/src/applyMiddleware.js +41 -0
- data/node_modules/redux/src/bindActionCreators.js +52 -0
- data/node_modules/redux/src/combineReducers.js +175 -0
- data/node_modules/redux/src/compose.js +22 -0
- data/node_modules/redux/src/createStore.js +315 -0
- data/node_modules/redux/src/index.js +36 -0
- data/node_modules/redux/src/utils/actionTypes.js +17 -0
- data/node_modules/redux/src/utils/formatProdErrorMessage.js +15 -0
- data/node_modules/redux/src/utils/isPlainObject.js +14 -0
- data/node_modules/redux/src/utils/kindOf.js +70 -0
- data/node_modules/redux/src/utils/symbol-observable.js +3 -0
- data/node_modules/redux/src/utils/warning.js +19 -0
- data/node_modules/regenerator-runtime/LICENSE +21 -0
- data/node_modules/regenerator-runtime/README.md +31 -0
- data/node_modules/regenerator-runtime/package.json +19 -0
- data/node_modules/regenerator-runtime/path.js +11 -0
- data/node_modules/regenerator-runtime/runtime.js +754 -0
- data/package.json +6 -0
- metadata +240 -10
- data/README.md +0 -223
@@ -0,0 +1 @@
|
|
1
|
+
module.exports = require("regenerator-runtime");
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015-present Dan Abramov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,322 @@
|
|
1
|
+
# <a href='http://redux.js.org'><img src='https://camo.githubusercontent.com/f28b5bc7822f1b7bb28a96d8d09e7d79169248fc/687474703a2f2f692e696d6775722e636f6d2f4a65567164514d2e706e67' height='60' alt='Redux Logo' aria-label='redux.js.org' /></a>
|
2
|
+
|
3
|
+
Redux is a predictable state container for JavaScript apps.
|
4
|
+
(Not to be confused with a WordPress framework – [Redux Framework](https://reduxframework.com/).)
|
5
|
+
|
6
|
+
It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. On top of that, it provides a great developer experience, such as [live code editing combined with a time traveling debugger](https://github.com/reduxjs/redux-devtools).
|
7
|
+
|
8
|
+
You can use Redux together with [React](https://reactjs.org), or with any other view library.
|
9
|
+
It is tiny (2kB, including dependencies).
|
10
|
+
|
11
|
+
> **Note**: We are currently planning a rewrite of the Redux docs. Please take some time to **[fill out this survey on what content is most important in a docs site](https://docs.google.com/forms/d/e/1FAIpQLSfzIkY3fXZ8PrQKScYMK0YoEgALfAK2qQ0mOj1_ibKv2qDTuQ/viewform)**. Thanks!
|
12
|
+
|
13
|
+
[![build status](https://img.shields.io/travis/reduxjs/redux/master.svg?style=flat-square)](https://travis-ci.org/reduxjs/redux)
|
14
|
+
[![npm version](https://img.shields.io/npm/v/redux.svg?style=flat-square)](https://www.npmjs.com/package/redux)
|
15
|
+
[![npm downloads](https://img.shields.io/npm/dm/redux.svg?style=flat-square)](https://www.npmjs.com/package/redux)
|
16
|
+
[![redux channel on discord](https://img.shields.io/badge/discord-%23redux%20%40%20reactiflux-61dafb.svg?style=flat-square)](https://discord.gg/0ZcbPKXt5bZ6au5t)
|
17
|
+
[![Changelog #187](https://img.shields.io/badge/changelog-%23187-lightgrey.svg?style=flat-square)](https://changelog.com/187)
|
18
|
+
|
19
|
+
## Learn Redux
|
20
|
+
|
21
|
+
We have a variety of resources available to help you learn Redux, no matter what your background or learning style is.
|
22
|
+
|
23
|
+
### Just the Basics
|
24
|
+
|
25
|
+
If you're brand new to Redux and want to understand the basic concepts, see:
|
26
|
+
|
27
|
+
- The **[Motivation](https://redux.js.org/introduction/motivation)** behind building Redux, the **[Core Concepts](https://redux.js.org/introduction/coreconcepts)**, and the **[Three Principles](https://redux.js.org/introduction/threeprinciples)**.
|
28
|
+
- The **[basic tutorial in the Redux docs](https://redux.js.org/basics)**
|
29
|
+
- Redux creator Dan Abramov's **free ["Getting Started with Redux" video series](https://egghead.io/series/getting-started-with-redux)** on Egghead.io
|
30
|
+
- Redux co-maintainer Mark Erikson's **["Redux Fundamentals" slideshow](http://blog.isquaredsoftware.com/2018/03/presentation-reactathon-redux-fundamentals/)** and **[list of suggested resources for learning Redux](http://blog.isquaredsoftware.com/2017/12/blogged-answers-learn-redux/)**
|
31
|
+
- If you learn best by looking at code and playing with it, check out our list of **[Redux example applications](https://redux.js.org/introduction/examples)**, available as separate projects in the Redux repo, and also as interactive online examples on CodeSandbox.
|
32
|
+
- The **[Redux Tutorials](https://github.com/markerikson/react-redux-links/blob/master/redux-tutorials.md)** section of the **[React/Redux links list](https://github.com/markerikson/react-redux-links)**. Here's a top list of our recommended tutorials:
|
33
|
+
- Dave Ceddia's posts [What Does Redux Do? (and when should you use it?)](https://daveceddia.com/what-does-redux-do/) and [How Redux Works: A Counter-Example](https://daveceddia.com/how-does-redux-work/) are a great intro to the basics of Redux and how to use it with React, as is this post on [React and Redux: An Introduction](http://jakesidsmith.com/blog/post/2017-11-18-redux-and-react-an-introduction/).
|
34
|
+
- Valentino Gagliardi's post [React Redux Tutorial for Beginners: Learning Redux in 2018](https://www.valentinog.com/blog/react-redux-tutorial-beginners/) is an excellent extended introduction to many aspects of using Redux.
|
35
|
+
- The CSS Tricks article [Leveling Up with React: Redux](https://css-tricks.com/learning-react-redux/) covers the Redux basics well.
|
36
|
+
- This [DevGuides: Introduction to Redux](http://devguides.io/redux/) tutorial covers several aspects of Redux, including actions, reducers, usage with React, and middleware.
|
37
|
+
|
38
|
+
### Intermediate Concepts
|
39
|
+
|
40
|
+
Once you've picked up the basics of working with actions, reducers, and the store, you may have questions about topics like working with asynchronous logic and AJAX requests, connecting a UI framework like React to your Redux store, and setting up an application to use Redux:
|
41
|
+
|
42
|
+
- The **["Advanced" docs section](https://redux.js.org/advanced)** covers working with async logic, middleware, routing.
|
43
|
+
- The Redux docs **["Learning Resources"](https://redux.js.org/introduction/learning-resources)** page points to recommended articles on a variety of Redux-related topics.
|
44
|
+
- Sophie DeBenedetto's 8-part **[Building a Simple CRUD App with React + Redux](http://www.thegreatcodeadventure.com/building-a-simple-crud-app-with-react-redux-part-1/)** series shows how to put together a basic CRUD app from scratch.
|
45
|
+
|
46
|
+
### Real-World Usage
|
47
|
+
|
48
|
+
Going from a TodoMVC app to a real production application can be a big jump, but we've got plenty of resources to help:
|
49
|
+
|
50
|
+
- Redux creator Dan Abramov's **[free "Building React Applications with Idiomatic Redux" video series](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)** builds on his first video series and covers topics like middleware, routing, and persistence.
|
51
|
+
- The **[Redux FAQ](https://redux.js.org/faq)** answers many common questions about how to use Redux, and the **["Recipes" docs section](https://redux.js.org/recipes)** has information on handling derived data, testing, structuring reducer logic, and reducing boilerplate.
|
52
|
+
- Redux co-maintainer Mark Erikson's **["Practical Redux" tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)** demonstrates real-world intermediate and advanced techniques for working with React and Redux (also available as **[an interactive course on Educative.io](https://www.educative.io/collection/5687753853370368/5707702298738688)**).
|
53
|
+
- The **[React/Redux links list](https://github.com/markerikson/react-redux-links)** has categorized articles on working with [reducers and selectors](https://github.com/markerikson/react-redux-links/blob/master/redux-reducers-selectors.md), [managing side effects](https://github.com/markerikson/react-redux-links/blob/master/redux-side-effects.md), [Redux architecture and best practices](https://github.com/markerikson/react-redux-links/blob/master/redux-architecture.md), and more.
|
54
|
+
- Our community has created thousands of Redux-related libraries, addons, and tools. The **["Ecosystem" docs page](https://redux.js.org/introduction/ecosystem)** lists our recommendations, and there's a complete listing available in the **[Redux addons catalog](https://github.com/markerikson/redux-ecosystem-links)**.
|
55
|
+
- If you're looking to learn from actual application codebases, the addons catalog also has a list of **[purpose-built examples and real-world applications](https://github.com/markerikson/redux-ecosystem-links/blob/master/apps-and-examples.md)**.
|
56
|
+
|
57
|
+
Finally, Mark Erikson is teaching a series of **[Redux workshops through Workshop.me](#redux-workshops)**. Check the [workshop schedule](https://workshop.me/?a=mark) for upcoming dates and locations.
|
58
|
+
|
59
|
+
### Help and Discussion
|
60
|
+
|
61
|
+
The **[#redux channel](https://discord.gg/0ZcbPKXt5bZ6au5t)** of the **[Reactiflux Discord community](http://www.reactiflux.com)** is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - come join us!
|
62
|
+
|
63
|
+
## Before Proceeding Further
|
64
|
+
|
65
|
+
Redux is a valuable tool for organizing your state, but you should also consider whether it's appropriate for your situation. Don't use Redux just because someone said you should - take some time to understand the potential benefits and tradeoffs of using it.
|
66
|
+
|
67
|
+
Here are some suggestions on when it makes sense to use Redux:
|
68
|
+
|
69
|
+
- You have reasonable amounts of data changing over time
|
70
|
+
- You need a single source of truth for your state
|
71
|
+
- You find that keeping all your state in a top-level component is no longer sufficient
|
72
|
+
|
73
|
+
Yes, these guidelines are subjective and vague, but this is for good reason. The point at which you should integrate Redux into your application is different for every user and different for every application.
|
74
|
+
|
75
|
+
> **For more thoughts on how Redux is meant to be used, see:**<br>
|
76
|
+
>
|
77
|
+
> - **[You Might Not Need Redux](https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367)**<br>
|
78
|
+
> - **[The Tao of Redux, Part 1 - Implementation and Intent](http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1/)**<br>
|
79
|
+
> - **[The Tao of Redux, Part 2 - Practice and Philosophy](http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-2/)**
|
80
|
+
> - **[Redux FAQ](https://redux.js.org/faq)**
|
81
|
+
|
82
|
+
## Developer Experience
|
83
|
+
|
84
|
+
Dan Abramov (author of Redux) wrote Redux while working on his React Europe talk called [“Hot Reloading with Time Travel”](https://www.youtube.com/watch?v=xsSnOQynTHs). His goal was to create a state management library with a minimal API but completely predictable behavior. Redux makes it possible to implement logging, hot reloading, time travel, universal apps, record and replay, without any buy-in from the developer.
|
85
|
+
|
86
|
+
## Influences
|
87
|
+
|
88
|
+
Redux evolves the ideas of [Flux](http://facebook.github.io/flux/), but avoids its complexity by taking cues from [Elm](https://github.com/evancz/elm-architecture-tutorial/).
|
89
|
+
Even if you haven't used Flux or Elm, Redux only takes a few minutes to get started with.
|
90
|
+
|
91
|
+
## Installation
|
92
|
+
|
93
|
+
To install the stable version:
|
94
|
+
|
95
|
+
```sh
|
96
|
+
npm install --save redux
|
97
|
+
```
|
98
|
+
|
99
|
+
This assumes you are using [npm](https://www.npmjs.com/) as your package manager.
|
100
|
+
|
101
|
+
If you're not, you can [access these files on unpkg](https://unpkg.com/redux/), download them, or point your package manager to them.
|
102
|
+
|
103
|
+
Most commonly, people consume Redux as a collection of [CommonJS](https://github.com/webpack/docs/wiki/commonjs) modules. These modules are what you get when you import `redux` in a [Webpack](https://webpack.js.org/), [Browserify](http://browserify.org/), or a Node environment. If you like to live on the edge and use [Rollup](https://rollupjs.org), we support that as well.
|
104
|
+
|
105
|
+
If you don't use a module bundler, it's also fine. The `redux` npm package includes precompiled production and development [UMD](https://github.com/umdjs/umd) builds in the [`dist` folder](https://unpkg.com/redux/dist/). They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. For example, you can drop a UMD build as a [`<script>` tag](https://unpkg.com/redux/dist/redux.js) on the page, or [tell Bower to install it](https://github.com/reduxjs/redux/pull/1181#issuecomment-167361975). The UMD builds make Redux available as a `window.Redux` global variable.
|
106
|
+
|
107
|
+
The Redux source code is written in ES2015 but we precompile both CommonJS and UMD builds to ES5 so they work in [any modern browser](http://caniuse.com/#feat=es5). You don't need to use Babel or a module bundler to [get started with Redux](https://github.com/reduxjs/redux/blob/master/examples/counter-vanilla/index.html). You can even use the ES module build that's available at [`es/redux.mjs`](https://unpkg.com/redux/es/) which can be referenced using `type="module"` in your `script` tag or as a standard `import`.
|
108
|
+
|
109
|
+
### Complementary Packages
|
110
|
+
|
111
|
+
Most likely, you'll also need [the React bindings](https://github.com/reduxjs/react-redux) and [the developer tools](https://github.com/reduxjs/redux-devtools).
|
112
|
+
|
113
|
+
```sh
|
114
|
+
npm install --save react-redux
|
115
|
+
npm install --save-dev redux-devtools
|
116
|
+
```
|
117
|
+
|
118
|
+
Note that unlike Redux itself, many packages in the Redux ecosystem don't provide UMD builds, so we recommend using CommonJS module bundlers like [Webpack](https://webpack.js.org/) and [Browserify](http://browserify.org/) for the most comfortable development experience.
|
119
|
+
|
120
|
+
## The Gist
|
121
|
+
|
122
|
+
The whole state of your app is stored in an object tree inside a single _store_.
|
123
|
+
The only way to change the state tree is to emit an _action_, an object describing what happened.
|
124
|
+
To specify how the actions transform the state tree, you write pure _reducers_.
|
125
|
+
|
126
|
+
That's it!
|
127
|
+
|
128
|
+
```js
|
129
|
+
import { createStore } from 'redux'
|
130
|
+
|
131
|
+
/**
|
132
|
+
* This is a reducer, a pure function with (state, action) => state signature.
|
133
|
+
* It describes how an action transforms the state into the next state.
|
134
|
+
*
|
135
|
+
* The shape of the state is up to you: it can be a primitive, an array, an object,
|
136
|
+
* or even an Immutable.js data structure. The only important part is that you should
|
137
|
+
* not mutate the state object, but return a new object if the state changes.
|
138
|
+
*
|
139
|
+
* In this example, we use a `switch` statement and strings, but you can use a helper that
|
140
|
+
* follows a different convention (such as function maps) if it makes sense for your
|
141
|
+
* project.
|
142
|
+
*/
|
143
|
+
function counter(state = 0, action) {
|
144
|
+
switch (action.type) {
|
145
|
+
case 'INCREMENT':
|
146
|
+
return state + 1
|
147
|
+
case 'DECREMENT':
|
148
|
+
return state - 1
|
149
|
+
default:
|
150
|
+
return state
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
// Create a Redux store holding the state of your app.
|
155
|
+
// Its API is { subscribe, dispatch, getState }.
|
156
|
+
let store = createStore(counter)
|
157
|
+
|
158
|
+
// You can use subscribe() to update the UI in response to state changes.
|
159
|
+
// Normally you'd use a view binding library (e.g. React Redux) rather than subscribe() directly.
|
160
|
+
// However it can also be handy to persist the current state in the localStorage.
|
161
|
+
|
162
|
+
store.subscribe(() => console.log(store.getState()))
|
163
|
+
|
164
|
+
// The only way to mutate the internal state is to dispatch an action.
|
165
|
+
// The actions can be serialized, logged or stored and later replayed.
|
166
|
+
store.dispatch({ type: 'INCREMENT' })
|
167
|
+
// 1
|
168
|
+
store.dispatch({ type: 'INCREMENT' })
|
169
|
+
// 2
|
170
|
+
store.dispatch({ type: 'DECREMENT' })
|
171
|
+
// 1
|
172
|
+
```
|
173
|
+
|
174
|
+
Instead of mutating the state directly, you specify the mutations you want to happen with plain objects called _actions_. Then you write a special function called a _reducer_ to decide how every action transforms the entire application's state.
|
175
|
+
|
176
|
+
If you're coming from Flux, there is a single important difference you need to understand. Redux doesn't have a Dispatcher or support many stores. Instead, there is just a single store with a single root reducing function. As your app grows, instead of adding stores, you split the root reducer into smaller reducers independently operating on the different parts of the state tree. This is exactly like how there is just one root component in a React app, but it is composed out of many small components.
|
177
|
+
|
178
|
+
This architecture might seem like an overkill for a counter app, but the beauty of this pattern is how well it scales to large and complex apps. It also enables very powerful developer tools, because it is possible to trace every mutation to the action that caused it. You can record user sessions and reproduce them just by replaying every action.
|
179
|
+
|
180
|
+
## Learn Redux from Its Authors
|
181
|
+
|
182
|
+
### Redux Video Tutorials by Dan Abramov
|
183
|
+
|
184
|
+
#### Getting Started with Redux
|
185
|
+
|
186
|
+
**[Getting Started with Redux](https://egghead.io/series/getting-started-with-redux)** is a video course consisting of 30 videos narrated by [Dan Abramov](https://twitter.com/dan_abramov), author of Redux. It is designed to complement the “Basics” part of the docs while bringing additional insights about immutability, testing, Redux best practices, and using Redux with React. **This course is free and will always be.**
|
187
|
+
|
188
|
+
> [“Great course on egghead.io by @dan_abramov - instead of just showing you how to use #redux, it also shows how and why redux was built!”](https://twitter.com/sandrinodm/status/670548531422326785)
|
189
|
+
> Sandrino Di Mattia
|
190
|
+
|
191
|
+
> [“Plowing through @dan_abramov 'Getting Started with Redux' - its amazing how much simpler concepts get with video.”](https://twitter.com/chrisdhanaraj/status/670328025553219584)
|
192
|
+
> Chris Dhanaraj
|
193
|
+
|
194
|
+
> [“This video series on Redux by @dan_abramov on @eggheadio is spectacular!”](https://twitter.com/eddiezane/status/670333133242408960)
|
195
|
+
> Eddie Zaneski
|
196
|
+
|
197
|
+
> [“Come for the name hype. Stay for the rock solid fundamentals. (Thanks, and great job @dan_abramov and @eggheadio!)”](https://twitter.com/danott/status/669909126554607617)
|
198
|
+
> Dan
|
199
|
+
|
200
|
+
> [“This series of videos on Redux by @dan_abramov is repeatedly blowing my mind - gunna do some serious refactoring”](https://twitter.com/gelatindesign/status/669658358643892224)
|
201
|
+
> Laurence Roberts
|
202
|
+
|
203
|
+
So, what are you waiting for?
|
204
|
+
|
205
|
+
#### [Watch the free "Getting Started with Redux" video series](https://egghead.io/series/getting-started-with-redux)
|
206
|
+
|
207
|
+
> Note: If you enjoyed Dan's course, consider supporting Egghead by [buying a subscription](https://egghead.io/pricing). Subscribers have access to the source code of every example in my videos and tons of advanced lessons on other topics, including JavaScript in depth, React, Angular, and more. Many [Egghead instructors](https://egghead.io/instructors) are also open source library authors, so buying a subscription is a nice way to thank them for the work that they've done.
|
208
|
+
|
209
|
+
#### Building React Applications with Idiomatic Redux
|
210
|
+
|
211
|
+
The **[Building React Applications with Idiomatic Redux](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)** course is a second free video series by Dan Abramov. It picks up where the first series left off, and covers practical production ready techniques for building your React and Redux applications: advanced state management, middleware, React Router integration, and other common problems you are likely to encounter while building applications for your clients and customers. As with the first series, **this course will always be free**.
|
212
|
+
|
213
|
+
#### [Watch the free "Idiomatic Redux" video series](https://egghead.io/courses/building-react-applications-with-idiomatic-redux)
|
214
|
+
|
215
|
+
### Practical Redux course
|
216
|
+
|
217
|
+
**[Practical Redux](https://www.educative.io/collection/5687753853370368/5707702298738688/)** is a paid interactive course by Redux co-maintainer [Mark Erikson](https://twitter.com/acemarke). The course is designed to show how to apply the basic concepts of Redux to building something larger than a TodoMVC application. It includes real-world topics like:
|
218
|
+
|
219
|
+
- Adding Redux to a new Create-React-App project and configuring Hot Module Replacement for faster development
|
220
|
+
- Controlling your UI behavior with Redux
|
221
|
+
- Using the Redux-ORM library to manage relational data in your Redux store
|
222
|
+
- Building a master/detail view to display and edit data
|
223
|
+
- Writing custom advanced Redux reducer logic to solve specific problems
|
224
|
+
- Optimizing performance of Redux-connected form inputs
|
225
|
+
|
226
|
+
And much more!
|
227
|
+
|
228
|
+
The course is based on Mark's original free **["Practical Redux" blog tutorial series](http://blog.isquaredsoftware.com/series/practical-redux/)**, but with updated and improved content.
|
229
|
+
|
230
|
+
### Redux Fundamentals Workshop
|
231
|
+
|
232
|
+
Redux co-maintainer [Mark Erikson](https://twitter.com/acemarke) has put together a [**Redux Fundamentals workshop**, and slides are available here](https://blog.isquaredsoftware.com/2018/06/redux-fundamentals-workshop-slides/). They cover:
|
233
|
+
|
234
|
+
- The history and purpose of Redux
|
235
|
+
- Reducers and actions, and working with a Redux store
|
236
|
+
- Using Redux with React
|
237
|
+
- Using and writing Redux middleware
|
238
|
+
- Working with AJAX calls and other side effects
|
239
|
+
- Unit testing Redux apps
|
240
|
+
- Real-world Redux app structure and development
|
241
|
+
|
242
|
+
## Documentation
|
243
|
+
|
244
|
+
- [Introduction](http://redux.js.org/introduction)
|
245
|
+
- [Basics](http://redux.js.org/basics)
|
246
|
+
- [Advanced](http://redux.js.org/advanced)
|
247
|
+
- [Recipes](http://redux.js.org/recipes)
|
248
|
+
- [FAQ](http://redux.js.org/faq)
|
249
|
+
- [Troubleshooting](http://redux.js.org/troubleshooting)
|
250
|
+
- [Glossary](http://redux.js.org/glossary)
|
251
|
+
- [API Reference](http://redux.js.org/api)
|
252
|
+
|
253
|
+
For PDF, ePub, and MOBI exports for offline reading, and instructions on how to create them, please see: [paulkogel/redux-offline-docs](https://github.com/paulkogel/redux-offline-docs).
|
254
|
+
|
255
|
+
For Offline docs, please see: [devdocs](http://devdocs.io/redux/)
|
256
|
+
|
257
|
+
## Examples
|
258
|
+
|
259
|
+
Almost all examples have a corresponding CodeSandbox sandbox. This is an interactive version of the code that you can play with online.
|
260
|
+
|
261
|
+
- [**Counter Vanilla**](https://redux.js.org/introduction/examples#counter-vanilla): [Source](https://github.com/reduxjs/redux/tree/master/examples/counter-vanilla)
|
262
|
+
- [**Counter**](https://redux.js.org/introduction/examples#counter): [Source](https://github.com/reduxjs/redux/tree/master/examples/counter) | [Sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/counter)
|
263
|
+
- [**Todos**](https://redux.js.org/introduction/examples#todos): [Source](https://github.com/reduxjs/redux/tree/master/examples/todos) | [Sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todos)
|
264
|
+
- [**Todos with Undo**](https://redux.js.org/introduction/examples#todos-with-undo): [Source](https://github.com/reduxjs/redux/tree/master/examples/todos-with-undo) | [Sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todos-with-undo)
|
265
|
+
- [**Todos w/ Flow**](https://redux.js.org/introduction/examples#todos-flow): [Source](https://github.com/reduxjs/redux/tree/master/examples/todos-flow)
|
266
|
+
- [**TodoMVC**](https://redux.js.org/introduction/examples#todomvc): [Source](https://github.com/reduxjs/redux/tree/master/examples/todomvc) | [Sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/todomvc)
|
267
|
+
- [**Shopping Cart**](https://redux.js.org/introduction/examples#shopping-cart): [Source](https://github.com/reduxjs/redux/tree/master/examples/shopping-cart) | [Sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/shopping-cart)
|
268
|
+
- [**Tree View**](https://redux.js.org/introduction/examples#tree-view): [Source](https://github.com/reduxjs/redux/tree/master/examples/tree-view) | [Sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/tree-view)
|
269
|
+
- [**Async**](https://redux.js.org/introduction/examples#async): [Source](https://github.com/reduxjs/redux/tree/master/examples/async) | [Sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/async)
|
270
|
+
- [**Universal**](https://redux.js.org/introduction/examples#universal): [Source](https://github.com/reduxjs/redux/tree/master/examples/universal)
|
271
|
+
- [**Real World**](https://redux.js.org/introduction/examples#real-world): [Source](https://github.com/reduxjs/redux/tree/master/examples/real-world) | [Sandbox](https://codesandbox.io/s/github/reduxjs/redux/tree/master/examples/real-world)
|
272
|
+
|
273
|
+
If you're new to the NPM ecosystem and have troubles getting a project up and running, or aren't sure where to paste the gist above, check out [simplest-redux-example](https://github.com/jackielii/simplest-redux-example) that uses Redux together with React and Browserify.
|
274
|
+
|
275
|
+
## Testimonials
|
276
|
+
|
277
|
+
> [“Love what you're doing with Redux”](https://twitter.com/jingc/status/616608251463909376)
|
278
|
+
> Jing Chen, creator of Flux
|
279
|
+
|
280
|
+
> [“I asked for comments on Redux in FB's internal JS discussion group, and it was universally praised. Really awesome work.”](https://twitter.com/fisherwebdev/status/616286955693682688)
|
281
|
+
> Bill Fisher, author of Flux documentation
|
282
|
+
|
283
|
+
> [“It's cool that you are inventing a better Flux by not doing Flux at all.”](https://twitter.com/andrestaltz/status/616271392930201604)
|
284
|
+
> André Staltz, creator of Cycle
|
285
|
+
|
286
|
+
## Thanks
|
287
|
+
|
288
|
+
- [The Elm Architecture](https://github.com/evancz/elm-architecture-tutorial) for a great intro to modeling state updates with reducers;
|
289
|
+
- [Turning the database inside-out](https://www.confluent.io/blog/turning-the-database-inside-out-with-apache-samza/) for blowing my mind;
|
290
|
+
- [Developing ClojureScript with Figwheel](https://www.youtube.com/watch?v=j-kj2qwJa_E) for convincing me that re-evaluation should “just work”;
|
291
|
+
- [Webpack](https://webpack.js.org/concepts/hot-module-replacement/) for Hot Module Replacement;
|
292
|
+
- [Flummox](https://github.com/acdlite/flummox) for teaching me to approach Flux without boilerplate or singletons;
|
293
|
+
- [disto](https://github.com/threepointone/disto) for a proof of concept of hot reloadable Stores;
|
294
|
+
- [NuclearJS](https://github.com/optimizely/nuclear-js) for proving this architecture can be performant;
|
295
|
+
- [Om](https://github.com/omcljs/om) for popularizing the idea of a single state atom;
|
296
|
+
- [Cycle](https://github.com/cyclejs/cycle-core) for showing how often a function is the best tool;
|
297
|
+
- [React](https://github.com/facebook/react) for the pragmatic innovation.
|
298
|
+
|
299
|
+
Special thanks to [Jamie Paton](http://jdpaton.github.io) for handing over the `redux` NPM package name.
|
300
|
+
|
301
|
+
## Logo
|
302
|
+
|
303
|
+
You can find the official logo [on GitHub](https://github.com/reduxjs/redux/tree/master/logo).
|
304
|
+
|
305
|
+
## Change Log
|
306
|
+
|
307
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
308
|
+
Every release, along with the migration instructions, is documented on the GitHub [Releases](https://github.com/reduxjs/redux/releases) page.
|
309
|
+
|
310
|
+
## Patrons
|
311
|
+
|
312
|
+
The work on Redux was [funded by the community](https://www.patreon.com/reactdx).
|
313
|
+
Meet some of the outstanding companies that made it possible:
|
314
|
+
|
315
|
+
- [Webflow](https://github.com/webflow)
|
316
|
+
- [Ximedes](https://www.ximedes.com/)
|
317
|
+
|
318
|
+
[See the full list of Redux patrons](PATRONS.md), as well as the always-growing list of [people and companies that use Redux](https://github.com/reduxjs/redux/issues/310).
|
319
|
+
|
320
|
+
## License
|
321
|
+
|
322
|
+
[MIT](LICENSE.md)
|
@@ -0,0 +1,735 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Redux = {}));
|
5
|
+
}(this, (function (exports) { 'use strict';
|
6
|
+
|
7
|
+
// Inlined version of the `symbol-observable` polyfill
|
8
|
+
var $$observable = (function () {
|
9
|
+
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
10
|
+
})();
|
11
|
+
|
12
|
+
/**
|
13
|
+
* These are private action types reserved by Redux.
|
14
|
+
* For any unknown actions, you must return the current state.
|
15
|
+
* If the current state is undefined, you must return the initial state.
|
16
|
+
* Do not reference these action types directly in your code.
|
17
|
+
*/
|
18
|
+
var randomString = function randomString() {
|
19
|
+
return Math.random().toString(36).substring(7).split('').join('.');
|
20
|
+
};
|
21
|
+
|
22
|
+
var ActionTypes = {
|
23
|
+
INIT: "@@redux/INIT" + randomString(),
|
24
|
+
REPLACE: "@@redux/REPLACE" + randomString(),
|
25
|
+
PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
|
26
|
+
return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @param {any} obj The object to inspect.
|
32
|
+
* @returns {boolean} True if the argument appears to be a plain object.
|
33
|
+
*/
|
34
|
+
function isPlainObject(obj) {
|
35
|
+
if (typeof obj !== 'object' || obj === null) return false;
|
36
|
+
var proto = obj;
|
37
|
+
|
38
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
39
|
+
proto = Object.getPrototypeOf(proto);
|
40
|
+
}
|
41
|
+
|
42
|
+
return Object.getPrototypeOf(obj) === proto;
|
43
|
+
}
|
44
|
+
|
45
|
+
// Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of
|
46
|
+
function miniKindOf(val) {
|
47
|
+
if (val === void 0) return 'undefined';
|
48
|
+
if (val === null) return 'null';
|
49
|
+
var type = typeof val;
|
50
|
+
|
51
|
+
switch (type) {
|
52
|
+
case 'boolean':
|
53
|
+
case 'string':
|
54
|
+
case 'number':
|
55
|
+
case 'symbol':
|
56
|
+
case 'function':
|
57
|
+
{
|
58
|
+
return type;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
if (Array.isArray(val)) return 'array';
|
63
|
+
if (isDate(val)) return 'date';
|
64
|
+
if (isError(val)) return 'error';
|
65
|
+
var constructorName = ctorName(val);
|
66
|
+
|
67
|
+
switch (constructorName) {
|
68
|
+
case 'Symbol':
|
69
|
+
case 'Promise':
|
70
|
+
case 'WeakMap':
|
71
|
+
case 'WeakSet':
|
72
|
+
case 'Map':
|
73
|
+
case 'Set':
|
74
|
+
return constructorName;
|
75
|
+
} // other
|
76
|
+
|
77
|
+
|
78
|
+
return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
79
|
+
}
|
80
|
+
|
81
|
+
function ctorName(val) {
|
82
|
+
return typeof val.constructor === 'function' ? val.constructor.name : null;
|
83
|
+
}
|
84
|
+
|
85
|
+
function isError(val) {
|
86
|
+
return val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number';
|
87
|
+
}
|
88
|
+
|
89
|
+
function isDate(val) {
|
90
|
+
if (val instanceof Date) return true;
|
91
|
+
return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function';
|
92
|
+
}
|
93
|
+
|
94
|
+
function kindOf(val) {
|
95
|
+
var typeOfVal = typeof val;
|
96
|
+
|
97
|
+
{
|
98
|
+
typeOfVal = miniKindOf(val);
|
99
|
+
}
|
100
|
+
|
101
|
+
return typeOfVal;
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Creates a Redux store that holds the state tree.
|
106
|
+
* The only way to change the data in the store is to call `dispatch()` on it.
|
107
|
+
*
|
108
|
+
* There should only be a single store in your app. To specify how different
|
109
|
+
* parts of the state tree respond to actions, you may combine several reducers
|
110
|
+
* into a single reducer function by using `combineReducers`.
|
111
|
+
*
|
112
|
+
* @param {Function} reducer A function that returns the next state tree, given
|
113
|
+
* the current state tree and the action to handle.
|
114
|
+
*
|
115
|
+
* @param {any} [preloadedState] The initial state. You may optionally specify it
|
116
|
+
* to hydrate the state from the server in universal apps, or to restore a
|
117
|
+
* previously serialized user session.
|
118
|
+
* If you use `combineReducers` to produce the root reducer function, this must be
|
119
|
+
* an object with the same shape as `combineReducers` keys.
|
120
|
+
*
|
121
|
+
* @param {Function} [enhancer] The store enhancer. You may optionally specify it
|
122
|
+
* to enhance the store with third-party capabilities such as middleware,
|
123
|
+
* time travel, persistence, etc. The only store enhancer that ships with Redux
|
124
|
+
* is `applyMiddleware()`.
|
125
|
+
*
|
126
|
+
* @returns {Store} A Redux store that lets you read the state, dispatch actions
|
127
|
+
* and subscribe to changes.
|
128
|
+
*/
|
129
|
+
|
130
|
+
function createStore(reducer, preloadedState, enhancer) {
|
131
|
+
var _ref2;
|
132
|
+
|
133
|
+
if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
|
134
|
+
throw new Error('It looks like you are passing several store enhancers to ' + 'createStore(). This is not supported. Instead, compose them ' + 'together to a single function. See https://redux.js.org/tutorials/fundamentals/part-4-store#creating-a-store-with-enhancers for an example.');
|
135
|
+
}
|
136
|
+
|
137
|
+
if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
|
138
|
+
enhancer = preloadedState;
|
139
|
+
preloadedState = undefined;
|
140
|
+
}
|
141
|
+
|
142
|
+
if (typeof enhancer !== 'undefined') {
|
143
|
+
if (typeof enhancer !== 'function') {
|
144
|
+
throw new Error("Expected the enhancer to be a function. Instead, received: '" + kindOf(enhancer) + "'");
|
145
|
+
}
|
146
|
+
|
147
|
+
return enhancer(createStore)(reducer, preloadedState);
|
148
|
+
}
|
149
|
+
|
150
|
+
if (typeof reducer !== 'function') {
|
151
|
+
throw new Error("Expected the root reducer to be a function. Instead, received: '" + kindOf(reducer) + "'");
|
152
|
+
}
|
153
|
+
|
154
|
+
var currentReducer = reducer;
|
155
|
+
var currentState = preloadedState;
|
156
|
+
var currentListeners = [];
|
157
|
+
var nextListeners = currentListeners;
|
158
|
+
var isDispatching = false;
|
159
|
+
/**
|
160
|
+
* This makes a shallow copy of currentListeners so we can use
|
161
|
+
* nextListeners as a temporary list while dispatching.
|
162
|
+
*
|
163
|
+
* This prevents any bugs around consumers calling
|
164
|
+
* subscribe/unsubscribe in the middle of a dispatch.
|
165
|
+
*/
|
166
|
+
|
167
|
+
function ensureCanMutateNextListeners() {
|
168
|
+
if (nextListeners === currentListeners) {
|
169
|
+
nextListeners = currentListeners.slice();
|
170
|
+
}
|
171
|
+
}
|
172
|
+
/**
|
173
|
+
* Reads the state tree managed by the store.
|
174
|
+
*
|
175
|
+
* @returns {any} The current state tree of your application.
|
176
|
+
*/
|
177
|
+
|
178
|
+
|
179
|
+
function getState() {
|
180
|
+
if (isDispatching) {
|
181
|
+
throw new Error('You may not call store.getState() while the reducer is executing. ' + 'The reducer has already received the state as an argument. ' + 'Pass it down from the top reducer instead of reading it from the store.');
|
182
|
+
}
|
183
|
+
|
184
|
+
return currentState;
|
185
|
+
}
|
186
|
+
/**
|
187
|
+
* Adds a change listener. It will be called any time an action is dispatched,
|
188
|
+
* and some part of the state tree may potentially have changed. You may then
|
189
|
+
* call `getState()` to read the current state tree inside the callback.
|
190
|
+
*
|
191
|
+
* You may call `dispatch()` from a change listener, with the following
|
192
|
+
* caveats:
|
193
|
+
*
|
194
|
+
* 1. The subscriptions are snapshotted just before every `dispatch()` call.
|
195
|
+
* If you subscribe or unsubscribe while the listeners are being invoked, this
|
196
|
+
* will not have any effect on the `dispatch()` that is currently in progress.
|
197
|
+
* However, the next `dispatch()` call, whether nested or not, will use a more
|
198
|
+
* recent snapshot of the subscription list.
|
199
|
+
*
|
200
|
+
* 2. The listener should not expect to see all state changes, as the state
|
201
|
+
* might have been updated multiple times during a nested `dispatch()` before
|
202
|
+
* the listener is called. It is, however, guaranteed that all subscribers
|
203
|
+
* registered before the `dispatch()` started will be called with the latest
|
204
|
+
* state by the time it exits.
|
205
|
+
*
|
206
|
+
* @param {Function} listener A callback to be invoked on every dispatch.
|
207
|
+
* @returns {Function} A function to remove this change listener.
|
208
|
+
*/
|
209
|
+
|
210
|
+
|
211
|
+
function subscribe(listener) {
|
212
|
+
if (typeof listener !== 'function') {
|
213
|
+
throw new Error("Expected the listener to be a function. Instead, received: '" + kindOf(listener) + "'");
|
214
|
+
}
|
215
|
+
|
216
|
+
if (isDispatching) {
|
217
|
+
throw new Error('You may not call store.subscribe() while the reducer is executing. ' + 'If you would like to be notified after the store has been updated, subscribe from a ' + 'component and invoke store.getState() in the callback to access the latest state. ' + 'See https://redux.js.org/api/store#subscribelistener for more details.');
|
218
|
+
}
|
219
|
+
|
220
|
+
var isSubscribed = true;
|
221
|
+
ensureCanMutateNextListeners();
|
222
|
+
nextListeners.push(listener);
|
223
|
+
return function unsubscribe() {
|
224
|
+
if (!isSubscribed) {
|
225
|
+
return;
|
226
|
+
}
|
227
|
+
|
228
|
+
if (isDispatching) {
|
229
|
+
throw new Error('You may not unsubscribe from a store listener while the reducer is executing. ' + 'See https://redux.js.org/api/store#subscribelistener for more details.');
|
230
|
+
}
|
231
|
+
|
232
|
+
isSubscribed = false;
|
233
|
+
ensureCanMutateNextListeners();
|
234
|
+
var index = nextListeners.indexOf(listener);
|
235
|
+
nextListeners.splice(index, 1);
|
236
|
+
currentListeners = null;
|
237
|
+
};
|
238
|
+
}
|
239
|
+
/**
|
240
|
+
* Dispatches an action. It is the only way to trigger a state change.
|
241
|
+
*
|
242
|
+
* The `reducer` function, used to create the store, will be called with the
|
243
|
+
* current state tree and the given `action`. Its return value will
|
244
|
+
* be considered the **next** state of the tree, and the change listeners
|
245
|
+
* will be notified.
|
246
|
+
*
|
247
|
+
* The base implementation only supports plain object actions. If you want to
|
248
|
+
* dispatch a Promise, an Observable, a thunk, or something else, you need to
|
249
|
+
* wrap your store creating function into the corresponding middleware. For
|
250
|
+
* example, see the documentation for the `redux-thunk` package. Even the
|
251
|
+
* middleware will eventually dispatch plain object actions using this method.
|
252
|
+
*
|
253
|
+
* @param {Object} action A plain object representing “what changed”. It is
|
254
|
+
* a good idea to keep actions serializable so you can record and replay user
|
255
|
+
* sessions, or use the time travelling `redux-devtools`. An action must have
|
256
|
+
* a `type` property which may not be `undefined`. It is a good idea to use
|
257
|
+
* string constants for action types.
|
258
|
+
*
|
259
|
+
* @returns {Object} For convenience, the same action object you dispatched.
|
260
|
+
*
|
261
|
+
* Note that, if you use a custom middleware, it may wrap `dispatch()` to
|
262
|
+
* return something else (for example, a Promise you can await).
|
263
|
+
*/
|
264
|
+
|
265
|
+
|
266
|
+
function dispatch(action) {
|
267
|
+
if (!isPlainObject(action)) {
|
268
|
+
throw new Error("Actions must be plain objects. Instead, the actual type was: '" + kindOf(action) + "'. You may need to add middleware to your store setup to handle dispatching other values, such as 'redux-thunk' to handle dispatching functions. See https://redux.js.org/tutorials/fundamentals/part-4-store#middleware and https://redux.js.org/tutorials/fundamentals/part-6-async-logic#using-the-redux-thunk-middleware for examples.");
|
269
|
+
}
|
270
|
+
|
271
|
+
if (typeof action.type === 'undefined') {
|
272
|
+
throw new Error('Actions may not have an undefined "type" property. You may have misspelled an action type string constant.');
|
273
|
+
}
|
274
|
+
|
275
|
+
if (isDispatching) {
|
276
|
+
throw new Error('Reducers may not dispatch actions.');
|
277
|
+
}
|
278
|
+
|
279
|
+
try {
|
280
|
+
isDispatching = true;
|
281
|
+
currentState = currentReducer(currentState, action);
|
282
|
+
} finally {
|
283
|
+
isDispatching = false;
|
284
|
+
}
|
285
|
+
|
286
|
+
var listeners = currentListeners = nextListeners;
|
287
|
+
|
288
|
+
for (var i = 0; i < listeners.length; i++) {
|
289
|
+
var listener = listeners[i];
|
290
|
+
listener();
|
291
|
+
}
|
292
|
+
|
293
|
+
return action;
|
294
|
+
}
|
295
|
+
/**
|
296
|
+
* Replaces the reducer currently used by the store to calculate the state.
|
297
|
+
*
|
298
|
+
* You might need this if your app implements code splitting and you want to
|
299
|
+
* load some of the reducers dynamically. You might also need this if you
|
300
|
+
* implement a hot reloading mechanism for Redux.
|
301
|
+
*
|
302
|
+
* @param {Function} nextReducer The reducer for the store to use instead.
|
303
|
+
* @returns {void}
|
304
|
+
*/
|
305
|
+
|
306
|
+
|
307
|
+
function replaceReducer(nextReducer) {
|
308
|
+
if (typeof nextReducer !== 'function') {
|
309
|
+
throw new Error("Expected the nextReducer to be a function. Instead, received: '" + kindOf(nextReducer));
|
310
|
+
}
|
311
|
+
|
312
|
+
currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
|
313
|
+
// Any reducers that existed in both the new and old rootReducer
|
314
|
+
// will receive the previous state. This effectively populates
|
315
|
+
// the new state tree with any relevant data from the old one.
|
316
|
+
|
317
|
+
dispatch({
|
318
|
+
type: ActionTypes.REPLACE
|
319
|
+
});
|
320
|
+
}
|
321
|
+
/**
|
322
|
+
* Interoperability point for observable/reactive libraries.
|
323
|
+
* @returns {observable} A minimal observable of state changes.
|
324
|
+
* For more information, see the observable proposal:
|
325
|
+
* https://github.com/tc39/proposal-observable
|
326
|
+
*/
|
327
|
+
|
328
|
+
|
329
|
+
function observable() {
|
330
|
+
var _ref;
|
331
|
+
|
332
|
+
var outerSubscribe = subscribe;
|
333
|
+
return _ref = {
|
334
|
+
/**
|
335
|
+
* The minimal observable subscription method.
|
336
|
+
* @param {Object} observer Any object that can be used as an observer.
|
337
|
+
* The observer object should have a `next` method.
|
338
|
+
* @returns {subscription} An object with an `unsubscribe` method that can
|
339
|
+
* be used to unsubscribe the observable from the store, and prevent further
|
340
|
+
* emission of values from the observable.
|
341
|
+
*/
|
342
|
+
subscribe: function subscribe(observer) {
|
343
|
+
if (typeof observer !== 'object' || observer === null) {
|
344
|
+
throw new Error("Expected the observer to be an object. Instead, received: '" + kindOf(observer) + "'");
|
345
|
+
}
|
346
|
+
|
347
|
+
function observeState() {
|
348
|
+
if (observer.next) {
|
349
|
+
observer.next(getState());
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
353
|
+
observeState();
|
354
|
+
var unsubscribe = outerSubscribe(observeState);
|
355
|
+
return {
|
356
|
+
unsubscribe: unsubscribe
|
357
|
+
};
|
358
|
+
}
|
359
|
+
}, _ref[$$observable] = function () {
|
360
|
+
return this;
|
361
|
+
}, _ref;
|
362
|
+
} // When a store is created, an "INIT" action is dispatched so that every
|
363
|
+
// reducer returns their initial state. This effectively populates
|
364
|
+
// the initial state tree.
|
365
|
+
|
366
|
+
|
367
|
+
dispatch({
|
368
|
+
type: ActionTypes.INIT
|
369
|
+
});
|
370
|
+
return _ref2 = {
|
371
|
+
dispatch: dispatch,
|
372
|
+
subscribe: subscribe,
|
373
|
+
getState: getState,
|
374
|
+
replaceReducer: replaceReducer
|
375
|
+
}, _ref2[$$observable] = observable, _ref2;
|
376
|
+
}
|
377
|
+
|
378
|
+
/**
|
379
|
+
* Prints a warning in the console if it exists.
|
380
|
+
*
|
381
|
+
* @param {String} message The warning message.
|
382
|
+
* @returns {void}
|
383
|
+
*/
|
384
|
+
function warning(message) {
|
385
|
+
/* eslint-disable no-console */
|
386
|
+
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
387
|
+
console.error(message);
|
388
|
+
}
|
389
|
+
/* eslint-enable no-console */
|
390
|
+
|
391
|
+
|
392
|
+
try {
|
393
|
+
// This error was thrown as a convenience so that if you enable
|
394
|
+
// "break on all exceptions" in your console,
|
395
|
+
// it would pause the execution at this line.
|
396
|
+
throw new Error(message);
|
397
|
+
} catch (e) {} // eslint-disable-line no-empty
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
|
402
|
+
var reducerKeys = Object.keys(reducers);
|
403
|
+
var argumentName = action && action.type === ActionTypes.INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer';
|
404
|
+
|
405
|
+
if (reducerKeys.length === 0) {
|
406
|
+
return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.';
|
407
|
+
}
|
408
|
+
|
409
|
+
if (!isPlainObject(inputState)) {
|
410
|
+
return "The " + argumentName + " has unexpected type of \"" + kindOf(inputState) + "\". Expected argument to be an object with the following " + ("keys: \"" + reducerKeys.join('", "') + "\"");
|
411
|
+
}
|
412
|
+
|
413
|
+
var unexpectedKeys = Object.keys(inputState).filter(function (key) {
|
414
|
+
return !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key];
|
415
|
+
});
|
416
|
+
unexpectedKeys.forEach(function (key) {
|
417
|
+
unexpectedKeyCache[key] = true;
|
418
|
+
});
|
419
|
+
if (action && action.type === ActionTypes.REPLACE) return;
|
420
|
+
|
421
|
+
if (unexpectedKeys.length > 0) {
|
422
|
+
return "Unexpected " + (unexpectedKeys.length > 1 ? 'keys' : 'key') + " " + ("\"" + unexpectedKeys.join('", "') + "\" found in " + argumentName + ". ") + "Expected to find one of the known reducer keys instead: " + ("\"" + reducerKeys.join('", "') + "\". Unexpected keys will be ignored.");
|
423
|
+
}
|
424
|
+
}
|
425
|
+
|
426
|
+
function assertReducerShape(reducers) {
|
427
|
+
Object.keys(reducers).forEach(function (key) {
|
428
|
+
var reducer = reducers[key];
|
429
|
+
var initialState = reducer(undefined, {
|
430
|
+
type: ActionTypes.INIT
|
431
|
+
});
|
432
|
+
|
433
|
+
if (typeof initialState === 'undefined') {
|
434
|
+
throw new Error("The slice reducer for key \"" + key + "\" returned undefined during initialization. " + "If the state passed to the reducer is undefined, you must " + "explicitly return the initial state. The initial state may " + "not be undefined. If you don't want to set a value for this reducer, " + "you can use null instead of undefined.");
|
435
|
+
}
|
436
|
+
|
437
|
+
if (typeof reducer(undefined, {
|
438
|
+
type: ActionTypes.PROBE_UNKNOWN_ACTION()
|
439
|
+
}) === 'undefined') {
|
440
|
+
throw new Error("The slice reducer for key \"" + key + "\" returned undefined when probed with a random type. " + ("Don't try to handle '" + ActionTypes.INIT + "' or other actions in \"redux/*\" ") + "namespace. They are considered private. Instead, you must return the " + "current state for any unknown actions, unless it is undefined, " + "in which case you must return the initial state, regardless of the " + "action type. The initial state may not be undefined, but can be null.");
|
441
|
+
}
|
442
|
+
});
|
443
|
+
}
|
444
|
+
/**
|
445
|
+
* Turns an object whose values are different reducer functions, into a single
|
446
|
+
* reducer function. It will call every child reducer, and gather their results
|
447
|
+
* into a single state object, whose keys correspond to the keys of the passed
|
448
|
+
* reducer functions.
|
449
|
+
*
|
450
|
+
* @param {Object} reducers An object whose values correspond to different
|
451
|
+
* reducer functions that need to be combined into one. One handy way to obtain
|
452
|
+
* it is to use ES6 `import * as reducers` syntax. The reducers may never return
|
453
|
+
* undefined for any action. Instead, they should return their initial state
|
454
|
+
* if the state passed to them was undefined, and the current state for any
|
455
|
+
* unrecognized action.
|
456
|
+
*
|
457
|
+
* @returns {Function} A reducer function that invokes every reducer inside the
|
458
|
+
* passed object, and builds a state object with the same shape.
|
459
|
+
*/
|
460
|
+
|
461
|
+
|
462
|
+
function combineReducers(reducers) {
|
463
|
+
var reducerKeys = Object.keys(reducers);
|
464
|
+
var finalReducers = {};
|
465
|
+
|
466
|
+
for (var i = 0; i < reducerKeys.length; i++) {
|
467
|
+
var key = reducerKeys[i];
|
468
|
+
|
469
|
+
{
|
470
|
+
if (typeof reducers[key] === 'undefined') {
|
471
|
+
warning("No reducer provided for key \"" + key + "\"");
|
472
|
+
}
|
473
|
+
}
|
474
|
+
|
475
|
+
if (typeof reducers[key] === 'function') {
|
476
|
+
finalReducers[key] = reducers[key];
|
477
|
+
}
|
478
|
+
}
|
479
|
+
|
480
|
+
var finalReducerKeys = Object.keys(finalReducers); // This is used to make sure we don't warn about the same
|
481
|
+
// keys multiple times.
|
482
|
+
|
483
|
+
var unexpectedKeyCache;
|
484
|
+
|
485
|
+
{
|
486
|
+
unexpectedKeyCache = {};
|
487
|
+
}
|
488
|
+
|
489
|
+
var shapeAssertionError;
|
490
|
+
|
491
|
+
try {
|
492
|
+
assertReducerShape(finalReducers);
|
493
|
+
} catch (e) {
|
494
|
+
shapeAssertionError = e;
|
495
|
+
}
|
496
|
+
|
497
|
+
return function combination(state, action) {
|
498
|
+
if (state === void 0) {
|
499
|
+
state = {};
|
500
|
+
}
|
501
|
+
|
502
|
+
if (shapeAssertionError) {
|
503
|
+
throw shapeAssertionError;
|
504
|
+
}
|
505
|
+
|
506
|
+
{
|
507
|
+
var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
|
508
|
+
|
509
|
+
if (warningMessage) {
|
510
|
+
warning(warningMessage);
|
511
|
+
}
|
512
|
+
}
|
513
|
+
|
514
|
+
var hasChanged = false;
|
515
|
+
var nextState = {};
|
516
|
+
|
517
|
+
for (var _i = 0; _i < finalReducerKeys.length; _i++) {
|
518
|
+
var _key = finalReducerKeys[_i];
|
519
|
+
var reducer = finalReducers[_key];
|
520
|
+
var previousStateForKey = state[_key];
|
521
|
+
var nextStateForKey = reducer(previousStateForKey, action);
|
522
|
+
|
523
|
+
if (typeof nextStateForKey === 'undefined') {
|
524
|
+
var actionType = action && action.type;
|
525
|
+
throw new Error("When called with an action of type " + (actionType ? "\"" + String(actionType) + "\"" : '(unknown type)') + ", the slice reducer for key \"" + _key + "\" returned undefined. " + "To ignore an action, you must explicitly return the previous state. " + "If you want this reducer to hold no value, you can return null instead of undefined.");
|
526
|
+
}
|
527
|
+
|
528
|
+
nextState[_key] = nextStateForKey;
|
529
|
+
hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
|
530
|
+
}
|
531
|
+
|
532
|
+
hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
|
533
|
+
return hasChanged ? nextState : state;
|
534
|
+
};
|
535
|
+
}
|
536
|
+
|
537
|
+
function bindActionCreator(actionCreator, dispatch) {
|
538
|
+
return function () {
|
539
|
+
return dispatch(actionCreator.apply(this, arguments));
|
540
|
+
};
|
541
|
+
}
|
542
|
+
/**
|
543
|
+
* Turns an object whose values are action creators, into an object with the
|
544
|
+
* same keys, but with every function wrapped into a `dispatch` call so they
|
545
|
+
* may be invoked directly. This is just a convenience method, as you can call
|
546
|
+
* `store.dispatch(MyActionCreators.doSomething())` yourself just fine.
|
547
|
+
*
|
548
|
+
* For convenience, you can also pass an action creator as the first argument,
|
549
|
+
* and get a dispatch wrapped function in return.
|
550
|
+
*
|
551
|
+
* @param {Function|Object} actionCreators An object whose values are action
|
552
|
+
* creator functions. One handy way to obtain it is to use ES6 `import * as`
|
553
|
+
* syntax. You may also pass a single function.
|
554
|
+
*
|
555
|
+
* @param {Function} dispatch The `dispatch` function available on your Redux
|
556
|
+
* store.
|
557
|
+
*
|
558
|
+
* @returns {Function|Object} The object mimicking the original object, but with
|
559
|
+
* every action creator wrapped into the `dispatch` call. If you passed a
|
560
|
+
* function as `actionCreators`, the return value will also be a single
|
561
|
+
* function.
|
562
|
+
*/
|
563
|
+
|
564
|
+
|
565
|
+
function bindActionCreators(actionCreators, dispatch) {
|
566
|
+
if (typeof actionCreators === 'function') {
|
567
|
+
return bindActionCreator(actionCreators, dispatch);
|
568
|
+
}
|
569
|
+
|
570
|
+
if (typeof actionCreators !== 'object' || actionCreators === null) {
|
571
|
+
throw new Error("bindActionCreators expected an object or a function, but instead received: '" + kindOf(actionCreators) + "'. " + "Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?");
|
572
|
+
}
|
573
|
+
|
574
|
+
var boundActionCreators = {};
|
575
|
+
|
576
|
+
for (var key in actionCreators) {
|
577
|
+
var actionCreator = actionCreators[key];
|
578
|
+
|
579
|
+
if (typeof actionCreator === 'function') {
|
580
|
+
boundActionCreators[key] = bindActionCreator(actionCreator, dispatch);
|
581
|
+
}
|
582
|
+
}
|
583
|
+
|
584
|
+
return boundActionCreators;
|
585
|
+
}
|
586
|
+
|
587
|
+
function _defineProperty(obj, key, value) {
|
588
|
+
if (key in obj) {
|
589
|
+
Object.defineProperty(obj, key, {
|
590
|
+
value: value,
|
591
|
+
enumerable: true,
|
592
|
+
configurable: true,
|
593
|
+
writable: true
|
594
|
+
});
|
595
|
+
} else {
|
596
|
+
obj[key] = value;
|
597
|
+
}
|
598
|
+
|
599
|
+
return obj;
|
600
|
+
}
|
601
|
+
|
602
|
+
function ownKeys(object, enumerableOnly) {
|
603
|
+
var keys = Object.keys(object);
|
604
|
+
|
605
|
+
if (Object.getOwnPropertySymbols) {
|
606
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
607
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
608
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
609
|
+
});
|
610
|
+
keys.push.apply(keys, symbols);
|
611
|
+
}
|
612
|
+
|
613
|
+
return keys;
|
614
|
+
}
|
615
|
+
|
616
|
+
function _objectSpread2(target) {
|
617
|
+
for (var i = 1; i < arguments.length; i++) {
|
618
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
619
|
+
|
620
|
+
if (i % 2) {
|
621
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
622
|
+
_defineProperty(target, key, source[key]);
|
623
|
+
});
|
624
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
625
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
626
|
+
} else {
|
627
|
+
ownKeys(Object(source)).forEach(function (key) {
|
628
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
629
|
+
});
|
630
|
+
}
|
631
|
+
}
|
632
|
+
|
633
|
+
return target;
|
634
|
+
}
|
635
|
+
|
636
|
+
/**
|
637
|
+
* Composes single-argument functions from right to left. The rightmost
|
638
|
+
* function can take multiple arguments as it provides the signature for
|
639
|
+
* the resulting composite function.
|
640
|
+
*
|
641
|
+
* @param {...Function} funcs The functions to compose.
|
642
|
+
* @returns {Function} A function obtained by composing the argument functions
|
643
|
+
* from right to left. For example, compose(f, g, h) is identical to doing
|
644
|
+
* (...args) => f(g(h(...args))).
|
645
|
+
*/
|
646
|
+
function compose() {
|
647
|
+
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
|
648
|
+
funcs[_key] = arguments[_key];
|
649
|
+
}
|
650
|
+
|
651
|
+
if (funcs.length === 0) {
|
652
|
+
return function (arg) {
|
653
|
+
return arg;
|
654
|
+
};
|
655
|
+
}
|
656
|
+
|
657
|
+
if (funcs.length === 1) {
|
658
|
+
return funcs[0];
|
659
|
+
}
|
660
|
+
|
661
|
+
return funcs.reduce(function (a, b) {
|
662
|
+
return function () {
|
663
|
+
return a(b.apply(void 0, arguments));
|
664
|
+
};
|
665
|
+
});
|
666
|
+
}
|
667
|
+
|
668
|
+
/**
|
669
|
+
* Creates a store enhancer that applies middleware to the dispatch method
|
670
|
+
* of the Redux store. This is handy for a variety of tasks, such as expressing
|
671
|
+
* asynchronous actions in a concise manner, or logging every action payload.
|
672
|
+
*
|
673
|
+
* See `redux-thunk` package as an example of the Redux middleware.
|
674
|
+
*
|
675
|
+
* Because middleware is potentially asynchronous, this should be the first
|
676
|
+
* store enhancer in the composition chain.
|
677
|
+
*
|
678
|
+
* Note that each middleware will be given the `dispatch` and `getState` functions
|
679
|
+
* as named arguments.
|
680
|
+
*
|
681
|
+
* @param {...Function} middlewares The middleware chain to be applied.
|
682
|
+
* @returns {Function} A store enhancer applying the middleware.
|
683
|
+
*/
|
684
|
+
|
685
|
+
function applyMiddleware() {
|
686
|
+
for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) {
|
687
|
+
middlewares[_key] = arguments[_key];
|
688
|
+
}
|
689
|
+
|
690
|
+
return function (createStore) {
|
691
|
+
return function () {
|
692
|
+
var store = createStore.apply(void 0, arguments);
|
693
|
+
|
694
|
+
var _dispatch = function dispatch() {
|
695
|
+
throw new Error('Dispatching while constructing your middleware is not allowed. ' + 'Other middleware would not be applied to this dispatch.');
|
696
|
+
};
|
697
|
+
|
698
|
+
var middlewareAPI = {
|
699
|
+
getState: store.getState,
|
700
|
+
dispatch: function dispatch() {
|
701
|
+
return _dispatch.apply(void 0, arguments);
|
702
|
+
}
|
703
|
+
};
|
704
|
+
var chain = middlewares.map(function (middleware) {
|
705
|
+
return middleware(middlewareAPI);
|
706
|
+
});
|
707
|
+
_dispatch = compose.apply(void 0, chain)(store.dispatch);
|
708
|
+
return _objectSpread2(_objectSpread2({}, store), {}, {
|
709
|
+
dispatch: _dispatch
|
710
|
+
});
|
711
|
+
};
|
712
|
+
};
|
713
|
+
}
|
714
|
+
|
715
|
+
/*
|
716
|
+
* This is a dummy function to check if the function name has been altered by minification.
|
717
|
+
* If the function has been minified and NODE_ENV !== 'production', warn the user.
|
718
|
+
*/
|
719
|
+
|
720
|
+
function isCrushed() {}
|
721
|
+
|
722
|
+
if (typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
|
723
|
+
warning('You are currently using minified code outside of NODE_ENV === "production". ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or setting mode to production in webpack (https://webpack.js.org/concepts/mode/) ' + 'to ensure you have the correct code for your production build.');
|
724
|
+
}
|
725
|
+
|
726
|
+
exports.__DO_NOT_USE__ActionTypes = ActionTypes;
|
727
|
+
exports.applyMiddleware = applyMiddleware;
|
728
|
+
exports.bindActionCreators = bindActionCreators;
|
729
|
+
exports.combineReducers = combineReducers;
|
730
|
+
exports.compose = compose;
|
731
|
+
exports.createStore = createStore;
|
732
|
+
|
733
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
734
|
+
|
735
|
+
})));
|