Skip to content

Commit b88a503

Browse files
authored
Add React-Redux v8 experimental build and initial hooks scenario (#30)
1 parent 1d251f3 commit b88a503

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2912
-33
lines changed

.yalc/react-redux/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

.yalc/react-redux/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# React Redux
2+
3+
Official React bindings for [Redux](https://github.com/reduxjs/redux).
4+
Performant and flexible.
5+
6+
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/reduxjs/react-redux/CI?style=flat-square) [![npm version](https://img.shields.io/npm/v/react-redux.svg?style=flat-square)](https://www.npmjs.com/package/react-redux)
7+
[![npm downloads](https://img.shields.io/npm/dm/react-redux.svg?style=flat-square)](https://www.npmjs.com/package/react-redux)
8+
[![redux channel on discord](https://img.shields.io/badge/[email protected]?style=flat-square)](http://www.reactiflux.com)
9+
10+
## Installation
11+
12+
### Using Create React App
13+
14+
The recommended way to start new apps with React Redux is by using the [official Redux+JS template](https://github.com/reduxjs/cra-template-redux) for [Create React App](https://github.com/facebook/create-react-app), which takes advantage of [Redux Toolkit](https://redux-toolkit.js.org/).
15+
16+
```sh
17+
npx create-react-app my-app --template redux
18+
```
19+
20+
### An Existing React App
21+
22+
React Redux 7.1 requires **React 16.8.3 or later.**
23+
24+
To use React Redux with your React app, install it as a dependency:
25+
26+
```bash
27+
# If you use npm:
28+
npm install react-redux
29+
30+
# Or if you use Yarn:
31+
yarn add react-redux
32+
```
33+
34+
You'll also need to [install Redux](https://redux.js.org/introduction/installation) and [set up a Redux store](https://redux.js.org/recipes/configuring-your-store/) in your app.
35+
36+
This assumes that you’re using [npm](http://npmjs.com/) package manager
37+
with a module bundler like [Webpack](https://webpack.js.org/) or
38+
[Browserify](http://browserify.org/) to consume [CommonJS
39+
modules](https://webpack.js.org/api/module-methods/#commonjs).
40+
41+
If you don’t yet use [npm](http://npmjs.com/) or a modern module bundler, and would rather prefer a single-file [UMD](https://github.com/umdjs/umd) build that makes `ReactRedux` available as a global object, you can grab a pre-built version from [cdnjs](https://cdnjs.com/libraries/react-redux). We _don’t_ recommend this approach for any serious application, as most of the libraries complementary to Redux are only available on [npm](http://npmjs.com/).
42+
43+
## React Native
44+
45+
As of React Native 0.18, React Redux 5.x should work with React Native. If you have any issues with React Redux 5.x on React Native, run `npm ls react` and make sure you don’t have a duplicate React installation in your `node_modules`. We recommend that you use `[email protected]` which is better at avoiding these kinds of issues.
46+
47+
## Documentation
48+
49+
The React Redux docs are now published at **https://react-redux.js.org** .
50+
51+
We're currently expanding and rewriting our docs content - check back soon for more updates!
52+
53+
## How Does It Work?
54+
55+
We do a deep dive on how React Redux works in [this readthesource episode](https://www.youtube.com/watch?v=VJ38wSFbM3A).
56+
57+
Also, the post [The History and Implementation of React-Redux](https://blog.isquaredsoftware.com/2018/11/react-redux-history-implementation/)
58+
explains what it does, how it works, and how the API and implementation have evolved over time.
59+
60+
Enjoy!
61+
62+
## License
63+
64+
[MIT](LICENSE.md)

.yalc/react-redux/package.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "react-redux",
3+
"version": "8.0.0-alpha.0",
4+
"description": "Official React bindings for Redux",
5+
"keywords": [
6+
"react",
7+
"reactjs",
8+
"redux"
9+
],
10+
"license": "MIT",
11+
"author": "Dan Abramov <[email protected]> (https://github.com/gaearon)",
12+
"homepage": "https://github.com/reduxjs/react-redux",
13+
"repository": "github:reduxjs/react-redux",
14+
"bugs": "https://github.com/reduxjs/react-redux/issues",
15+
"main": "./lib/index.js",
16+
"types": "./es/index.d.ts",
17+
"unpkg": "dist/react-redux.js",
18+
"module": "es/index.js",
19+
"files": [
20+
"dist",
21+
"lib",
22+
"src",
23+
"es"
24+
],
25+
"scripts": {
26+
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --extensions \".js,.ts,.tsx\" --out-dir lib",
27+
"build:es": "babel src --extensions \".js,.ts,.tsx\" --out-dir es",
28+
"build:umd": "cross-env NODE_ENV=development rollup -c -o dist/react-redux.js",
29+
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/react-redux.min.js",
30+
"build:types": "tsc",
31+
"build": "yarn build:types && yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:umd:min",
32+
"clean": "rimraf lib dist es coverage",
33+
"api-types": "api-extractor run --local",
34+
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"",
35+
"lint": "eslint src --ext ts,js test/utils test/components test/hooks",
36+
"pretest": "yarn lint",
37+
"test": "jest",
38+
"type-tests": "yarn tsc -p test/typetests",
39+
"coverage": "codecov"
40+
},
41+
"workspaces": [
42+
"website"
43+
],
44+
"peerDependencies": {
45+
"react": "^16.8.3 || ^17"
46+
},
47+
"peerDependenciesMeta": {
48+
"react-dom": {
49+
"optional": true
50+
},
51+
"react-native": {
52+
"optional": true
53+
}
54+
},
55+
"dependencies": {
56+
"@babel/runtime": "^7.12.1",
57+
"hoist-non-react-statics": "^3.3.2",
58+
"loose-envify": "^1.4.0",
59+
"prop-types": "^15.7.2",
60+
"react-is": "^16.13.1",
61+
"use-sync-external-store": "0.0.0-experimental-5b57bc6e3-20210921"
62+
},
63+
"browserify": {
64+
"transform": [
65+
"loose-envify"
66+
]
67+
},
68+
"yalcSig": "ff0db988ba4013dfd771fdeeafc7f593"
69+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export * from './exports'
2+
3+
import { getBatch } from './utils/batch'
4+
5+
// For other renderers besides ReactDOM and React Native,
6+
// use the default noop batch function
7+
const batch = getBatch()
8+
9+
export { batch }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import { Action, AnyAction, Store } from 'redux'
3+
import type { FixTypeLater } from '../types'
4+
import type { Subscription } from '../utils/Subscription'
5+
6+
export interface ReactReduxContextValue<
7+
SS = FixTypeLater,
8+
A extends Action = AnyAction
9+
> {
10+
store: Store<SS, A>
11+
subscription: Subscription
12+
}
13+
14+
export const ReactReduxContext =
15+
/*#__PURE__*/ React.createContext<ReactReduxContextValue | null>(null)
16+
17+
export type ReactReduxContextInstance = typeof ReactReduxContext
18+
19+
if (process.env.NODE_ENV !== 'production') {
20+
ReactReduxContext.displayName = 'ReactRedux'
21+
}
22+
23+
export default ReactReduxContext
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { Context, ReactNode, useMemo } from 'react'
2+
import { ReactReduxContext, ReactReduxContextValue } from './Context'
3+
import { createSubscription } from '../utils/Subscription'
4+
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
5+
import type { FixTypeLater } from '../types'
6+
import { Action, AnyAction, Store } from 'redux'
7+
8+
export interface ProviderProps<A extends Action = AnyAction> {
9+
/**
10+
* The single Redux store in your application.
11+
*/
12+
store: Store<FixTypeLater, A>
13+
/**
14+
* Optional context to be used internally in react-redux. Use React.createContext() to create a context to be used.
15+
* If this is used, you'll need to customize `connect` by supplying the same context provided to the Provider.
16+
* Initial value doesn't matter, as it is overwritten with the internal state of Provider.
17+
*/
18+
context?: Context<ReactReduxContextValue | null>
19+
children: ReactNode
20+
}
21+
22+
function Provider({ store, context, children }: ProviderProps) {
23+
const contextValue = useMemo(() => {
24+
const subscription = createSubscription(store)
25+
return {
26+
store,
27+
subscription,
28+
}
29+
}, [store])
30+
31+
const previousState = useMemo(() => store.getState(), [store])
32+
33+
useIsomorphicLayoutEffect(() => {
34+
const { subscription } = contextValue
35+
36+
subscription.onStateChange = subscription.notifyNestedSubs
37+
subscription.trySubscribe()
38+
39+
if (previousState !== store.getState()) {
40+
subscription.notifyNestedSubs()
41+
}
42+
return () => {
43+
subscription.tryUnsubscribe()
44+
subscription.onStateChange = undefined
45+
}
46+
}, [contextValue, previousState])
47+
48+
const Context = context || ReactReduxContext
49+
50+
return <Context.Provider value={contextValue}>{children}</Context.Provider>
51+
}
52+
53+
export default Provider

0 commit comments

Comments
 (0)