@3plus/redux-api 1.0.4 → 1.1.0
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/lib/PubSub.js +3 -2
- package/lib/actionFn.js +19 -58
- package/lib/adapters/fetch.js +2 -2
- package/lib/async.js +2 -12
- package/lib/createHolder.js +2 -1
- package/lib/fetchResolver.js +2 -1
- package/lib/index.js +7 -51
- package/lib/reducerFn.js +2 -10
- package/lib/transformers.js +2 -5
- package/lib/urlTransform.js +17 -17
- package/lib/utils/get.js +2 -3
- package/lib/utils/merge.js +0 -1
- package/lib/utils/omit.js +2 -1
- package/module/PubSub.js +39 -0
- package/module/actionFn.js +373 -0
- package/module/adapters/fetch.js +40 -0
- package/module/async.js +21 -0
- package/module/createHolder.js +27 -0
- package/module/fetchResolver.js +15 -0
- package/module/helpers.js +54 -0
- package/module/index.js +127 -0
- package/module/reducerFn.js +74 -0
- package/module/transformers.js +17 -0
- package/module/urlTransform.js +65 -0
- package/module/utils/cache.js +84 -0
- package/module/utils/get.js +19 -0
- package/module/utils/merge.js +32 -0
- package/module/utils/omit.js +17 -0
- package/package.json +15 -7
package/lib/PubSub.js
CHANGED
|
@@ -10,7 +10,7 @@ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o =
|
|
|
10
10
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
11
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
12
12
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
-
var PubSub = exports["default"] =
|
|
13
|
+
var PubSub = exports["default"] = function () {
|
|
14
14
|
function PubSub() {
|
|
15
15
|
_classCallCheck(this, PubSub);
|
|
16
16
|
this.container = [];
|
|
@@ -39,4 +39,5 @@ var PubSub = exports["default"] = /*#__PURE__*/function () {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
}]);
|
|
42
|
-
}();
|
|
42
|
+
}();
|
|
43
|
+
module.exports = exports.default;
|
package/lib/actionFn.js
CHANGED
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = actionFn;
|
|
8
|
-
var _fastApply = _interopRequireDefault(require("fast-apply"));
|
|
9
|
-
var _url = _interopRequireDefault(require("url"));
|
|
10
8
|
var _urlTransform = _interopRequireDefault(require("./urlTransform"));
|
|
11
9
|
var _merge = _interopRequireDefault(require("./utils/merge"));
|
|
12
10
|
var _get = _interopRequireDefault(require("./utils/get"));
|
|
@@ -16,6 +14,10 @@ var _createHolder = _interopRequireDefault(require("./createHolder"));
|
|
|
16
14
|
var _helpers = require("./helpers");
|
|
17
15
|
var _cache = require("./utils/cache");
|
|
18
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
17
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
18
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
20
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
19
21
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
22
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
23
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -27,15 +29,6 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
27
29
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
28
30
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
29
31
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
30
|
-
/**
|
|
31
|
-
* Constructor for create action
|
|
32
|
-
* @param {String} url endpoint's url
|
|
33
|
-
* @param {String} name action name
|
|
34
|
-
* @param {Object} options action configuration
|
|
35
|
-
* @param {Object} ACTIONS map of actions
|
|
36
|
-
* @param {[type]} fetchAdapter adapter for fetching data
|
|
37
|
-
* @return {Function+Object} action function object
|
|
38
|
-
*/
|
|
39
32
|
function actionFn(url, name, options) {
|
|
40
33
|
var ACTIONS = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
41
34
|
var meta = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
@@ -58,10 +51,17 @@ function actionFn(url, name, options) {
|
|
|
58
51
|
var rootUrl = (0, _get["default"])(meta, "holder", "rootUrl");
|
|
59
52
|
rootUrl = !(rootUrl instanceof Function) ? rootUrl : rootUrl(urlT, params, getState);
|
|
60
53
|
if (rootUrl) {
|
|
61
|
-
var
|
|
62
|
-
|
|
54
|
+
var urlObject = {};
|
|
55
|
+
try {
|
|
56
|
+
urlObject = new URL(urlT);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
urlObject = {
|
|
59
|
+
pathname: urlT
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var rootUrlObject = new URL(rootUrl);
|
|
63
63
|
if (!urlObject.host) {
|
|
64
|
-
var urlPath = (rootUrlObject.
|
|
64
|
+
var urlPath = (rootUrlObject.pathname ? rootUrlObject.pathname.replace(/\/$/, "") : "") + "/" + (urlObject.pathname ? urlObject.pathname.replace(/^\//, "") : "");
|
|
65
65
|
urlT = "".concat(rootUrlObject.protocol, "//").concat(rootUrlObject.host).concat(urlPath);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -85,8 +85,6 @@ function actionFn(url, name, options) {
|
|
|
85
85
|
Object.defineProperty(data, "persisted", {
|
|
86
86
|
value: true
|
|
87
87
|
});
|
|
88
|
-
// expire persisted cache immediately after consumption
|
|
89
|
-
// because we will try to reload and persist new data
|
|
90
88
|
cache[id].expire = true;
|
|
91
89
|
}
|
|
92
90
|
return Promise.resolve(data);
|
|
@@ -111,13 +109,6 @@ function actionFn(url, name, options) {
|
|
|
111
109
|
defer && defer.reject(err);
|
|
112
110
|
return err;
|
|
113
111
|
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Fetch data from server
|
|
117
|
-
* @param {Object} pathvars path vars for url
|
|
118
|
-
* @param {Object} params fetch params
|
|
119
|
-
* @param {Function} getState helper meta function
|
|
120
|
-
*/
|
|
121
112
|
function request(pathvars, params, options) {
|
|
122
113
|
var getState = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _helpers.none;
|
|
123
114
|
var dispatch = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : _helpers.none;
|
|
@@ -150,13 +141,6 @@ function actionFn(url, name, options) {
|
|
|
150
141
|
ret && ret["catch"] && ret["catch"](_helpers.none);
|
|
151
142
|
return ret;
|
|
152
143
|
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Fetch data from server
|
|
156
|
-
* @param {Object} pathvars path vars for url
|
|
157
|
-
* @param {Object} params fetch params
|
|
158
|
-
* @param {Function} callback) callback execute after end request
|
|
159
|
-
*/
|
|
160
144
|
function fn() {
|
|
161
145
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
162
146
|
args[_key] = arguments[_key];
|
|
@@ -198,7 +182,6 @@ function actionFn(url, name, options) {
|
|
|
198
182
|
if (Object.defineProperty) {
|
|
199
183
|
Object.defineProperty(fetchResolverOpts, "requestOptions", {
|
|
200
184
|
get: function get() {
|
|
201
|
-
/* eslint no-console: 0 */
|
|
202
185
|
console.warn("Deprecated option, use `request` option");
|
|
203
186
|
return requestOptions;
|
|
204
187
|
}
|
|
@@ -262,7 +245,6 @@ function actionFn(url, name, options) {
|
|
|
262
245
|
}
|
|
263
246
|
pubsub.resolve(data);
|
|
264
247
|
done(data);
|
|
265
|
-
// special case where we will try to relaod data if persisted cache is consumed
|
|
266
248
|
if (d && d.persisted && meta.cache && meta.cache.reloadPersisted) {
|
|
267
249
|
fn.force.apply(fn, args)(dispatch, getState);
|
|
268
250
|
}
|
|
@@ -283,17 +265,9 @@ function actionFn(url, name, options) {
|
|
|
283
265
|
return result;
|
|
284
266
|
};
|
|
285
267
|
}
|
|
286
|
-
|
|
287
|
-
/*
|
|
288
|
-
Pure rest request
|
|
289
|
-
*/
|
|
290
268
|
fn.request = function (pathvars, params, options) {
|
|
291
269
|
return request(pathvars, params, options || {});
|
|
292
270
|
};
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Reset store to initial state
|
|
296
|
-
*/
|
|
297
271
|
fn.reset = function (mutation) {
|
|
298
272
|
abort();
|
|
299
273
|
return mutation === "sync" ? {
|
|
@@ -303,10 +277,6 @@ function actionFn(url, name, options) {
|
|
|
303
277
|
type: actionReset
|
|
304
278
|
};
|
|
305
279
|
};
|
|
306
|
-
|
|
307
|
-
/*
|
|
308
|
-
Abort request
|
|
309
|
-
*/
|
|
310
280
|
fn.abort = function () {
|
|
311
281
|
var error = abort();
|
|
312
282
|
return {
|
|
@@ -327,14 +297,6 @@ function actionFn(url, name, options) {
|
|
|
327
297
|
return fn.apply(void 0, args)(dispatch, getState);
|
|
328
298
|
};
|
|
329
299
|
};
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Sync store with server. In server mode works as usual method.
|
|
333
|
-
* If data have already synced, data would not fetch after call this method.
|
|
334
|
-
* @param {Object} pathvars path vars for url
|
|
335
|
-
* @param {Object} params fetch params
|
|
336
|
-
* @param {Function} callback) callback execute after end request
|
|
337
|
-
*/
|
|
338
300
|
fn.sync = function () {
|
|
339
301
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
340
302
|
args[_key3] = arguments[_key3];
|
|
@@ -378,7 +340,7 @@ function actionFn(url, name, options) {
|
|
|
378
340
|
return function (dispatch, getState) {
|
|
379
341
|
var index = args.length - 1;
|
|
380
342
|
var callbackFn = args[index] instanceof Function ? args[index] : _helpers.none;
|
|
381
|
-
var helpersResult = (
|
|
343
|
+
var helpersResult = call.apply({
|
|
382
344
|
getState: getState,
|
|
383
345
|
dispatch: dispatch,
|
|
384
346
|
actions: meta.actions
|
|
@@ -388,22 +350,20 @@ function actionFn(url, name, options) {
|
|
|
388
350
|
err ? reject(err) : resolve(data);
|
|
389
351
|
callbackFn(err, data);
|
|
390
352
|
};
|
|
391
|
-
// If helper alias using async functionality
|
|
392
353
|
if (helpersResult instanceof Function) {
|
|
393
354
|
helpersResult(function (error) {
|
|
394
355
|
var newArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
395
356
|
if (error) {
|
|
396
357
|
callback(error);
|
|
397
358
|
} else {
|
|
398
|
-
(
|
|
359
|
+
(sync ? fn.sync : fn).apply(void 0, _toConsumableArray(newArgs.concat(callback)))(dispatch, getState);
|
|
399
360
|
}
|
|
400
361
|
});
|
|
401
362
|
} else {
|
|
402
|
-
// if helper alias is synchronous
|
|
403
363
|
var _helpersResult = _slicedToArray(helpersResult, 2),
|
|
404
364
|
pathvars = _helpersResult[0],
|
|
405
365
|
params = _helpersResult[1];
|
|
406
|
-
(
|
|
366
|
+
(sync ? fn.sync : fn)(pathvars, params, callback)(dispatch, getState);
|
|
407
367
|
}
|
|
408
368
|
});
|
|
409
369
|
result["catch"](_helpers.none);
|
|
@@ -415,4 +375,5 @@ function actionFn(url, name, options) {
|
|
|
415
375
|
return Object.keys(helpers).reduce(function (memo, key) {
|
|
416
376
|
return fnHelperCallback(memo, helpers[key], key, helpers);
|
|
417
377
|
}, fn);
|
|
418
|
-
}
|
|
378
|
+
}
|
|
379
|
+
module.exports = exports.default;
|
package/lib/adapters/fetch.js
CHANGED
|
@@ -23,7 +23,6 @@ function toJSON(resp) {
|
|
|
23
23
|
function _default(fetch) {
|
|
24
24
|
return function (url, opts) {
|
|
25
25
|
return fetch(url, opts).then(function (resp) {
|
|
26
|
-
// Normalize IE9's response to HTTP 204 when Win error 1223.
|
|
27
26
|
var status = resp.status === 1223 ? 204 : resp.status;
|
|
28
27
|
var statusText = resp.status === 1223 ? "No Content" : resp.statusText;
|
|
29
28
|
if (status >= 400) {
|
|
@@ -42,4 +41,5 @@ function _default(fetch) {
|
|
|
42
41
|
}
|
|
43
42
|
});
|
|
44
43
|
};
|
|
45
|
-
}
|
|
44
|
+
}
|
|
45
|
+
module.exports = exports.default;
|
package/lib/async.js
CHANGED
|
@@ -4,17 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = async;
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {[type]} dispatch [description]
|
|
10
|
-
* @param {...[type]} args [description]
|
|
11
|
-
* @return {[type]} [description]
|
|
12
|
-
* @example
|
|
13
|
-
* async(dispatch,
|
|
14
|
-
* cb=> actions.test(1, cb),
|
|
15
|
-
* actions.test2
|
|
16
|
-
* ).then(()=> async(dispatch, actions.test3))
|
|
17
|
-
*/
|
|
18
7
|
function async(dispatch) {
|
|
19
8
|
var currentFunction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
20
9
|
for (var _len = arguments.length, restFunctions = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
@@ -35,4 +24,5 @@ function async(dispatch) {
|
|
|
35
24
|
return data;
|
|
36
25
|
}
|
|
37
26
|
});
|
|
38
|
-
}
|
|
27
|
+
}
|
|
28
|
+
module.exports = exports.default;
|
package/lib/createHolder.js
CHANGED
package/lib/fetchResolver.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
/* eslint no-void: 0 */
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
3
|
value: true
|
|
6
4
|
});
|
|
7
5
|
exports["default"] = reduxApi;
|
|
6
|
+
Object.defineProperty(exports, "transformers", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _transformers["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
8
12
|
var _reducerFn = _interopRequireDefault(require("./reducerFn"));
|
|
9
13
|
var _actionFn = _interopRequireDefault(require("./actionFn"));
|
|
10
14
|
var _transformers = _interopRequireDefault(require("./transformers"));
|
|
11
|
-
var _async = _interopRequireDefault(require("./async"));
|
|
12
15
|
var _cache = _interopRequireDefault(require("./utils/cache"));
|
|
13
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
14
17
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -17,53 +20,10 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
|
|
|
17
20
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
21
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
22
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
20
|
-
// export { transformers, async };
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Default configuration for each endpoint
|
|
24
|
-
* @type {Object}
|
|
25
|
-
*/
|
|
26
23
|
var defaultEndpointConfig = {
|
|
27
24
|
transformer: _transformers["default"].object
|
|
28
25
|
};
|
|
29
26
|
var PREFIX = "@@redux-api";
|
|
30
|
-
/**
|
|
31
|
-
* Entry api point
|
|
32
|
-
* @param {Object} config Rest api configuration
|
|
33
|
-
* @param {Object} baseConfig baseConfig settings for Rest api
|
|
34
|
-
* @param {Function} fetch Adapter for rest requests
|
|
35
|
-
* @param {Boolean} isServer false by default (fif you want to use it for isomorphic apps)
|
|
36
|
-
* @return {actions, reducers} { actions, reducers}
|
|
37
|
-
* @example ```js
|
|
38
|
-
* const api = reduxApi({
|
|
39
|
-
* test: "/plain/url",
|
|
40
|
-
* testItem: "/plain/url/:id",
|
|
41
|
-
* testModify: {
|
|
42
|
-
* url: "/plain/url/:endpoint",
|
|
43
|
-
|
|
44
|
-
* transformer: (data)=> !data ?
|
|
45
|
-
* { title: "", message: "" } :
|
|
46
|
-
* { title: data.title, message: data.message },
|
|
47
|
-
* options: {
|
|
48
|
-
* method: "post"
|
|
49
|
-
* headers: {
|
|
50
|
-
* "Accept": "application/json",
|
|
51
|
-
* "Content-Type": "application/json"
|
|
52
|
-
* }
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* });
|
|
56
|
-
* // register reducers
|
|
57
|
-
*
|
|
58
|
-
* // call actions
|
|
59
|
-
* dispatch(api.actions.test());
|
|
60
|
-
* dispatch(api.actions.testItem({id: 1}));
|
|
61
|
-
* dispatch(api.actions.testModify({endpoint: "upload-1"}, {
|
|
62
|
-
* body: JSON.stringify({title: "Hello", message: "World"})
|
|
63
|
-
* }));
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
27
|
function reduxApi(config, baseConfig) {
|
|
68
28
|
config || (config = {});
|
|
69
29
|
var fetchHolder = {
|
|
@@ -82,7 +42,6 @@ function reduxApi(config, baseConfig) {
|
|
|
82
42
|
init: function init(fetch) {
|
|
83
43
|
var isServer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
84
44
|
var rootUrl = arguments.length > 2 ? arguments[2] : undefined;
|
|
85
|
-
/* eslint no-console: 0 */
|
|
86
45
|
console.warn("Deprecated method, use `use` method");
|
|
87
46
|
this.use("fetch", fetch);
|
|
88
47
|
this.use("server", isServer);
|
|
@@ -101,7 +60,6 @@ function reduxApi(config, baseConfig) {
|
|
|
101
60
|
url: value
|
|
102
61
|
});
|
|
103
62
|
if (opts.broadcast !== void 0) {
|
|
104
|
-
/* eslint no-console: 0 */
|
|
105
63
|
console.warn("Deprecated `broadcast` option. you shoud use `events`" + "to catch redux-api events (see https://github.com/3plus/redux-api/blob/master/DOCS.md#Events)");
|
|
106
64
|
}
|
|
107
65
|
var url = opts.url,
|
|
@@ -176,6 +134,4 @@ function reduxApi(config, baseConfig) {
|
|
|
176
134
|
return Object.keys(config).reduce(function (memo, key) {
|
|
177
135
|
return fnConfigCallback(memo, config[key], key, config);
|
|
178
136
|
}, cfg);
|
|
179
|
-
}
|
|
180
|
-
reduxApi.transformers = _transformers["default"];
|
|
181
|
-
reduxApi.async = _async["default"];
|
|
137
|
+
}
|
package/lib/reducerFn.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
/* eslint no-case-declarations: 0 */
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
3
|
value: true
|
|
6
4
|
});
|
|
@@ -12,13 +10,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
12
10
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
12
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
-
/**
|
|
16
|
-
* Reducer contructor
|
|
17
|
-
* @param {Object} initialState default initial state
|
|
18
|
-
* @param {Object} actions actions map
|
|
19
|
-
* @param {Function} reducer custom reducer function
|
|
20
|
-
* @return {Function} reducer function
|
|
21
|
-
*/
|
|
22
13
|
function reducerFn(initialState) {
|
|
23
14
|
var actions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
24
15
|
var reducer = arguments.length > 2 ? arguments[2] : undefined;
|
|
@@ -84,4 +75,5 @@ function reducerFn(initialState) {
|
|
|
84
75
|
return reducer ? reducer(state, action) : state;
|
|
85
76
|
}
|
|
86
77
|
};
|
|
87
|
-
}
|
|
78
|
+
}
|
|
79
|
+
module.exports = exports.default;
|
package/lib/transformers.js
CHANGED
|
@@ -6,10 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var toString = Object.prototype.toString;
|
|
8
8
|
var OBJECT = "[object Object]";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Default responce transformens
|
|
12
|
-
*/
|
|
13
9
|
var _default = exports["default"] = {
|
|
14
10
|
array: function array(data) {
|
|
15
11
|
return !data ? [] : Array.isArray(data) ? data : [data];
|
|
@@ -22,4 +18,5 @@ var _default = exports["default"] = {
|
|
|
22
18
|
data: data
|
|
23
19
|
};
|
|
24
20
|
}
|
|
25
|
-
};
|
|
21
|
+
};
|
|
22
|
+
module.exports = exports.default;
|
package/lib/urlTransform.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = urlTransform;
|
|
7
7
|
var _qs = _interopRequireDefault(require("qs"));
|
|
8
|
-
var _url = require("url");
|
|
9
8
|
var _omit = _interopRequireDefault(require("./utils/omit"));
|
|
10
9
|
var _merge = _interopRequireDefault(require("./utils/merge"));
|
|
11
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
@@ -15,17 +14,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
15
14
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
16
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
16
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
|
-
/* eslint no-useless-escape: 0 */
|
|
19
17
|
var rxClean = /(\(:[^\)]+\)|:[^\/]+\/?)/g;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Url modification
|
|
23
|
-
* @param {String} url url template
|
|
24
|
-
* @param {Object} params params for url template
|
|
25
|
-
* @param {Object} options transformation options, accepts +delimiter+, +arrayFormat+,
|
|
26
|
-
* +qsStringifyOptions+ and +qsParseOptions+
|
|
27
|
-
* @return {String} result url
|
|
28
|
-
*/
|
|
29
18
|
function urlTransform(url, params, options) {
|
|
30
19
|
if (!url) {
|
|
31
20
|
return "";
|
|
@@ -43,11 +32,21 @@ function urlTransform(url, params, options) {
|
|
|
43
32
|
if (!urlWithParams) {
|
|
44
33
|
return urlWithParams;
|
|
45
34
|
}
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
var protocol, host, pathname;
|
|
36
|
+
try {
|
|
37
|
+
var _URL = new URL(urlWithParams);
|
|
38
|
+
protocol = _URL.protocol;
|
|
39
|
+
host = _URL.host;
|
|
40
|
+
pathname = _URL.pathname;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
var _pathname = {
|
|
43
|
+
pathname: urlWithParams
|
|
44
|
+
};
|
|
45
|
+
protocol = _pathname.protocol;
|
|
46
|
+
host = _pathname.host;
|
|
47
|
+
pathname = _pathname.pathname;
|
|
48
|
+
}
|
|
49
|
+
var cleanURL = host ? "".concat(protocol, "//").concat(host).concat(pathname.replace(rxClean, "")) : pathname.replace(rxClean, "");
|
|
51
50
|
var usedKeysArray = Object.keys(usedKeys);
|
|
52
51
|
if (usedKeysArray.length !== Object.keys(params).length) {
|
|
53
52
|
var urlObject = cleanURL.split("?");
|
|
@@ -68,4 +67,5 @@ function urlTransform(url, params, options) {
|
|
|
68
67
|
return "".concat(urlObject[0], "?").concat(urlStringParams);
|
|
69
68
|
}
|
|
70
69
|
return cleanURL;
|
|
71
|
-
}
|
|
70
|
+
}
|
|
71
|
+
module.exports = exports.default;
|
package/lib/utils/get.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
/* eslint no-void: 0 */
|
|
4
2
|
Object.defineProperty(exports, "__esModule", {
|
|
5
3
|
value: true
|
|
6
4
|
});
|
|
@@ -22,4 +20,5 @@ function get(obj) {
|
|
|
22
20
|
return Array.isArray(name) ? get.apply(void 0, [memo].concat(_toConsumableArray(name))) : isEmpty(name) ? memo : memo && memo[name];
|
|
23
21
|
}, obj);
|
|
24
22
|
}
|
|
25
|
-
var _default = exports["default"] = get;
|
|
23
|
+
var _default = exports["default"] = get;
|
|
24
|
+
module.exports = exports.default;
|
package/lib/utils/merge.js
CHANGED
package/lib/utils/omit.js
CHANGED
package/module/PubSub.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
5
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
6
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
var PubSub = function () {
|
|
10
|
+
function PubSub() {
|
|
11
|
+
_classCallCheck(this, PubSub);
|
|
12
|
+
this.container = [];
|
|
13
|
+
}
|
|
14
|
+
return _createClass(PubSub, [{
|
|
15
|
+
key: "push",
|
|
16
|
+
value: function push(cb) {
|
|
17
|
+
cb instanceof Function && this.container.push(cb);
|
|
18
|
+
}
|
|
19
|
+
}, {
|
|
20
|
+
key: "resolve",
|
|
21
|
+
value: function resolve(data) {
|
|
22
|
+
var container = this.container;
|
|
23
|
+
this.container = [];
|
|
24
|
+
container.forEach(function (cb) {
|
|
25
|
+
return cb(null, data);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
key: "reject",
|
|
30
|
+
value: function reject(err) {
|
|
31
|
+
var container = this.container;
|
|
32
|
+
this.container = [];
|
|
33
|
+
container.forEach(function (cb) {
|
|
34
|
+
return cb(err);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}]);
|
|
38
|
+
}();
|
|
39
|
+
export { PubSub as default };
|