Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix #3 and prepare for 0.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
cellog committed Jan 23, 2017
1 parent 3ce6b07 commit fbeb0fe
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-saga-router",
"version": "0.3.4",
"version": "0.3.5",
"description": "elegant powerful routing based on the simplicity of storing url as state",
"main": "lib/index.js",
"directories": {
Expand Down
6 changes: 5 additions & 1 deletion src/RouteManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import RouteParser from 'route-parser'
import { createPath } from 'history'
import { put, take, select, call } from 'redux-saga/effects'

import * as types from './types'
import * as actions from './actions'
import * as selectors from './selectors'

Expand Down Expand Up @@ -92,7 +93,10 @@ export default class RouteManager {

*monitorState() {
while (true) { // eslint-disable-line
yield take('*')
const action = yield take('*')
if (action.type === types.PENDING_UPDATES) {
yield take(types.COMMITTED_UPDATES)
}
yield call([this, this.locationFromState])
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,17 @@ export function enterRoutes(routes) {
payload: routes
}
}

export function pending() {
return {
type: types.PENDING_UPDATES,
payload: null
}
}

export function commit() {
return {
type: types.COMMITTED_UPDATES,
payload: null
}
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function *router(connect, routeDefinitions, history, channel) {

location = path
lastMatches = matchedRoutes
yield put(actions.pending())
yield put(actions.route(locationChange.location))
yield put(actions.matchRoutes(matchedRoutes))
if (exiting.length) {
Expand All @@ -98,6 +99,7 @@ export function *router(connect, routeDefinitions, history, channel) {
}
yield keys.map(name => call([routes[name], routes[name].monitorUrl],
locationChange.location))
yield put(actions.commit())
}
}
} finally {
Expand Down
2 changes: 2 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const MATCH_ROUTES = '@@react-redux-saga-router/MATCH_ROUTES'
export const SET_PARAMS = '@@react-redux-saga-router/SET_PARAMS'
export const ENTER_ROUTES = '@@react-redux-saga-router/ENTER_ROUTES'
export const EXIT_ROUTES = '@@react-redux-saga-router/EXIT_ROUTES'
export const PENDING_UPDATES = '@@react-redux-saga-router/PENDING_UPDATES'
export const COMMITTED_UPDATES = '@@react-redux-saga-router/COMMITTED_UPDATES'
16 changes: 16 additions & 0 deletions test/RouteManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { put, take, select, call } from 'redux-saga/effects'

import RouteManager, { fake } from '../src/RouteManager'
import * as actions from '../src/actions'
import * as types from '../src/types'

describe('Route', () => {
describe('basics', () => {
Expand Down Expand Up @@ -311,8 +312,23 @@ describe('Route', () => {
let next = saga.next()

expect(next.value).eqls(take('*'))
next = saga.next({ type: 'foo'})

expect(next.value).eqls(call([route, route.locationFromState]))
next = saga.next()

expect(next.value).eqls(take('*'))
})
it('monitorState during url update', () => {
const saga = route.monitorState()
let next = saga.next()

expect(next.value).eqls(take('*'))
next = saga.next(actions.pending())

expect(next.value).eqls(take(types.COMMITTED_UPDATES))
next = saga.next(actions.commit())

expect(next.value).eqls(call([route, route.locationFromState]))
next = saga.next()

Expand Down
12 changes: 12 additions & 0 deletions test/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,16 @@ describe('react-redux-saga-router actions', () => {
payload: ['hi']
})
})
it('pending', () => {
expect(actions.pending()).eqls({
type: types.PENDING_UPDATES,
payload: null
})
})
it('committed', () => {
expect(actions.commit()).eqls({
type: types.COMMITTED_UPDATES,
payload: null
})
})
})
12 changes: 12 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ describe('react-redux-saga-router', () => {
}
})

expect(next.value).eqls(put(actions.pending()))
next = saga.next()

expect(next.value).eqls(put(actions.route({
pathname: '/campers/2017',
search: '',
Expand Down Expand Up @@ -238,6 +241,9 @@ describe('react-redux-saga-router', () => {
])
next = saga.next()

expect(next.value).eqls(put(actions.commit()))
next = saga.next()

expect(next.value).eqls(take(channel))
next = saga.next({
location: {
Expand All @@ -247,6 +253,9 @@ describe('react-redux-saga-router', () => {
}
})

expect(next.value).eqls(put(actions.pending()))
next = saga.next()

expect(next.value).eqls(put(actions.route({
pathname: '/campers/2016',
search: '',
Expand Down Expand Up @@ -275,6 +284,9 @@ describe('react-redux-saga-router', () => {
])
next = saga.next()

expect(next.value).eqls(put(actions.commit()))
next = saga.next()

expect(next.value).eqls(take(channel))

next = saga.throw(new Error('all done'))
Expand Down

0 comments on commit fbeb0fe

Please sign in to comment.