@legendapp/state 3.0.0-alpha.37 → 3.0.0-alpha.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/state",
3
- "version": "3.0.0-alpha.37",
3
+ "version": "3.0.0-alpha.38",
4
4
  "description": "legend-state",
5
5
  "sideEffects": false,
6
6
  "private": false,
@@ -14,6 +14,7 @@ function syncedQuery(params) {
14
14
  let observer = void 0;
15
15
  let latestOptions = defaultedOptions;
16
16
  let queryKeyFromFn;
17
+ let resolveInitialPromise = void 0;
17
18
  const origQueryKey = options.queryKey;
18
19
  const isKeyFunction = state.isFunction(origQueryKey);
19
20
  const updateQueryOptions = (obj) => {
@@ -33,14 +34,23 @@ function syncedQuery(params) {
33
34
  });
34
35
  }
35
36
  observer = new Observer(queryClient, latestOptions);
36
- const get = () => {
37
+ const get = async () => {
37
38
  const result = observer.getOptimisticResult(latestOptions);
39
+ if (result.isLoading) {
40
+ await new Promise((resolve) => {
41
+ resolveInitialPromise = resolve;
42
+ });
43
+ }
38
44
  return result.data;
39
45
  };
40
46
  const subscribe = ({ update }) => {
41
47
  const unsubscribe = observer.subscribe(
42
48
  queryCore.notifyManager.batchCalls((result) => {
43
49
  if (result.status === "success") {
50
+ if (resolveInitialPromise) {
51
+ resolveInitialPromise(result.data);
52
+ resolveInitialPromise = void 0;
53
+ }
44
54
  update({ value: result.data });
45
55
  }
46
56
  })
@@ -12,6 +12,7 @@ function syncedQuery(params) {
12
12
  let observer = void 0;
13
13
  let latestOptions = defaultedOptions;
14
14
  let queryKeyFromFn;
15
+ let resolveInitialPromise = void 0;
15
16
  const origQueryKey = options.queryKey;
16
17
  const isKeyFunction = isFunction(origQueryKey);
17
18
  const updateQueryOptions = (obj) => {
@@ -31,14 +32,23 @@ function syncedQuery(params) {
31
32
  });
32
33
  }
33
34
  observer = new Observer(queryClient, latestOptions);
34
- const get = () => {
35
+ const get = async () => {
35
36
  const result = observer.getOptimisticResult(latestOptions);
37
+ if (result.isLoading) {
38
+ await new Promise((resolve) => {
39
+ resolveInitialPromise = resolve;
40
+ });
41
+ }
36
42
  return result.data;
37
43
  };
38
44
  const subscribe = ({ update }) => {
39
45
  const unsubscribe = observer.subscribe(
40
46
  notifyManager.batchCalls((result) => {
41
47
  if (result.status === "success") {
48
+ if (resolveInitialPromise) {
49
+ resolveInitialPromise(result.data);
50
+ resolveInitialPromise = void 0;
51
+ }
42
52
  update({ value: result.data });
43
53
  }
44
54
  })