@civet/core 1.0.0-rc5 → 1.0.0-rc8
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 +18 -7
- package/package.json +1 -1
- package/src/useResource.js +11 -6
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,14 +227,14 @@ 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
|
-
return {
|
|
232
|
+
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
233
233
|
isLoading: !done,
|
|
234
234
|
value: _objectSpread(_objectSpread({}, context), {}, {
|
|
235
235
|
data: dataProvider.recycleItems(dataProvider.transition(data, prevData, context, prevContext), prevData, context, prevContext)
|
|
236
236
|
})
|
|
237
|
-
};
|
|
237
|
+
});
|
|
238
238
|
});
|
|
239
239
|
};
|
|
240
240
|
|
|
@@ -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
|
@@ -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,10 +166,11 @@ 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 {
|
|
173
|
+
...prevState,
|
|
173
174
|
isLoading: !done,
|
|
174
175
|
value: {
|
|
175
176
|
...context,
|
|
@@ -191,10 +192,14 @@ function useResource({
|
|
|
191
192
|
};
|
|
192
193
|
}, [request, revision]);
|
|
193
194
|
|
|
194
|
-
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
|
+
);
|
|
195
200
|
const context = React.useMemo(
|
|
196
|
-
() => ({ ...value, dataProvider, isLoading, isStale, notify }),
|
|
197
|
-
[value, dataProvider, isLoading, isStale, notify],
|
|
201
|
+
() => ({ ...value, dataProvider, isLoading, isStale, next, notify }),
|
|
202
|
+
[value, dataProvider, isLoading, isStale, next, notify],
|
|
198
203
|
);
|
|
199
204
|
|
|
200
205
|
return dataProvider.contextPlugins.reduce((result, fn) => fn(result, rest), context);
|