Skip to content

Commit 7f77d18

Browse files
feat: optionally allow dispatching the current route by disabling the preventDoubleDispatch middleware
1 parent 51ff994 commit 7f77d18

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

packages/rudy/src/core/createRouter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
pathlessRoute,
2929
anonymousThunk,
3030
transformAction,
31+
preventDoubleDispatch,
3132
call,
3233
enter,
3334
changePageTitle,
@@ -41,6 +42,7 @@ export default (
4142
anonymousThunk,
4243
pathlessRoute('thunk'),
4344
transformAction, // pipeline starts here
45+
preventDoubleDispatch,
4446
// Hydrate: skip callbacks called on server to produce initialState (beforeEnter, thunk, etc)
4547
// Server: don't allow client-centric callbacks (onEnter, onLeave, beforeLeave)
4648
call('beforeLeave', { prev: true }),

packages/rudy/src/middleware/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { default as transformAction } from './transformAction'
2+
export { default as preventDoubleDispatch } from './preventDoubleDispatch'
23
export { default as enter } from './enter'
34
export { default as call } from './call'
45

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
export default () => (req, next) => {
3+
if (!req.route.path) return next()
4+
if (req.isDoubleDispatch()) return req.handleDoubleDispatch() // don't dispatch the same action twice
5+
return next()
6+
}

packages/rudy/src/middleware/transformAction/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ export default () => (req, next) => {
55

66
req.action = formatAction(req)
77

8-
if (req.isDoubleDispatch()) return req.handleDoubleDispatch() // don't dispatch the same action twice
9-
108
const { type, params, query, state, hash, basename, location } = req.action
119
Object.assign(req, { type, params, query, state, hash, basename, location }) // assign to `req` for conevenience (less destructuring in callbacks)
1210

0 commit comments

Comments
 (0)