@civet/core 1.0.0-rc6 → 1.0.0-rc7
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/useResource.js +14 -3
- package/package.json +1 -1
- package/src/useResource.js +8 -4
package/lib/useResource.js
CHANGED
|
@@ -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/useResource.js
CHANGED
|
@@ -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);
|