Skip to content

Commit b848318

Browse files
committed
revert useGet change that broke lazy behavior, combine watch so the API is not hit twice
1 parent 13703f5 commit b848318

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

docs/composition-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ And here's a look at each individual property:
281281
- `params` is a FeathersJS Params object OR a Composition API `ref` (or `computed`, since they return a `ref` instance) which returns a Params object.
282282
- Unlike the `useFind` utility, `useGet` does not currently have built-in debouncing.
283283
- `queryWhen` must be a `computed` property which returns a `boolean`. It provides a logical separation for preventing API requests apart from `null` in the `id`.
284-
- `lazy`, which is `true` by default, determines if the internal `watch` should fire immediately. By default a single query will be performed, independent of the watchers. Set `lazy: false` and the watchers on the `id` and `params` will fire immediately (currently this will cause duplicate queries to be performed, so it's not recommended).
284+
- `lazy`, which is `false` by default, determines if the internal `watch` should fire immediately. Set `lazy: true` and the query will not fire immediately. It will only fire on subsequent changes to the `id` or `params`.
285285
286286
### Returned Attributes
287287

src/useGet.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function get<T extends AnyData = AnyData>(options: UseGetOptions<
4646
params: null,
4747
queryWhen: computed((): boolean => true),
4848
local: false,
49-
lazy: true
49+
lazy: false
5050
}
5151
const { model, id, params, queryWhen, local, lazy } = Object.assign(
5252
{},
@@ -113,25 +113,16 @@ export default function get<T extends AnyData = AnyData>(options: UseGetOptions<
113113
}
114114
}
115115

116-
watch(
116+
watch([
117117
() => getId(),
118-
id => {
119-
get(id, getParams())
120-
},
121-
{ lazy }
122-
)
123-
watch(
124118
() => getParams(),
125-
params => {
126-
get(getId(), params)
119+
],
120+
([id, params]) => {
121+
get(id as Id, params as Params)
127122
},
128123
{ lazy }
129124
)
130125

131-
if (lazy) {
132-
get(id, getParams())
133-
}
134-
135126
return {
136127
...toRefs(state),
137128
...computes,

0 commit comments

Comments
 (0)