Skip to content

Commit 56a04ae

Browse files
committedApr 15, 2019
Updates related to new framework
1 parent 2e149db commit 56a04ae

14 files changed

+11443
-9661
lines changed
 

‎.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Autodetect text files
22
* text=auto
33

4+
core.eol = lf
5+
46
# Ensure those won't be messed up with
57
*.jpg binary
68
*.data binary

‎.size-snapshot.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"cjs/react-router-pause.js": {
3+
"bundled": 114119,
4+
"minified": 36218,
5+
"gzipped": 11236
6+
},
7+
"cjs/react-router-pause.min.js": {
8+
"bundled": 114119,
9+
"minified": 36218,
10+
"gzipped": 11236
11+
},
12+
"umd/react-router-pause.js": {
13+
"bundled": 121897,
14+
"minified": 20779,
15+
"gzipped": 7866
16+
},
17+
"umd/react-router-pause.min.js": {
18+
"bundled": 20779,
19+
"minified": 19768,
20+
"gzipped": 7391
21+
},
22+
"esm/react-router-pause.js": {
23+
"bundled": 113928,
24+
"minified": 36070,
25+
"gzipped": 11191,
26+
"treeshaked": {
27+
"rollup": {
28+
"code": 19289,
29+
"import_statements": 93
30+
},
31+
"webpack": {
32+
"code": 21498
33+
}
34+
}
35+
},
36+
"esm/index.js": {
37+
"bundled": 113928,
38+
"minified": 36070,
39+
"gzipped": 11191,
40+
"treeshaked": {
41+
"rollup": {
42+
"code": 19289,
43+
"import_statements": 93
44+
},
45+
"webpack": {
46+
"code": 21498
47+
}
48+
}
49+
}
50+
}

‎README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ However this is clumsy and allows only a single, global configuration.
5656
- NPM: `npm install @allpro/react-router-pause`
5757
- Yarn: `yarn add @allpro/react-router-pause`
5858
- CDN: Exposed global is `ReactRouterPause`
59-
- Unpkg: `<script src="https://unpkg.com/@allpro/react-router-pause/dist/umd/@allpro/react-router-pause.min.js"></script>`
60-
- JSDelivr: `<script src="https://cdn.jsdelivr.net/npm/@allpro/react-router-pause/dist/umd/@allpro/react-router-pause.min.js"></script>`
59+
- Unpkg: `<script src="https://unpkg.com/@allpro/react-router-pause/umd/react-router-pause.min.js"></script>`
60+
- JSDelivr: `<script src="https://cdn.jsdelivr.net/npm/@allpro/react-router-pause/umd/react-router-pause.min.js"></script>`
6161

6262

