Skip to content
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
19 changes: 15 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var _pathToRegexp = require('path-to-regexp');

var _pathToRegexp2 = _interopRequireDefault(_pathToRegexp);

var _queryString = require('query-string');

var _queryString2 = _interopRequireDefault(_queryString);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function subscribe(history, dispatch) {
Expand Down Expand Up @@ -55,11 +59,14 @@ function subscribe(history, dispatch) {
if (!lastMatch) {
shouldExec = true;
} else {
shouldExec = _diff(match.slice(1), lastMatch.slice(1), currentLocation.query, lastLocation.query, queries);
var currentQuery = _queryString2.default.parse(currentLocation.search);
var lastQuery = _queryString2.default.parse(lastLocation.search);
shouldExec = _diff(match.slice(1), lastMatch.slice(1), currentQuery, lastQuery, queries);
}
}
if (shouldExec) {
var queryResult = [];
var search = _queryString2.default.parse(currentLocation.search);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
Expand All @@ -68,7 +75,7 @@ function subscribe(history, dispatch) {
for (var _iterator2 = (0, _getIterator3.default)(queries), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var query = _step2.value;

queryResult.push(currentLocation.query[query]);
queryResult.push(search[query]);
}
} catch (err) {
_didIteratorError2 = true;
Expand All @@ -95,7 +102,9 @@ function subscribe(history, dispatch) {
for (var _iterator3 = (0, _getIterator3.default)(action), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var i = _step3.value;

dispatch(i);
if (i) {
dispatch(i);
}
}
} catch (err) {
_didIteratorError3 = true;
Expand All @@ -112,7 +121,9 @@ function subscribe(history, dispatch) {
}
}
} else {
dispatch(action);
if (action) {
dispatch(action);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
},
"dependencies": {
"babel-runtime": "^6.23.0",
"path-to-regexp": "^1.7.0"
"path-to-regexp": "^1.7.0",
"query-string": "^6.0.0"
},
"peerDependencies": {
"dva": "^1.0.0"
Expand Down
16 changes: 12 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import pathToRegexp from 'path-to-regexp'
import queryString from 'query-string'

/**
* @param {Object} history, react-router history
Expand Down Expand Up @@ -47,21 +48,28 @@ function subscribe (history, dispatch, ...rules) {
if (!lastMatch) {
shouldExec = true
} else {
shouldExec = _diff(match.slice(1), lastMatch.slice(1), currentLocation.query, lastLocation.query, queries)
const currentQuery = queryString.parse(currentLocation.search);
const lastQuery = queryString.parse(lastLocation.search);
shouldExec = _diff(match.slice(1), lastMatch.slice(1), currentQuery, lastQuery, queries)
}
}
if (shouldExec) {
const queryResult = []
const search = queryString.parse(currentLocation.search)
for (let query of queries) {
queryResult.push(currentLocation.query[query])
queryResult.push(search[query])
}
const action = actionCreator && actionCreator(...match.slice(1), ...queryResult)
if (Array.isArray(action)) {
for (let i of action) {
dispatch(i)
if (i) {
dispatch(i)
}
}
} else {
dispatch(action)
if (action) {
dispatch(action)
}
}
}
}
Expand Down