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

feat: optionally allow dispatching the current route #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rudy/src/core/createReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default (initialState: Object, routes: Routes) => (
return { ...st, ...act, ...location }
}

if (r && r.path && (l.url !== st.url || /load|reset/.test(l.kind))) {
if (r && r.path) {
const { type, params, query, state, hash, basename } = action
const { universal } = st
const s = { type, params, query, state, hash, basename, universal, ...l }
Expand Down
2 changes: 2 additions & 0 deletions packages/rudy/src/core/createRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
pathlessRoute,
anonymousThunk,
transformAction,
preventDoubleDispatch,
call,
enter,
changePageTitle,
Expand All @@ -41,6 +42,7 @@ export default (
anonymousThunk,
pathlessRoute('thunk'),
transformAction, // pipeline starts here
preventDoubleDispatch,
// Hydrate: skip callbacks called on server to produce initialState (beforeEnter, thunk, etc)
// Server: don't allow client-centric callbacks (onEnter, onLeave, beforeLeave)
call('beforeLeave', { prev: true }),
Expand Down
1 change: 1 addition & 0 deletions packages/rudy/src/middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as transformAction } from './transformAction'
export { default as preventDoubleDispatch } from './preventDoubleDispatch'
export { default as enter } from './enter'
export { default as call, shouldCall } from './call'

Expand Down
5 changes: 5 additions & 0 deletions packages/rudy/src/middleware/preventDoubleDispatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default () => (req, next) => {
if (!req.route.path) return next()
if (req.isDoubleDispatch()) return req.handleDoubleDispatch() // don't dispatch the same action twice
return next()
}
2 changes: 0 additions & 2 deletions packages/rudy/src/middleware/transformAction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export default () => (req, next) => {

req.action = formatAction(req)

if (req.isDoubleDispatch()) return req.handleDoubleDispatch() // don't dispatch the same action twice

const { type, params, query, state, hash, basename, location } = req.action
Object.assign(req, { type, params, query, state, hash, basename, location }) // assign to `req` for conevenience (less destructuring in callbacks)

Expand Down