eddev 0.1.39 → 0.1.40-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/routing/remoteProps.js +20 -19
package/package.json
CHANGED
package/routing/remoteProps.js
CHANGED
|
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports.hasCachedProps = exports.fetchProps = exports.isSameOrigin = exports.setInitialProps = exports.parseURL = void 0;
|
|
43
43
|
var url_parse_1 = __importDefault(require("url-parse"));
|
|
44
44
|
var qs_1 = __importDefault(require("qs"));
|
|
45
|
+
var pending = {};
|
|
45
46
|
var cache = {};
|
|
46
47
|
function parseURL(url) {
|
|
47
48
|
return (0, url_parse_1.default)(url, qs_1.default.parse);
|
|
@@ -63,26 +64,26 @@ function isSameOrigin(url) {
|
|
|
63
64
|
exports.isSameOrigin = isSameOrigin;
|
|
64
65
|
function fetchProps(url) {
|
|
65
66
|
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var parsed, cacheKey, requestUrl,
|
|
67
|
+
var parsed, cacheKey, requestUrl, promise;
|
|
67
68
|
return __generator(this, function (_a) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
parsed = parseURL(url);
|
|
70
|
+
cacheKey = getRouteCacheKey(url);
|
|
71
|
+
// Cached value?
|
|
72
|
+
if (cacheKey in cache)
|
|
73
|
+
return [2 /*return*/, Promise.resolve(cache[cacheKey])];
|
|
74
|
+
if (cacheKey in pending)
|
|
75
|
+
return [2 /*return*/, pending[cacheKey]];
|
|
76
|
+
parsed.query["_props"] = "1";
|
|
77
|
+
requestUrl = parsed.toString();
|
|
78
|
+
promise = fetch(requestUrl)
|
|
79
|
+
.then(function (response) { return response.json(); })
|
|
80
|
+
.then(function (data) {
|
|
81
|
+
delete pending[cacheKey];
|
|
82
|
+
cache[cacheKey] = data;
|
|
83
|
+
return data;
|
|
84
|
+
});
|
|
85
|
+
pending[cacheKey] = promise;
|
|
86
|
+
return [2 /*return*/, promise];
|
|
86
87
|
});
|
|
87
88
|
});
|
|
88
89
|
}
|