@civet/core 0.6.6 → 0.6.9
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/ConfigProvider.js +5 -5
- package/lib/DefaultDataStore.js +9 -9
- package/lib/Meta.js +1 -1
- package/lib/Resource.js +120 -104
- package/lib/context.js +4 -4
- package/lib/createPlugin.js +9 -9
- package/lib/index.js +35 -35
- package/lib/uniqueIdentifier.js +56 -0
- package/package.json +24 -23
- package/src/ConfigProvider.js +1 -1
- package/src/Resource.js +17 -16
- package/src/index.js +9 -10
- package/src/uniqueIdentifier.js +27 -0
package/lib/ConfigProvider.js
CHANGED
|
@@ -7,19 +7,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports["default"] = void 0;
|
|
9
9
|
|
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
11
|
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
14
|
var _context = require("./context");
|
|
15
15
|
|
|
16
16
|
var _DataStore = require("./DataStore");
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
21
|
|
|
22
|
-
function
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Provides general configuration to its descendants using React's context API.
|
package/lib/DefaultDataStore.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -11,28 +13,26 @@ var _DataStore = _interopRequireDefault(require("./DataStore"));
|
|
|
11
13
|
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
15
|
|
|
14
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
15
|
-
|
|
16
16
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
17
|
|
|
18
18
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
19
19
|
|
|
20
20
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
21
21
|
|
|
22
|
-
function
|
|
22
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
23
|
+
|
|
24
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
25
|
+
|
|
26
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
23
27
|
|
|
24
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
28
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
25
29
|
|
|
26
30
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
27
31
|
|
|
28
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
32
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
29
33
|
|
|
30
34
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
31
35
|
|
|
32
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
33
|
-
|
|
34
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
|
-
|
|
36
36
|
var DefaultDataStore = /*#__PURE__*/function (_BaseDataStore) {
|
|
37
37
|
_inherits(DefaultDataStore, _BaseDataStore);
|
|
38
38
|
|
package/lib/Meta.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
9
9
|
|
|
10
10
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
11
11
|
|
package/lib/Resource.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -11,53 +13,59 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
13
|
|
|
12
14
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
15
|
|
|
14
|
-
var _uuid = require("uuid");
|
|
15
|
-
|
|
16
16
|
var _AbortSignal = _interopRequireDefault(require("./AbortSignal"));
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _context2 = require("./context");
|
|
19
19
|
|
|
20
20
|
var _DataStore = require("./DataStore");
|
|
21
21
|
|
|
22
22
|
var _Meta = _interopRequireDefault(require("./Meta"));
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
var _uniqueIdentifier = _interopRequireDefault(require("./uniqueIdentifier"));
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
var _excluded = ["data"],
|
|
27
|
+
_excluded2 = ["data"],
|
|
28
|
+
_excluded3 = ["children"];
|
|
27
29
|
|
|
28
|
-
function
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
31
|
|
|
30
|
-
function
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
+
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
35
|
|
|
32
36
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
33
37
|
|
|
34
38
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
35
39
|
|
|
36
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
40
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
37
41
|
|
|
38
42
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
39
43
|
|
|
40
44
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
41
45
|
|
|
46
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
47
|
+
|
|
48
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
49
|
+
|
|
42
50
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
43
51
|
|
|
44
52
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
45
53
|
|
|
46
54
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
47
55
|
|
|
48
|
-
function
|
|
56
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
49
57
|
|
|
50
|
-
function
|
|
58
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
51
59
|
|
|
52
|
-
function
|
|
60
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
53
61
|
|
|
54
|
-
function
|
|
62
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
55
63
|
|
|
56
|
-
function
|
|
64
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
57
65
|
|
|
58
|
-
function
|
|
66
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
59
67
|
|
|
60
|
-
function
|
|
68
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
61
69
|
|
|
62
70
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
63
71
|
|
|
@@ -114,52 +122,6 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
114
122
|
|
|
115
123
|
var _super = _createSuper(Resource);
|
|
116
124
|
|
|
117
|
-
_createClass(Resource, null, [{
|
|
118
|
-
key: "getDerivedStateFromProps",
|
|
119
|
-
value: function getDerivedStateFromProps(nextProps, prevState) {
|
|
120
|
-
var empty = nextProps.empty,
|
|
121
|
-
ds = nextProps.dataStore,
|
|
122
|
-
persistent = nextProps.persistent;
|
|
123
|
-
|
|
124
|
-
var _ = getComparator(nextProps);
|
|
125
|
-
|
|
126
|
-
if (prevState.ds !== ds || !compareRequests(ds, prevState._, _)) {
|
|
127
|
-
var request = (0, _uuid.v1)();
|
|
128
|
-
var revision = (0, _uuid.v1)();
|
|
129
|
-
var isEmpty = ds == null || empty;
|
|
130
|
-
var nextState = {
|
|
131
|
-
_: _,
|
|
132
|
-
ds: ds,
|
|
133
|
-
request: request,
|
|
134
|
-
revision: revision,
|
|
135
|
-
isLoading: !isEmpty,
|
|
136
|
-
persistent: persistent
|
|
137
|
-
};
|
|
138
|
-
var isPersistent;
|
|
139
|
-
|
|
140
|
-
if (prevState.value.meta.persistent === 'very' || persistent === 'very' && prevState.persistent === 'very') {
|
|
141
|
-
isPersistent = 'very';
|
|
142
|
-
} else if (prevState.value.meta.persistent || persistent && prevState.persistent) {
|
|
143
|
-
isPersistent = true;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (prevState.ds == null || prevState.ds !== ds || isEmpty || !isPersistent || isPersistent !== 'very' && prevState._.name !== _.name) {
|
|
147
|
-
nextState.value = getEmptyValue(nextProps, request, revision, isEmpty);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return nextState;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (prevState.persistent !== persistent) {
|
|
154
|
-
return {
|
|
155
|
-
persistent: persistent
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
}]);
|
|
162
|
-
|
|
163
125
|
function Resource(props) {
|
|
164
126
|
var _this;
|
|
165
127
|
|
|
@@ -167,37 +129,47 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
167
129
|
|
|
168
130
|
_this = _super.call(this, props);
|
|
169
131
|
|
|
170
|
-
_defineProperty(_assertThisInitialized(_this), "notify", function () {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
132
|
+
_defineProperty(_assertThisInitialized(_this), "notify", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
133
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
134
|
+
while (1) {
|
|
135
|
+
switch (_context.prev = _context.next) {
|
|
136
|
+
case 0:
|
|
137
|
+
return _context.abrupt("return", new Promise(function (resolve) {
|
|
138
|
+
_this.setState(function (currentState) {
|
|
139
|
+
if (currentState.ds == null || currentState.empty) return null;
|
|
140
|
+
var nextRevision = (0, _uniqueIdentifier["default"])(currentState.revision);
|
|
141
|
+
resolve({
|
|
142
|
+
request: currentState.request,
|
|
143
|
+
revision: nextRevision
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
isLoading: true,
|
|
147
|
+
revision: nextRevision
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
}));
|
|
151
|
+
|
|
152
|
+
case 1:
|
|
153
|
+
case "end":
|
|
154
|
+
return _context.stop();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}, _callee);
|
|
158
|
+
})));
|
|
185
159
|
|
|
186
|
-
var
|
|
160
|
+
var empty = props.empty,
|
|
187
161
|
ds = props.dataStore,
|
|
188
162
|
persistent = props.persistent;
|
|
189
|
-
|
|
190
|
-
var
|
|
191
|
-
|
|
192
|
-
var revision = (0, _uuid.v1)();
|
|
193
|
-
var isEmpty = ds == null || _empty;
|
|
163
|
+
var request = (0, _uniqueIdentifier["default"])();
|
|
164
|
+
var revision = (0, _uniqueIdentifier["default"])();
|
|
165
|
+
var isEmpty = ds == null || empty;
|
|
194
166
|
_this.state = {
|
|
195
167
|
_: getComparator(props),
|
|
196
168
|
ds: ds,
|
|
197
|
-
request:
|
|
169
|
+
request: request,
|
|
198
170
|
revision: revision,
|
|
199
171
|
isLoading: !isEmpty,
|
|
200
|
-
value: getEmptyValue(props,
|
|
172
|
+
value: getEmptyValue(props, request, revision, isEmpty),
|
|
201
173
|
persistent: persistent
|
|
202
174
|
};
|
|
203
175
|
return _this;
|
|
@@ -206,10 +178,10 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
206
178
|
_createClass(Resource, [{
|
|
207
179
|
key: "componentDidMount",
|
|
208
180
|
value: function componentDidMount() {
|
|
209
|
-
var _this$
|
|
210
|
-
name = _this$
|
|
211
|
-
empty = _this$
|
|
212
|
-
dataStore = _this$
|
|
181
|
+
var _this$props = this.props,
|
|
182
|
+
name = _this$props.name,
|
|
183
|
+
empty = _this$props.empty,
|
|
184
|
+
dataStore = _this$props.dataStore;
|
|
213
185
|
var _this$state = this.state,
|
|
214
186
|
request = _this$state.request,
|
|
215
187
|
revision = _this$state.revision;
|
|
@@ -220,10 +192,10 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
220
192
|
}, {
|
|
221
193
|
key: "componentDidUpdate",
|
|
222
194
|
value: function componentDidUpdate(prevProps, prevState) {
|
|
223
|
-
var _this$
|
|
224
|
-
name = _this$
|
|
225
|
-
empty = _this$
|
|
226
|
-
dataStore = _this$
|
|
195
|
+
var _this$props2 = this.props,
|
|
196
|
+
name = _this$props2.name,
|
|
197
|
+
empty = _this$props2.empty,
|
|
198
|
+
dataStore = _this$props2.dataStore;
|
|
227
199
|
var _this$state2 = this.state,
|
|
228
200
|
request = _this$state2.request,
|
|
229
201
|
revision = _this$state2.revision;
|
|
@@ -282,7 +254,7 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
282
254
|
if (error != null) {
|
|
283
255
|
return {
|
|
284
256
|
isLoading: false,
|
|
285
|
-
value: _objectSpread({}, currentState.value, {
|
|
257
|
+
value: _objectSpread(_objectSpread({}, currentState.value), {}, {
|
|
286
258
|
error: error,
|
|
287
259
|
isIncomplete: false
|
|
288
260
|
})
|
|
@@ -291,13 +263,13 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
291
263
|
|
|
292
264
|
var _currentState$value = currentState.value,
|
|
293
265
|
prevData = _currentState$value.data,
|
|
294
|
-
prevContext = _objectWithoutProperties(_currentState$value,
|
|
266
|
+
prevContext = _objectWithoutProperties(_currentState$value, _excluded);
|
|
295
267
|
|
|
296
268
|
var _getEmptyValue = getEmptyValue(props, request, revision, false),
|
|
297
269
|
emptyData = _getEmptyValue.data,
|
|
298
|
-
emptyValue = _objectWithoutProperties(_getEmptyValue,
|
|
270
|
+
emptyValue = _objectWithoutProperties(_getEmptyValue, _excluded2);
|
|
299
271
|
|
|
300
|
-
var context = _objectSpread({}, emptyValue, {
|
|
272
|
+
var context = _objectSpread(_objectSpread({}, emptyValue), {}, {
|
|
301
273
|
meta: meta.commit(prevContext.meta),
|
|
302
274
|
isIncomplete: !done,
|
|
303
275
|
isInitial: currentState.isInitial && !done
|
|
@@ -305,7 +277,7 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
305
277
|
|
|
306
278
|
return {
|
|
307
279
|
isLoading: !done,
|
|
308
|
-
value: _objectSpread({}, context, {
|
|
280
|
+
value: _objectSpread(_objectSpread({}, context), {}, {
|
|
309
281
|
data: dataStore.recycleItems(dataStore.transition(data, prevData, context, prevContext), prevData, context, prevContext)
|
|
310
282
|
})
|
|
311
283
|
};
|
|
@@ -317,9 +289,9 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
317
289
|
}, {
|
|
318
290
|
key: "render",
|
|
319
291
|
value: function render() {
|
|
320
|
-
var _this$
|
|
321
|
-
children = _this$
|
|
322
|
-
rest = _objectWithoutProperties(_this$
|
|
292
|
+
var _this$props3 = this.props,
|
|
293
|
+
children = _this$props3.children,
|
|
294
|
+
rest = _objectWithoutProperties(_this$props3, _excluded3);
|
|
323
295
|
|
|
324
296
|
var _this$state3 = this.state,
|
|
325
297
|
request = _this$state3.request,
|
|
@@ -327,7 +299,7 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
327
299
|
value = _this$state3.value;
|
|
328
300
|
if (value.dataStore == null) return null;
|
|
329
301
|
|
|
330
|
-
var contextValue = _objectSpread({}, value, {
|
|
302
|
+
var contextValue = _objectSpread(_objectSpread({}, value), {}, {
|
|
331
303
|
isLoading: isLoading,
|
|
332
304
|
isStale: request !== value.request,
|
|
333
305
|
notify: this.notify
|
|
@@ -336,7 +308,7 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
336
308
|
var plugins = Array.isArray(value.dataStore.resourcePlugins) ? value.dataStore.resourcePlugins : [];
|
|
337
309
|
|
|
338
310
|
var renderProvider = function renderProvider(context) {
|
|
339
|
-
return /*#__PURE__*/_react["default"].createElement(
|
|
311
|
+
return /*#__PURE__*/_react["default"].createElement(_context2.ResourceContext.Provider, {
|
|
340
312
|
value: context
|
|
341
313
|
}, children);
|
|
342
314
|
};
|
|
@@ -354,6 +326,50 @@ var Resource = /*#__PURE__*/function (_Component) {
|
|
|
354
326
|
};
|
|
355
327
|
}, renderProvider)(contextValue);
|
|
356
328
|
}
|
|
329
|
+
}], [{
|
|
330
|
+
key: "getDerivedStateFromProps",
|
|
331
|
+
value: function getDerivedStateFromProps(nextProps, prevState) {
|
|
332
|
+
var empty = nextProps.empty,
|
|
333
|
+
ds = nextProps.dataStore,
|
|
334
|
+
persistent = nextProps.persistent;
|
|
335
|
+
|
|
336
|
+
var _ = getComparator(nextProps);
|
|
337
|
+
|
|
338
|
+
if (prevState.ds !== ds || !compareRequests(ds, prevState._, _)) {
|
|
339
|
+
var request = (0, _uniqueIdentifier["default"])(prevState.request);
|
|
340
|
+
var revision = (0, _uniqueIdentifier["default"])(prevState.revision);
|
|
341
|
+
var isEmpty = ds == null || empty;
|
|
342
|
+
var nextState = {
|
|
343
|
+
_: _,
|
|
344
|
+
ds: ds,
|
|
345
|
+
request: request,
|
|
346
|
+
revision: revision,
|
|
347
|
+
isLoading: !isEmpty,
|
|
348
|
+
persistent: persistent
|
|
349
|
+
};
|
|
350
|
+
var isPersistent;
|
|
351
|
+
|
|
352
|
+
if (prevState.value.meta.persistent === 'very' || persistent === 'very' && prevState.persistent === 'very') {
|
|
353
|
+
isPersistent = 'very';
|
|
354
|
+
} else if (prevState.value.meta.persistent || persistent && prevState.persistent) {
|
|
355
|
+
isPersistent = true;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (prevState.ds == null || prevState.ds !== ds || isEmpty || !isPersistent || isPersistent !== 'very' && prevState._.name !== _.name) {
|
|
359
|
+
nextState.value = getEmptyValue(nextProps, request, revision, isEmpty);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return nextState;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (prevState.persistent !== persistent) {
|
|
366
|
+
return {
|
|
367
|
+
persistent: persistent
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
357
373
|
}]);
|
|
358
374
|
|
|
359
375
|
return Resource;
|
|
@@ -400,8 +416,8 @@ Resource.propTypes = {
|
|
|
400
416
|
|
|
401
417
|
var withContext = function withContext(ChildComponent) {
|
|
402
418
|
var WithContext = function WithContext(props) {
|
|
403
|
-
return /*#__PURE__*/_react["default"].createElement(
|
|
404
|
-
var dataStore =
|
|
419
|
+
return /*#__PURE__*/_react["default"].createElement(_context2.ConfigContext.Consumer, null, function (_ref4) {
|
|
420
|
+
var dataStore = _ref4.dataStore;
|
|
405
421
|
return /*#__PURE__*/_react["default"].createElement(ChildComponent, _extends({
|
|
406
422
|
dataStore: dataStore
|
|
407
423
|
}, props));
|
package/lib/context.js
CHANGED
|
@@ -9,13 +9,13 @@ exports.useResourceContext = exports.ResourceContext = exports.useConfigContext
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
12
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
13
|
|
|
14
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
15
|
|
|
16
16
|
var noop = function noop() {};
|
|
17
17
|
|
|
18
|
-
var ConfigContext = _react["default"].createContext({});
|
|
18
|
+
var ConfigContext = /*#__PURE__*/_react["default"].createContext({});
|
|
19
19
|
|
|
20
20
|
exports.ConfigContext = ConfigContext;
|
|
21
21
|
ConfigContext.displayName = 'ConfigContext';
|
|
@@ -26,7 +26,7 @@ var useConfigContext = function useConfigContext() {
|
|
|
26
26
|
|
|
27
27
|
exports.useConfigContext = useConfigContext;
|
|
28
28
|
|
|
29
|
-
var ResourceContext = _react["default"].createContext({
|
|
29
|
+
var ResourceContext = /*#__PURE__*/_react["default"].createContext({
|
|
30
30
|
data: [],
|
|
31
31
|
notify: noop
|
|
32
32
|
});
|
package/lib/createPlugin.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -9,24 +11,22 @@ var _DataStore = _interopRequireDefault(require("./DataStore"));
|
|
|
9
11
|
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
13
|
|
|
12
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
13
|
-
|
|
14
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
15
|
|
|
16
|
-
function
|
|
16
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
17
|
+
|
|
18
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
19
|
+
|
|
20
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
17
21
|
|
|
18
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
22
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
19
23
|
|
|
20
24
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
21
25
|
|
|
22
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
26
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
23
27
|
|
|
24
28
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
25
29
|
|
|
26
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
27
|
-
|
|
28
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
29
|
-
|
|
30
30
|
function createPlugin(plugin) {
|
|
31
31
|
if (typeof plugin !== 'function') throw new Error('No valid plugin definition specified');
|
|
32
32
|
return function (dataStoreClass) {
|
package/lib/index.js
CHANGED
|
@@ -17,105 +17,105 @@ Object.defineProperty(exports, "useResourceContext", {
|
|
|
17
17
|
return _context.useResourceContext;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
Object.defineProperty(exports, "
|
|
20
|
+
Object.defineProperty(exports, "AbortSignal", {
|
|
21
21
|
enumerable: true,
|
|
22
22
|
get: function get() {
|
|
23
|
-
return
|
|
23
|
+
return _AbortSignal["default"];
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
Object.defineProperty(exports, "
|
|
26
|
+
Object.defineProperty(exports, "ChannelNotifier", {
|
|
27
27
|
enumerable: true,
|
|
28
28
|
get: function get() {
|
|
29
|
-
return
|
|
29
|
+
return _ChannelNotifier["default"];
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
Object.defineProperty(exports, "
|
|
32
|
+
Object.defineProperty(exports, "compose", {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
get: function get() {
|
|
35
|
-
return
|
|
35
|
+
return _compose["default"];
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
Object.defineProperty(exports, "
|
|
38
|
+
Object.defineProperty(exports, "ConfigProvider", {
|
|
39
39
|
enumerable: true,
|
|
40
40
|
get: function get() {
|
|
41
|
-
return
|
|
41
|
+
return _ConfigProvider["default"];
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
-
Object.defineProperty(exports, "
|
|
44
|
+
Object.defineProperty(exports, "createPlugin", {
|
|
45
45
|
enumerable: true,
|
|
46
46
|
get: function get() {
|
|
47
|
-
return
|
|
47
|
+
return _createPlugin["default"];
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
|
-
Object.defineProperty(exports, "
|
|
50
|
+
Object.defineProperty(exports, "dataStorePropType", {
|
|
51
51
|
enumerable: true,
|
|
52
52
|
get: function get() {
|
|
53
|
-
return
|
|
53
|
+
return _DataStore.dataStorePropType;
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
|
-
Object.defineProperty(exports, "
|
|
56
|
+
Object.defineProperty(exports, "BaseDataStore", {
|
|
57
57
|
enumerable: true,
|
|
58
58
|
get: function get() {
|
|
59
|
-
return
|
|
59
|
+
return _DataStore["default"];
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
Object.defineProperty(exports, "
|
|
62
|
+
Object.defineProperty(exports, "isDataStore", {
|
|
63
63
|
enumerable: true,
|
|
64
64
|
get: function get() {
|
|
65
|
-
return
|
|
65
|
+
return _DataStore.isDataStore;
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
|
-
Object.defineProperty(exports, "
|
|
68
|
+
Object.defineProperty(exports, "DataStore", {
|
|
69
69
|
enumerable: true,
|
|
70
70
|
get: function get() {
|
|
71
|
-
return
|
|
71
|
+
return _DefaultDataStore["default"];
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
-
Object.defineProperty(exports, "
|
|
74
|
+
Object.defineProperty(exports, "Meta", {
|
|
75
75
|
enumerable: true,
|
|
76
76
|
get: function get() {
|
|
77
|
-
return
|
|
77
|
+
return _Meta["default"];
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
|
-
Object.defineProperty(exports, "
|
|
80
|
+
Object.defineProperty(exports, "Notifier", {
|
|
81
81
|
enumerable: true,
|
|
82
82
|
get: function get() {
|
|
83
|
-
return
|
|
83
|
+
return _Notifier["default"];
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
|
-
Object.defineProperty(exports, "
|
|
86
|
+
Object.defineProperty(exports, "Resource", {
|
|
87
87
|
enumerable: true,
|
|
88
88
|
get: function get() {
|
|
89
|
-
return
|
|
89
|
+
return _Resource["default"];
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
92
|
exports.ResourceConsumer = exports.ResourceProvider = exports.ConfigConsumer = void 0;
|
|
93
93
|
|
|
94
94
|
var _context = require("./context");
|
|
95
95
|
|
|
96
|
-
var
|
|
96
|
+
var _AbortSignal = _interopRequireDefault(require("./AbortSignal"));
|
|
97
97
|
|
|
98
|
-
var
|
|
98
|
+
var _ChannelNotifier = _interopRequireDefault(require("./ChannelNotifier"));
|
|
99
99
|
|
|
100
|
-
var
|
|
100
|
+
var _compose = _interopRequireDefault(require("./compose"));
|
|
101
101
|
|
|
102
|
-
var
|
|
102
|
+
var _ConfigProvider = _interopRequireDefault(require("./ConfigProvider"));
|
|
103
103
|
|
|
104
104
|
var _createPlugin = _interopRequireDefault(require("./createPlugin"));
|
|
105
105
|
|
|
106
|
-
var
|
|
106
|
+
var _DataStore = _interopRequireWildcard(require("./DataStore"));
|
|
107
107
|
|
|
108
|
-
var
|
|
108
|
+
var _DefaultDataStore = _interopRequireDefault(require("./DefaultDataStore"));
|
|
109
109
|
|
|
110
|
-
var
|
|
110
|
+
var _Meta = _interopRequireDefault(require("./Meta"));
|
|
111
111
|
|
|
112
|
-
var
|
|
112
|
+
var _Notifier = _interopRequireDefault(require("./Notifier"));
|
|
113
113
|
|
|
114
|
-
var
|
|
114
|
+
var _Resource = _interopRequireDefault(require("./Resource"));
|
|
115
115
|
|
|
116
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
116
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
117
117
|
|
|
118
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
118
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
119
119
|
|
|
120
120
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
121
121
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _uuid = require("uuid");
|
|
9
|
+
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
|
|
12
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
|
|
16
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
17
|
+
|
|
18
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
+
|
|
20
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns incrementing unique string identifiers.
|
|
24
|
+
* Uniqueness is guaranteed for <Number.MAX_SAFE_INTEGER> iterations.
|
|
25
|
+
* The values can be compared alphanumerically, as long as they do not exceed the previously specified iterations.
|
|
26
|
+
*
|
|
27
|
+
* @param {string?} previous Previous identifier
|
|
28
|
+
*/
|
|
29
|
+
function uniqueIdentifier(previous) {
|
|
30
|
+
var prefix;
|
|
31
|
+
var value;
|
|
32
|
+
var scope;
|
|
33
|
+
|
|
34
|
+
if (typeof previous !== 'string') {
|
|
35
|
+
prefix = '~';
|
|
36
|
+
value = 0;
|
|
37
|
+
scope = (0, _uuid.v1)();
|
|
38
|
+
} else {
|
|
39
|
+
var prevValue;
|
|
40
|
+
|
|
41
|
+
var _previous$split = previous.split('$');
|
|
42
|
+
|
|
43
|
+
var _previous$split2 = _slicedToArray(_previous$split, 3);
|
|
44
|
+
|
|
45
|
+
prefix = _previous$split2[0];
|
|
46
|
+
prevValue = _previous$split2[1];
|
|
47
|
+
scope = _previous$split2[2];
|
|
48
|
+
value = ((parseInt(prevValue, 36) || 0) + 1) % Number.MAX_SAFE_INTEGER;
|
|
49
|
+
if (value === 0) prefix += '~';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return "".concat(prefix, "$").concat(value.toString(36).padStart(11, '0'), "$").concat(scope);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var _default = uniqueIdentifier;
|
|
56
|
+
exports["default"] = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@civet/core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "Civet",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,35 +34,36 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://civet.js.org/",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@babel/cli": "7.8
|
|
38
|
-
"@babel/core": "7.
|
|
39
|
-
"@babel/plugin-proposal-class-properties": "7.
|
|
40
|
-
"@babel/preset-env": "7.
|
|
41
|
-
"@babel/preset-react": "7.
|
|
42
|
-
"babel-eslint": "10.1.0",
|
|
43
|
-
"cross-env": "7.0.
|
|
44
|
-
"cross-var": "1.1.0",
|
|
45
|
-
"eslint": "
|
|
46
|
-
"eslint-config-airbnb": "18.1
|
|
47
|
-
"eslint-config-airbnb-base": "14.1
|
|
48
|
-
"eslint-config-prettier": "
|
|
49
|
-
"eslint-plugin-import": "2.
|
|
50
|
-
"eslint-plugin-jsx-a11y": "6.
|
|
51
|
-
"eslint-plugin-prettier": "3.1
|
|
52
|
-
"eslint-plugin-react": "7.
|
|
53
|
-
"
|
|
37
|
+
"@babel/cli": "^7.14.8",
|
|
38
|
+
"@babel/core": "^7.15.0",
|
|
39
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
40
|
+
"@babel/preset-env": "^7.15.0",
|
|
41
|
+
"@babel/preset-react": "^7.14.5",
|
|
42
|
+
"babel-eslint": "^10.1.0",
|
|
43
|
+
"cross-env": "^7.0.3",
|
|
44
|
+
"cross-var": "^1.1.0",
|
|
45
|
+
"eslint": "7.2",
|
|
46
|
+
"eslint-config-airbnb": "^18.2.1",
|
|
47
|
+
"eslint-config-airbnb-base": "^14.2.1",
|
|
48
|
+
"eslint-config-prettier": "^8.3.0",
|
|
49
|
+
"eslint-plugin-import": "^2.22.1",
|
|
50
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
51
|
+
"eslint-plugin-prettier": "^3.4.1",
|
|
52
|
+
"eslint-plugin-react": "^7.21.5",
|
|
53
|
+
"eslint-plugin-react-hooks": "^4.2.0",
|
|
54
|
+
"prettier": "^2.3.2",
|
|
54
55
|
"react": "*",
|
|
55
56
|
"react-dom": "*",
|
|
56
|
-
"rimraf": "3.0.2"
|
|
57
|
+
"rimraf": "^3.0.2"
|
|
57
58
|
},
|
|
58
59
|
"peerDependencies": {
|
|
59
60
|
"react": ">= 16.8",
|
|
60
61
|
"react-dom": ">= 16.8"
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
|
-
"fast-deep-equal": "3.1.3",
|
|
64
|
-
"object-hash": "2.0
|
|
65
|
-
"prop-types": "15.7.2",
|
|
66
|
-
"uuid": "8.3.
|
|
64
|
+
"fast-deep-equal": "^3.1.3",
|
|
65
|
+
"object-hash": "^2.2.0",
|
|
66
|
+
"prop-types": "^15.7.2",
|
|
67
|
+
"uuid": "^8.3.2"
|
|
67
68
|
}
|
|
68
69
|
}
|
package/src/ConfigProvider.js
CHANGED
package/src/Resource.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import deepEquals from 'fast-deep-equal';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import React, { Component } from 'react';
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
import AbortSignal from './AbortSignal';
|
|
6
6
|
import { ConfigContext, ResourceContext } from './context';
|
|
7
7
|
import { dataStorePropType } from './DataStore';
|
|
8
8
|
import Meta from './Meta';
|
|
9
|
+
import uniqueIdentifier from './uniqueIdentifier';
|
|
9
10
|
|
|
10
11
|
function getComparator({ name, ids, query, empty, options }) {
|
|
11
12
|
return {
|
|
@@ -49,8 +50,8 @@ class Resource extends Component {
|
|
|
49
50
|
const { empty, dataStore: ds, persistent } = nextProps;
|
|
50
51
|
const _ = getComparator(nextProps);
|
|
51
52
|
if (prevState.ds !== ds || !compareRequests(ds, prevState._, _)) {
|
|
52
|
-
const request =
|
|
53
|
-
const revision =
|
|
53
|
+
const request = uniqueIdentifier(prevState.request);
|
|
54
|
+
const revision = uniqueIdentifier(prevState.revision);
|
|
54
55
|
const isEmpty = ds == null || empty;
|
|
55
56
|
const nextState = {
|
|
56
57
|
_,
|
|
@@ -89,8 +90,8 @@ class Resource extends Component {
|
|
|
89
90
|
constructor(props) {
|
|
90
91
|
super(props);
|
|
91
92
|
const { empty, dataStore: ds, persistent } = props;
|
|
92
|
-
const request =
|
|
93
|
-
const revision =
|
|
93
|
+
const request = uniqueIdentifier();
|
|
94
|
+
const revision = uniqueIdentifier();
|
|
94
95
|
const isEmpty = ds == null || empty;
|
|
95
96
|
this.state = {
|
|
96
97
|
_: getComparator(props),
|
|
@@ -135,18 +136,18 @@ class Resource extends Component {
|
|
|
135
136
|
if (this.abortSignal) this.abortSignal.abort();
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
notify = () =>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
139
|
+
notify = async () =>
|
|
140
|
+
new Promise((resolve) => {
|
|
141
|
+
this.setState((currentState) => {
|
|
142
|
+
if (currentState.ds == null || currentState.empty) return null;
|
|
143
|
+
const nextRevision = uniqueIdentifier(currentState.revision);
|
|
144
|
+
resolve({ request: currentState.request, revision: nextRevision });
|
|
145
|
+
return {
|
|
146
|
+
isLoading: true,
|
|
147
|
+
revision: nextRevision,
|
|
148
|
+
};
|
|
149
|
+
});
|
|
148
150
|
});
|
|
149
|
-
};
|
|
150
151
|
|
|
151
152
|
fetch(request, revision) {
|
|
152
153
|
const { ...props } = this.props;
|
package/src/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { ConfigContext,
|
|
1
|
+
import { ConfigContext, ResourceContext, useConfigContext, useResourceContext } from './context';
|
|
2
2
|
|
|
3
3
|
export const { Consumer: ConfigConsumer } = ConfigContext;
|
|
4
4
|
export const { Provider: ResourceProvider, Consumer: ResourceConsumer } = ResourceContext;
|
|
5
|
-
export {
|
|
6
|
-
|
|
5
|
+
export { default as AbortSignal } from './AbortSignal';
|
|
6
|
+
export { default as ChannelNotifier } from './ChannelNotifier';
|
|
7
|
+
export { default as compose } from './compose';
|
|
7
8
|
export { default as ConfigProvider } from './ConfigProvider';
|
|
8
|
-
export { default as Resource } from './Resource';
|
|
9
|
-
export { default as BaseDataStore, isDataStore, dataStorePropType } from './DataStore';
|
|
10
|
-
export { default as DataStore } from './DefaultDataStore';
|
|
11
9
|
export { default as createPlugin } from './createPlugin';
|
|
12
|
-
export { default as
|
|
13
|
-
export { default as
|
|
14
|
-
export { default as ChannelNotifier } from './ChannelNotifier';
|
|
15
|
-
export { default as AbortSignal } from './AbortSignal';
|
|
10
|
+
export { dataStorePropType, default as BaseDataStore, isDataStore } from './DataStore';
|
|
11
|
+
export { default as DataStore } from './DefaultDataStore';
|
|
16
12
|
export { default as Meta } from './Meta';
|
|
13
|
+
export { default as Notifier } from './Notifier';
|
|
14
|
+
export { default as Resource } from './Resource';
|
|
15
|
+
export { useConfigContext, useResourceContext };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { v1 as uuid } from 'uuid';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns incrementing unique string identifiers.
|
|
5
|
+
* Uniqueness is guaranteed for <Number.MAX_SAFE_INTEGER> iterations.
|
|
6
|
+
* The values can be compared alphanumerically, as long as they do not exceed the previously specified iterations.
|
|
7
|
+
*
|
|
8
|
+
* @param {string?} previous Previous identifier
|
|
9
|
+
*/
|
|
10
|
+
function uniqueIdentifier(previous) {
|
|
11
|
+
let prefix;
|
|
12
|
+
let value;
|
|
13
|
+
let scope;
|
|
14
|
+
if (typeof previous !== 'string') {
|
|
15
|
+
prefix = '~';
|
|
16
|
+
value = 0;
|
|
17
|
+
scope = uuid();
|
|
18
|
+
} else {
|
|
19
|
+
let prevValue;
|
|
20
|
+
[prefix, prevValue, scope] = previous.split('$');
|
|
21
|
+
value = ((parseInt(prevValue, 36) || 0) + 1) % Number.MAX_SAFE_INTEGER;
|
|
22
|
+
if (value === 0) prefix += '~';
|
|
23
|
+
}
|
|
24
|
+
return `${prefix}$${value.toString(36).padStart(11, '0')}$${scope}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default uniqueIdentifier;
|