From f4e9f857af1754ba9147eec9f5004ada26d0dcd5 Mon Sep 17 00:00:00 2001 From: Xuefeng Zhu Date: Tue, 24 Apr 2018 09:32:38 -0500 Subject: [PATCH 1/5] fix query for dva 2 --- lib/index.js | 7 ++++++- package.json | 3 ++- src/index.js | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 5c2c546..8c39f70 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) { @@ -60,6 +64,7 @@ function subscribe(history, dispatch) { } if (shouldExec) { var queryResult = []; + var search = _queryString2.default.parse(currentLocation.search); var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; @@ -68,7 +73,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; diff --git a/package.json b/package.json index ccb6ba2..471ced1 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/index.js b/src/index.js index 12aba79..0d8388e 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ */ import pathToRegexp from 'path-to-regexp' +import queryString from 'query-string' /** * @param {Object} history, react-router history @@ -52,8 +53,9 @@ function subscribe (history, dispatch, ...rules) { } 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)) { From 14cd84ef7d38b9054b762935392d5c0e799a99e4 Mon Sep 17 00:00:00 2001 From: Xuefeng Zhu Date: Tue, 24 Apr 2018 09:40:00 -0500 Subject: [PATCH 2/5] fix empty action --- lib/index.js | 4 +++- src/index.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 8c39f70..ebf0cc3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -117,7 +117,9 @@ function subscribe(history, dispatch) { } } } else { - dispatch(action); + if (action) { + dispatch(action); + } } } } diff --git a/src/index.js b/src/index.js index 0d8388e..a663c52 100644 --- a/src/index.js +++ b/src/index.js @@ -63,7 +63,9 @@ function subscribe (history, dispatch, ...rules) { dispatch(i) } } else { - dispatch(action) + if (action) { + dispatch(action) + } } } } From b611144adbfbd4010f5dad4d4e290d9a737d8773 Mon Sep 17 00:00:00 2001 From: Xuefeng Zhu Date: Tue, 24 Apr 2018 14:34:35 -0500 Subject: [PATCH 3/5] Update index.js --- src/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index a663c52..97f9eed 100644 --- a/src/index.js +++ b/src/index.js @@ -48,7 +48,8 @@ function subscribe (history, dispatch, ...rules) { if (!lastMatch) { shouldExec = true } else { - shouldExec = _diff(match.slice(1), lastMatch.slice(1), currentLocation.query, lastLocation.query, queries) + shouldExec = _diff(match.slice(1), lastMatch.slice(1), queryString.parse(currentLocation.search) +, queryString.parse(lastLocation.search), queries) } } if (shouldExec) { @@ -60,7 +61,9 @@ function subscribe (history, dispatch, ...rules) { const action = actionCreator && actionCreator(...match.slice(1), ...queryResult) if (Array.isArray(action)) { for (let i of action) { - dispatch(i) + if (i) { + dispatch(i) + } } } else { if (action) { From 224cae3e140e325a8e398c4f957b117e55ac581f Mon Sep 17 00:00:00 2001 From: Xuefeng Zhu Date: Wed, 25 Apr 2018 00:59:14 -0500 Subject: [PATCH 4/5] fix query --- lib/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index ebf0cc3..d742016 100644 --- a/lib/index.js +++ b/lib/index.js @@ -59,7 +59,7 @@ function subscribe(history, dispatch) { if (!lastMatch) { shouldExec = true; } else { - shouldExec = _diff(match.slice(1), lastMatch.slice(1), currentLocation.query, lastLocation.query, queries); + shouldExec = _diff(match.slice(1), lastMatch.slice(1), _queryString2.default.parse(currentLocation.search), _queryString2.default.parse(lastLocation.search), queries); } } if (shouldExec) { @@ -100,7 +100,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; From 9a7ddf2c7f63f0f7f1ad35e5108af7ac8366b8db Mon Sep 17 00:00:00 2001 From: Xuefeng Zhu Date: Wed, 25 Apr 2018 01:10:40 -0500 Subject: [PATCH 5/5] Fix query update diff --- lib/index.js | 4 +++- src/index.js | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index d742016..e201d80 100644 --- a/lib/index.js +++ b/lib/index.js @@ -59,7 +59,9 @@ function subscribe(history, dispatch) { if (!lastMatch) { shouldExec = true; } else { - shouldExec = _diff(match.slice(1), lastMatch.slice(1), _queryString2.default.parse(currentLocation.search), _queryString2.default.parse(lastLocation.search), 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) { diff --git a/src/index.js b/src/index.js index 97f9eed..ed96fe5 100644 --- a/src/index.js +++ b/src/index.js @@ -48,8 +48,9 @@ function subscribe (history, dispatch, ...rules) { if (!lastMatch) { shouldExec = true } else { - shouldExec = _diff(match.slice(1), lastMatch.slice(1), queryString.parse(currentLocation.search) -, queryString.parse(lastLocation.search), 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) {