(
dependency: any[], callback: () => Collection)
| 68 | } |
| 69 | |
| 70 | export function useDataApiDynamicQuery<T, Collection extends IDataCollection>( |
| 71 | dependency: any[], callback: () => Collection): Collection { |
| 72 | const storedDependency = useRef<any[]>([]); |
| 73 | let storedCollection = useRef<Collection|null>(null); |
| 74 | |
| 75 | if (storedCollection.current === null || |
| 76 | !storedCollection.current.isValid() || |
| 77 | !arrayElementsEqual(dependency, storedDependency.current)) { |
| 78 | if (storedCollection.current !== null) { |
| 79 | storedCollection.current.close(); |
| 80 | } |
| 81 | storedCollection.current = callback(); |
| 82 | storedDependency.current = [...dependency]; |
| 83 | } |
| 84 | |
| 85 | return storedCollection.current; |
| 86 | } |
| 87 | |
| 88 | // The difference between this function and useDataApiDynamicQuery() is that |
| 89 | // useDataApiDynamicQuery() will return empty collection whenever it is refreshed whereas |
no test coverage detected