Skip to content

Commit

Permalink
Merge branch 'v3'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielr18 committed May 24, 2020
2 parents 2974a1f + cffbb7b commit 6445d39
Show file tree
Hide file tree
Showing 75 changed files with 25,284 additions and 10,893 deletions.
14 changes: 0 additions & 14 deletions .babelrc.js

This file was deleted.

4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
lib/*
node_modules
examples
cypress
e2e
test-lib
45 changes: 27 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
module.exports = {
parser: "babel-eslint",
parser: '@typescript-eslint/parser',
env: {
browser: true,
node: true
node: true,
es6: true,
},
plugins: ["import", "react"],
plugins: ['react', 'react-hooks', '@typescript-eslint'],
settings: {
'import/resolver': {
node: {
moduleDirectory: ['node_modules', __dirname],
},
},
react: {
version: '16.6',
version: '16.8',
},
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:react/recommended"
],
extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
"max-len": ["error", { code: 120 }],
quotes: [2, "single", "avoid-escape"],
semi: [2, "never"]
}
'@typescript-eslint/indent': ['error', 2],
'max-len': ['error', { code: 120 }],
quotes: [2, 'single', 'avoid-escape'],
semi: [2, 'never'],
'react/prop-types': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/prefer-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
allowHigherOrderFunctions: true,
allowTypedFunctionExpressions: true,
},
],
},
};
28 changes: 28 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on: ["push"]

name: End To End tests

jobs:
test:
name: Test
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v2

- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: npm install
run: |
npm install
- name: run tests
run: |
npm run e2e
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v1.1.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ node_modules
lib
umd
.next
.nyc_output
.vscode
coverage
cypress/videos
test-lib
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"prettier.eslintIntegration": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "typescript",
"autoFix": true
},
{
"language": "typescriptreact",
"autoFix": true
}
],
}
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
> v1.0.0 requires React v16.4.0 and React Redux v6.0 or later. If you are using React Redux v5, check out [v0 branch](https://github.com/danielr18/connected-next-router/tree/v0).
[![Coverage Status](https://coveralls.io/repos/github/danielr18/connected-next-router/badge.svg?branch=test-github-action)](https://coveralls.io/github/danielr18/connected-next-router?branch=test-github-action)

> v3.0.0 requires Next.js 9 or newer, React Redux 7.1.0 or newer, and React 16.8.0 or newer. If you are using Next.js 7-8, check out [v0 branch](https://github.com/danielr18/connected-next-router/tree/v0).
# Connected Next Router

Expand Down Expand Up @@ -36,10 +38,11 @@ Or [yarn](https://yarnpkg.com/):


```js
...
// store/configure-store.js
import { applyMiddleware, compose, createStore, combineReducers } from 'redux'
import { routerReducer, createRouterMiddleware, initialRouterState } from 'connected-next-router'
...
import { createWrapper } from 'next-redux-wrapper'

const rootReducer = combineReducers({
...reducers,
router: routerReducer
Expand All @@ -61,57 +64,56 @@ const routerMiddleware = createRouterMiddleware({
});
*/

// Using next-redux-wrapper's makeStore
export const makeStore = (initialState = {}, options) => {
if (options.asPath) {
initialState.router = initialRouterState(options.asPath);
// Using next-redux-wrapper's initStore
export const initStore = (context) => {
const routerMiddleware = createRouterMiddleware()
const { asPath, pathname, query } = context.ctx || Router.router || {};
let initialState
if (asPath) {
const url = format({ pathname, query })
initialState = {
router: initialRouterState(url, asPath)
}
}

return createStore(
rootReducer,
initialState,
applyMiddleware(
routerMiddleware,
// ... other middlewares ...
)
);
return createStore(rootReducer, initialState, applyMiddleware(routerMiddleware))
}

export const wrapper = createWrapper(initStore)
```

### Step 2

- Place `ConnectedRouter` as children of `react-redux`'s `Provider`.

```js
...
// pages/_app.js
import App, { Container } from 'next/app';
import { Provider } from 'react-redux'
import { ConnectedRouter } from 'connected-next-router'
...
import { wrapper } from '../store/configure-store'

class MyApp extends App {
render() {
const { Component, pageProps, store } = this.props;
const { Component, pageProps } = this.props;
return (
<Container>
<Provider store={store}>
<ConnectedRouter>
<Component { ...pageProps } />
</ConnectedRouter>
</Provider>
</Container>
<ConnectedRouter>
<Component { ...pageProps } />
</ConnectedRouter>
);
}
}

// wrapper.withRedux wraps the App with react-redux's Provider
export default wrapper.withRedux(MyApp);
```

## Examples

- [examples/basic](/examples/basic) - basic reference implementation
- [examples/typescript](/examples/typescript) - typescript reference implementation

## TODO

- Add unit tests
- Support [Immutable.js](https://facebook.github.io/immutable-js/)

## Acknowledgements
Expand Down
8 changes: 8 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"baseUrl": "http://localhost:3000",
"env": {
"codeCoverage": {
"url": "/api/__coverage__"
}
}
}
Loading

0 comments on commit 6445d39

Please sign in to comment.