Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore) Add support for preact x #48

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
[![NPM](http://img.shields.io/npm/v/preact-redux.svg)](https://www.npmjs.com/package/preact-redux)
[![travis-ci](https://travis-ci.org/developit/preact-redux.svg)](https://travis-ci.org/developit/preact-redux)

Wraps [react-redux] up for [Preact] (8.x and prior), without using [preact-compat](https://github.com/developit/preact-compat). Think of this as a version of `react-redux` that is pre-aliased to use preact in place of React.
Wraps [`react-redux`](https://react-redux.js.org/) up for `preact@^10.0.0`, without using [preact/compat](https://github.com/preactjs/preact). Think of this as a version of `react-redux` that is pre-aliased to use `preact` in place of `react`.

**See [preact-redux-example](https://github.com/developit/preact-redux-example):** _a full working example of `redux` + `preact` using `preact-redux`!_

> 💁‍ **Compatibility Note:**
>
> If you're using Preact X (preact@10+), please use the official [react-redux] library.

---


### Usage Example

> This is a contrived example. Please refer to Redux's [Usage with React](http://redux.js.org/docs/basics/UsageWithReact.html) documentation for details on how to work with Redux from Preact.
> This is a contrived example. Please refer to Redux's [Usage with React](https://react-redux.js.org/introduction/quick-start) documentation for details on how to work with Redux from Preact.

```js
import { Provider, connect } from 'preact-redux';
Expand Down Expand Up @@ -47,5 +43,5 @@ render(<Main />, document.body);


[react-redux]: https://github.com/reactjs/react-redux
[Preact]: https://github.com/developit/preact
[Preact]: https://github.com/preactjs/preact
[MIT]: http://choosealicense.com/licenses/mit/
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function(config) {
},

webpack: {
mode: "production",
mode: "development",
module: {
rules: [{
test: /\.jsx?$/,
Expand Down
6,071 changes: 2,291 additions & 3,780 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "preact-redux",
"amdName": "preactRedux",
"version": "2.1.0",
"description": "Wraps react-redux up for Preact, without preact-compat",
"description": "Wraps react-redux up for Preact, without preact/compat",
"main": "dist/preact-redux.js",
"module": "dist/preact-redux.esm.js",
"types": "src/preact-redux.d.ts",
Expand Down Expand Up @@ -41,9 +41,8 @@
},
"homepage": "https://github.com/developit/preact-redux",
"peerDependencies": {
"preact": "<10",
"redux": ">=2",
"preact-context": ">=1.1.0"
"preact": ">=10",
"redux": ">=2"
},
"devDependencies": {
"@babel/cli": "^7.4.3",
Expand Down Expand Up @@ -72,12 +71,10 @@
"mkdirp": "^0.5.1",
"mocha": "^6.1.2",
"npm-run-all": "^4.0.2",
"phantomjs-prebuilt": "^2.1.14",
"preact": "^8.1.0",
"preact-context": "^1.1.3",
"preact": "^10.0.0",
"pretty-bytes-cli": "^2.0.0",
"react-redux": "^6.0.1",
"redux": "^4.0.0",
"react-redux": "^7.1.1",
"redux": "^4.0.4",
"rimraf": "^2.6.1",
"rollup": "^1.9.2",
"rollup-plugin-alias": "^1.2.1",
Expand Down
4 changes: 3 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const babelRc = JSON.parse(fs.readFileSync(".babelrc"));
let pkg = JSON.parse(fs.readFileSync("./package.json"));

let external = Object.keys(pkg.peerDependencies || {}).concat(
Object.keys(pkg.dependencies || {})
Object.keys(pkg.dependencies || {}), 'preact/compat'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including preact/compat completely defeats the purpose of this project, doesn't it? 😿

);

let format = process.env.FORMAT === "es" ? "es" : "umd";
Expand All @@ -35,12 +35,14 @@ export default {
alias({
"react-redux": "node_modules/react-redux/src/index.js",
react: __dirname + "/src/compat.js",
"react-dom": __dirname + "/src/compat.js",
invariant: __dirname + "/src/empty.js",
"prop-types": __dirname + "/src/prop-types.js"
}),
replace({
"process.env.NODE_ENV": JSON.stringify("production"),
"typeof Symbol": JSON.stringify("string"),
"Symbol.for": "undefined",
"(forwardRef)": "(false)"
}),
babel({
Expand Down
53 changes: 46 additions & 7 deletions src/compat.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
export { Component, Component as PureComponent } from "preact";
import { createContext } from "preact-context";
import { h } from "preact";
import empty from "./empty";
import {
createContext,
createElement,
Component,
useEffect,
useContext,
useMemo,
useLayoutEffect,
useRef,
useReducer,
memo,
forwardRef,
PureComponent,
unstable_batchedUpdates
} from 'preact/compat';

export default {
const React = {
Component,
PureComponent,
createContext,
forwardRef: empty,
createElement: h
createElement,
useEffect,
useContext,
useMemo,
useLayoutEffect,
useRef,
useReducer,
forwardRef,
memo,
unstable_batchedUpdates
};

export {
Component,
PureComponent,
createContext,
createElement,
useEffect,
useContext,
useMemo,
useLayoutEffect,
useRef,
useReducer,
forwardRef,
memo,
unstable_batchedUpdates
};

export default React;
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Provider, connect, connectAdvanced, ReactReduxContext } from 'react-redux';
export { Provider, connect, connectAdvanced, ReactReduxContext };
export default { Provider, connect, connectAdvanced, ReactReduxContext };
import * as ReactRedux from 'react-redux';
export * from 'react-redux';

export default ReactRedux;
5 changes: 2 additions & 3 deletions test/provider.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createStore } from 'redux';
import { Provider, connect, connectAdvanced } from '../';
import { Provider, connect, connectAdvanced } from '../dist/preact-redux.esm';
import { render, options } from 'preact';
import React from 'preact';

import * as React from 'preact';
import * as Redux from '../dist/preact-redux.esm.js';

// disable async rendering entirely to make tests simpler
Expand Down