6363
## Usage
@@ -364,9 +364,10 @@ see the tags on this repository.
364364
365365
## License
366366
367-
This project is licensed under the MIT License - see the
368-
[LICENSE.md](https://github.com/allpro/react-router-pause/blob/master/LICENSE)
369-
file for details
367+
MIT © [allpro](https://github.com/allpro)
368+
<br>See
369+
[LICENSE](https://github.com/allpro/react-router-pause/blob/master/LICENSE)
370+
file for details
370371
371372
372373
[gzip-size-badge]: http://img.badgesize.io/https://cdn.jsdelivr.net/npm/@allpro/react-router-pause/umd/@allpro/react-router-pause.min.js?compression=gzip

‎_config.yml

-1
This file was deleted.

‎example/src/README.md ‎example/README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ However this is clumsy and allows only a single, global configuration.
5656
- NPM: `npm install @allpro/react-router-pause`
5757
- Yarn: `yarn add @allpro/react-router-pause`
5858
- CDN: Exposed global is `ReactRouterPause`
59-
- Unpkg: `<script src="https://unpkg.com/@allpro/react-router-pause/dist/umd/@allpro/react-router-pause.min.js"></script>`
60-
- JSDelivr: `<script src="https://cdn.jsdelivr.net/npm/@allpro/react-router-pause/dist/umd/@allpro/react-router-pause.min.js"></script>`
59+
- Unpkg: `<script src="https://unpkg.com/@allpro/react-router-pause/umd/react-router-pause.min.js"></script>`
60+
- JSDelivr: `<script src="https://cdn.jsdelivr.net/npm/@allpro/react-router-pause/umd/react-router-pause.min.js"></script>`
6161

6262

6363
## Usage
@@ -364,9 +364,10 @@ see the tags on this repository.
364364
365365
## License
366366
367-
This project is licensed under the MIT License - see the
368-
[LICENSE.md](https://github.com/allpro/react-router-pause/blob/master/LICENSE)
369-
file for details
367+
MIT © [allpro](https://github.com/allpro)
368+
<br>See
369+
[LICENSE](https://github.com/allpro/react-router-pause/blob/master/LICENSE)
370+
file for details
370371
371372
372373
[gzip-size-badge]: http://img.badgesize.io/https://cdn.jsdelivr.net/npm/@allpro/react-router-pause/umd/@allpro/react-router-pause.min.js?compression=gzip

‎example/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"name": "react-router-pause-example",
33
"homepage": "https://allpro.github.io/react-router-pause",
4-
"version": "0.7.0",
4+
"version": "0.7.1",
55
"license": "MIT",
66
"private": true,
77
"dependencies": {
88
"@allpro/form-manager": "^0.4.2",
99
"@material-ui/core": "^3.9.0",
1010
"@material-ui/icons": "^3.0.0",
1111
"classnames": "^2.2.6",
12-
"lodash": "^4.0.0",
1312
"prop-types": "^15.6.2",
1413
"react": "^16.8.6",
1514
"react-dom": "^16.8.5",
1615
"react-router-dom": "^5.0.0",
17-
"react-scripts": "^2.0.0"
16+
"react-scripts": "^1.1.4",
17+
"react-router-pause": "file:.."
1818
},
1919
"scripts": {
2020
"start": "react-scripts start",

‎example/src/FormPage.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import TextField from '@material-ui/core/TextField'
99

1010
import { useFormManager } from '@allpro/form-manager'
1111

12-
import Pause from './react-router-pause'
12+
import Pause from 'react-router-pause'
13+
1314
import PromptDialog from './PromptDialog'
1415
import Notification from './Notification'
1516

‎example/src/react-router-pause.js

-270
This file was deleted.

‎example/package-lock.json ‎package-lock.json

+11,261-9,268
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
{
22
"name": "react-router-pause",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "Helper for React Router to provide customizable asynchronous navigation blocking",
55
"author": "allpro",
66
"repository": "allpro/react-router-pause",
77
"license": "MIT",
8-
"main": "dist/cjs/react-router-pause.js",
9-
"module": "dist/esm/react-router-pause.js",
10-
"jsnext:main": "dist/esm/react-router-pause.js",
11-
"react-native": "dist/umd/react-router-pause.js",
12-
"umd:main": "dist/umd/react-router-pause.js",
8+
"main": "cjs/index.js",
9+
"module": "esm/index.js",
10+
"jsnext:main": "esm/index.js",
11+
"react-native": "umd/react-router-pause.js",
12+
"umd:main": "umd/react-router-pause.js",
1313
"files": [
14-
"src",
15-
"dist"
14+
"cjs",
15+
"esm",
16+
"umd"
1617
],
1718
"engines": {
1819
"node": ">=8",
1920
"npm": ">=5"
2021
},
22+
"browserslist": [
23+
">0.2%",
24+
"not dead",
25+
"not ie <= 11",
26+
"not op_mini all"
27+
],
2128
"scripts": {
22-
"test": "cross-env CI=1 react-scripts test",
29+
"test": "cross-env CI=1 react-scripts test --env=jsdom",
2330
"test:watch": "react-scripts test --env=jsdom",
2431
"build": "rollup -c",
2532
"start": "rollup -c -w",
@@ -28,25 +35,22 @@
2835
"deploy": "gh-pages -d example/build"
2936
},
3037
"peerDependencies": {
31-
"prop-types": "^15.5.4",
38+
"prop-types": ">=15.0.0",
3239
"react": "^15.0.0 || ^16.0.0",
3340
"react-dom": "^15.0.0 || ^16.0.0",
3441
"react-router": "^4.0.0 || ^5.0.0",
3542
"react-router-dom": "^4.0.0 || ^5.0.0"
3643
},
3744
"devDependencies": {
38-
"@allpro/form-manager": "^0.4.2",
39-
"@material-ui/core": "^3.9.0",
40-
"@material-ui/icons": "^3.0.0",
41-
"@svgr/rollup": "^4.2.0",
45+
"@svgr/rollup": "^2.4.1",
4246
"babel-core": "^6.26.3",
43-
"babel-eslint": "^9.0.0",
47+
"babel-eslint": "^8.2.5",
4448
"babel-plugin-external-helpers": "^6.22.0",
4549
"babel-preset-env": "^1.7.0",
4650
"babel-preset-react": "^6.24.1",
4751
"babel-preset-stage-0": "^6.24.1",
48-
"classnames": "^2.2.6",
4952
"cross-env": "^5.1.4",
53+
"eslint": "^5.0.1",
5054
"eslint-plugin-import": "^2.13.0",
5155
"eslint-plugin-node": "^7.0.1",
5256
"eslint-plugin-promise": "^4.0.0",
@@ -57,18 +61,19 @@
5761
"lodash": "^4.0.0",
5862
"react": "^16.4.1",
5963
"react-dom": "^16.4.1",
60-
"react-router-dom": "^5.0.0",
61-
"react-scripts": "^2.1.8",
64+
"react-scripts": "^1.1.4",
6265
"react-testing-library": "^6.1.2",
6366
"rollup": "^1.10.0",
6467
"rollup-plugin-babel": "^3.0.7",
6568
"rollup-plugin-commonjs": "^9.3.4",
6669
"rollup-plugin-node-resolve": "^4.2.3",
6770
"rollup-plugin-peer-deps-external": "^2.2.0",
6871
"rollup-plugin-postcss": "^2.0.3",
69-
"rollup-plugin-replace": "^2.2.0",
7072
"rollup-plugin-size-snapshot": "^0.8.0",
7173
"rollup-plugin-terser": "^4.0.4",
7274
"rollup-plugin-url": "^2.2.1"
75+
},
76+
"dependencies": {
77+
"react-router-dom": "^5.0.0"
7378
}
7479
}

‎rollup.config.js

+59-55
Original file line numberDiff line numberDiff line change
@@ -7,85 +7,89 @@ import url from 'rollup-plugin-url'
77
import svgr from '@svgr/rollup'
88
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
99
import { terser } from 'rollup-plugin-terser'
10-
// import replace from 'rollup-plugin-replace'
1110

1211
import pkg from './package.json'
1312

14-
1513
const globals = {
1614
react: 'React',
1715
'react-router-dom': 'ReactRouterDOM',
1816
'prop-types': 'PropTypes'
1917
}
2018

19+
const basePlugins = [
20+
// List external libraries that should not be bundled
21+
external(),
22+
postcss({
23+
modules: true
24+
}),
25+
url(),
26+
svgr(),
27+
babel({
28+
exclude: 'node_modules/**',
29+
plugins: ['external-helpers']
30+
}),
2131

22-
export default {
23-
input: 'src/index.js',
24-
output: [
25-
{
26-
file: `dist/cjs/${pkg.name}.js`,
27-
format: 'cjs',
28-
plugins: [
29-
sizeSnapshot()
30-
]
31-
},
32-
{
33-
file: `dist/cjs/${pkg.name}.min.js`,
34-
format: 'cjs',
35-
sourcemap: true,
36-
plugins: [
37-
terser(),
38-
sizeSnapshot()
39-
]
32+
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
33+
commonjs(),
34+
35+
// Allow node_modules resolution, so you can use 'external' to control
36+
// which external modules to include in the bundle
37+
// https://github.com/rollup/rollup-plugin-node-resolve#usage
38+
resolve()
39+
40+
// Output a file listing bundle sizes for easy review
41+
// sizeSnapshot(),
4042

43+
// Enable minification
44+
// terser()
45+
]
46+
47+
48+
export default [
49+
{
50+
input: 'src/index.js',
51+
output: {
52+
file: `cjs/index.js`,
53+
format: 'cjs',
4154
},
55+
plugins: basePlugins
56+
},
4257

43-
{
44-
file: `dist/esm/${pkg.name}.js`,
58+
{
59+
input: 'src/index.js',
60+
output: {
61+
file: `esm/index.js`,
4562
format: 'esm',
46-
plugins: [
47-
sizeSnapshot()
48-
]
63+
esModule: true,
4964
},
65+
plugins: [ sizeSnapshot() ].concat(basePlugins)
66+
},
5067

51-
{
52-
file: `dist/umd/${pkg.name}.js`,
68+
{
69+
input: 'src/index.js',
70+
output: {
71+
file: `umd/${pkg.name}.js`,
5372
format: 'umd',
5473
name: 'ReactRouterPause',
5574
globals,
5675
external: Object.keys(globals),
76+
esModule: false,
5777
sourcemap: true,
58-
plugins: [
59-
sizeSnapshot()
60-
]
61-
6278
},
63-
{
64-
file: `dist/umd/${pkg.name}.min.js`,
79+
plugins: basePlugins
80+
},
81+
82+
{
83+
input: 'src/index.js',
84+
output: {
85+
file: `umd/${pkg.name}.min.js`,
6586
format: 'umd',
6687
name: 'ReactRouterPause',
6788
globals,
6889
external: Object.keys(globals),
90+
esModule: false,
6991
sourcemap: true,
70-
plugins: [
71-
terser(),
72-
sizeSnapshot()
73-
]
74-
}
75-
],
76-
plugins: [
77-
external(),
78-
postcss({
79-
modules: true,
80-
minimize: true
81-
}),
82-
url(),
83-
svgr(),
84-
babel({
85-
exclude: 'node_modules/**',
86-
plugins: [ 'external-helpers' ]
87-
}),
88-
resolve(),
89-
commonjs()
90-
]
91-
}
92+
},
93+
plugins: [ terser(), sizeSnapshot() ].concat(basePlugins)
94+
}
95+
]

‎src/__tests__/index.test.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import React from 'react'
22
import { MemoryRouter } from 'react-router-dom'
3-
import { render } from 'react-testing-library'
4-
/* Methods
3+
import assign from 'lodash/assign'
4+
5+
import 'jest-dom/extend-expect'
6+
import 'react-testing-library/cleanup-after-each'
57
import {
6-
render,
7-
fireEvent,
8-
cleanup,
9-
wait,
10-
waitForElement,
8+
render
9+
// fireEvent,
10+
// cleanup,
11+
// wait,
12+
// waitForElement,
1113
} from 'react-testing-library'
12-
*/
13-
import assign from 'lodash/assign'
14-
// import clone from 'lodash/clone'
1514

1615
import ReactRouterPause from '../'
1716

@@ -35,10 +34,10 @@ const location = {
3534
}
3635

3736
const Component = props => (
38-
<MemoryRouter initialEntries={[ '/' ]}>
37+
<MemoryRouter initialEntries={[ location.pathname ]}>
3938
<ReactRouterPause
4039
history={history}
41-
location={assign({}, location, propt.pathname)}
40+
location={assign({}, location)}
4241
{...props}
4342
/>
4443
</MemoryRouter>
@@ -65,20 +64,21 @@ test('renders without crashing', () => {
6564

6665
test('binds history.block handler onMount', () => {
6766
render(<Component use={handler} />)
67+
expect(history.block).toHaveBeenCalledTimes(1)
6868
})
6969

7070
test('unbinds history.block handler onUnmount', () => {
7171
const { unmount } = render(<Component use={handler} />)
7272
unmount()
73-
console.log({ history })
74-
expect(unblockMock.toHaveBeenCalledTimes(1))
73+
expect(unblockMock).toHaveBeenCalledTimes(1)
74+
// console.warn({ history })
7575
})
7676

7777
test('calls the navigation handler onRouteChange', () => {
7878
const { debug, rerender } = render(<Component use={handler} />)
79-
debug()
80-
expect(handler.toBeCalledTimes(1))
81-
// expect(handler.toBeCalledWith([]))
82-
rerender(<Component use={handler} pathname={'/next'} />)
83-
expect(handler.toHaveBeenCalledTimes(1))
79+
debug() // Output DOM markup at END of test output
80+
expect(handler).toBeCalledTimes(1)
81+
// expect(handler).toBeCalledWith([])
82+
// rerender(<Component use={handler} pathname={'/next'} />)
83+
// expect(handler).toHaveBeenCalledTimes(1)
8484
})

‎src/index.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { withRouter } from 'react-router-dom'
2+
import { withRouter } from 'react-router-dom' // eslint-disable-line
33
import PropTypes from 'prop-types'
44

55
import bindAll from 'lodash/bindAll'
@@ -141,7 +141,7 @@ class ReactRouterPause extends React.Component {
141141
history.goBack()
142142
}
143143
else { // (push|replace)
144-
history[action](location)
144+
history[action](location.pathname, location.state)
145145
}
146146
}
147147

@@ -222,33 +222,31 @@ class ReactRouterPause extends React.Component {
222222
* @param {string} action One of [PUSH|REPLACE|POP]
223223
*/
224224
beforeRouteChange(location, action) {
225-
console.log({ location, action })
226-
227-
// Cache the new location data for comparison
228-
const prevFingerprint = this.locationFingerprint
229-
this.locationFingerprint = createFingerprint(location)
225+
// Create new location fingerprint for comparison
226+
const newFingerprint = createFingerprint(location)
230227

231228
if (this.props.when === false) {
232-
return true // Allow - RRP is disabled!
229+
// Allow this event - RRP is disabled!
233230
}
234-
else if (this.locationFingerprint === prevFingerprint) {
231+
else if (newFingerprint === this.locationFingerprint) {
235232
// Block navigation if this is SAME LOCATION we are already at!
236233
// This prevents reloading a form component and losing its contents.
237234
return false
238235
}
239236
else if (this.skipNext) {
240237
this.setSkipNext(false) // Reset flag - only used ONCE
241-
return true // Allow this event
238+
// Allow this event - blocking was skipped!
242239
}
243240
else if (this.isBlocking()) {
244241
// The askHandler method handles the pause/resume functionality.
245242
// Call the handler to see if we should allow route change (true).
246243
// Coerce response to a boolean because that's what RR expects.
247244
return !!this.askHandler({ location, action })
248245
}
249-
else {
250-
return true
251-
}
246+
247+
// Cache the new location data for comparison
248+
this.locationFingerprint = newFingerprint
249+
return true
252250
}
253251

254252

‎src/setupTests.js

-2
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.