@civet/core 1.0.0-rc6 → 1.0.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/uniqueIdentifier.js +1 -1
- package/lib/useResource.js +16 -5
- package/package.json +1 -1
- package/src/uniqueIdentifier.js +1 -1
- package/src/useResource.js +10 -6
package/lib/uniqueIdentifier.js
CHANGED
|
@@ -22,7 +22,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
22
22
|
/**
|
|
23
23
|
* Returns incrementing unique string identifiers.
|
|
24
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.
|
|
25
|
+
* The values can be compared alphanumerically, as long as they do not exceed the previously specified number of iterations.
|
|
26
26
|
*
|
|
27
27
|
* @param {string?} previous Previous identifier
|
|
28
28
|
*/
|
package/lib/useResource.js
CHANGED
|
@@ -99,7 +99,7 @@ function useResource(_ref) {
|
|
|
99
99
|
data: [],
|
|
100
100
|
meta: {},
|
|
101
101
|
error: undefined,
|
|
102
|
-
isEmpty: empty,
|
|
102
|
+
isEmpty: !!empty,
|
|
103
103
|
isIncomplete: !empty,
|
|
104
104
|
isInitial: !empty
|
|
105
105
|
},
|
|
@@ -144,7 +144,7 @@ function useResource(_ref) {
|
|
|
144
144
|
data: [],
|
|
145
145
|
meta: {},
|
|
146
146
|
error: undefined,
|
|
147
|
-
isEmpty: empty,
|
|
147
|
+
isEmpty: !!empty,
|
|
148
148
|
isIncomplete: !empty,
|
|
149
149
|
isInitial: !empty
|
|
150
150
|
},
|
|
@@ -227,7 +227,7 @@ function useResource(_ref) {
|
|
|
227
227
|
error: undefined,
|
|
228
228
|
isEmpty: false,
|
|
229
229
|
isIncomplete: !done,
|
|
230
|
-
isInitial: prevState.isInitial && !done
|
|
230
|
+
isInitial: !!prevState.isInitial && !done
|
|
231
231
|
};
|
|
232
232
|
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
233
233
|
isLoading: !done,
|
|
@@ -244,16 +244,27 @@ function useResource(_ref) {
|
|
|
244
244
|
};
|
|
245
245
|
}, [request, revision]);
|
|
246
246
|
|
|
247
|
-
var isStale =
|
|
247
|
+
var isStale = revision !== value.revision;
|
|
248
|
+
|
|
249
|
+
var next = _react["default"].useMemo(function () {
|
|
250
|
+
return isStale ? {
|
|
251
|
+
request: request,
|
|
252
|
+
revision: revision
|
|
253
|
+
} : {
|
|
254
|
+
request: value.request,
|
|
255
|
+
revision: value.revision
|
|
256
|
+
};
|
|
257
|
+
}, [isStale, request, revision, value.request, value.revision]);
|
|
248
258
|
|
|
249
259
|
var context = _react["default"].useMemo(function () {
|
|
250
260
|
return _objectSpread(_objectSpread({}, value), {}, {
|
|
251
261
|
dataProvider: dataProvider,
|
|
252
262
|
isLoading: isLoading,
|
|
253
263
|
isStale: isStale,
|
|
264
|
+
next: next,
|
|
254
265
|
notify: notify
|
|
255
266
|
});
|
|
256
|
-
}, [value, dataProvider, isLoading, isStale, notify]);
|
|
267
|
+
}, [value, dataProvider, isLoading, isStale, next, notify]);
|
|
257
268
|
|
|
258
269
|
return dataProvider.contextPlugins.reduce(function (result, fn) {
|
|
259
270
|
return fn(result, rest);
|
package/package.json
CHANGED
package/src/uniqueIdentifier.js
CHANGED
|
@@ -3,7 +3,7 @@ import { v1 as uuid } from 'uuid';
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns incrementing unique string identifiers.
|
|
5
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.
|
|
6
|
+
* The values can be compared alphanumerically, as long as they do not exceed the previously specified number of iterations.
|
|
7
7
|
*
|
|
8
8
|
* @param {string?} previous Previous identifier
|
|
9
9
|
*/
|
package/src/useResource.js
CHANGED
|
@@ -51,7 +51,7 @@ function useResource({
|
|
|
51
51
|
data: [],
|
|
52
52
|
meta: {},
|
|
53
53
|
error: undefined,
|
|
54
|
-
isEmpty: empty,
|
|
54
|
+
isEmpty: !!empty,
|
|
55
55
|
isIncomplete: !empty,
|
|
56
56
|
isInitial: !empty,
|
|
57
57
|
},
|
|
@@ -100,7 +100,7 @@ function useResource({
|
|
|
100
100
|
data: [],
|
|
101
101
|
meta: {},
|
|
102
102
|
error: undefined,
|
|
103
|
-
isEmpty: empty,
|
|
103
|
+
isEmpty: !!empty,
|
|
104
104
|
isIncomplete: !empty,
|
|
105
105
|
isInitial: !empty,
|
|
106
106
|
},
|
|
@@ -166,7 +166,7 @@ function useResource({
|
|
|
166
166
|
error: undefined,
|
|
167
167
|
isEmpty: false,
|
|
168
168
|
isIncomplete: !done,
|
|
169
|
-
isInitial: prevState.isInitial && !done,
|
|
169
|
+
isInitial: !!prevState.isInitial && !done,
|
|
170
170
|
};
|
|
171
171
|
|
|
172
172
|
return {
|
|
@@ -192,10 +192,14 @@ function useResource({
|
|
|
192
192
|
};
|
|
193
193
|
}, [request, revision]);
|
|
194
194
|
|
|
195
|
-
const isStale =
|
|
195
|
+
const isStale = revision !== value.revision;
|
|
196
|
+
const next = React.useMemo(
|
|
197
|
+
() => (isStale ? { request, revision } : { request: value.request, revision: value.revision }),
|
|
198
|
+
[isStale, request, revision, value.request, value.revision],
|
|
199
|
+
);
|
|
196
200
|
const context = React.useMemo(
|
|
197
|
-
() => ({ ...value, dataProvider, isLoading, isStale, notify }),
|
|
198
|
-
[value, dataProvider, isLoading, isStale, notify],
|
|
201
|
+
() => ({ ...value, dataProvider, isLoading, isStale, next, notify }),
|
|
202
|
+
[value, dataProvider, isLoading, isStale, next, notify],
|
|
199
203
|
);
|
|
200
204
|
|
|
201
205
|
return dataProvider.contextPlugins.reduce((result, fn) => fn(result, rest), context);
|