MCPcopy
hub / github.com/buildbot/buildbot / useDataApiDynamicQueryResolved

Function useDataApiDynamicQueryResolved

www/data-module/src/data/ReactUtils.ts:91–119  ·  view source on GitHub ↗
(
  dependency: any[], callback: () => Collection)

Source from the content-addressed store, hash-verified

89// useDataApiDynamicQuery() will return empty collection whenever it is refreshed whereas
90// this function will wait until the replacement query is resolved.
91export function useDataApiDynamicQueryResolved<T, Collection extends IDataCollection>(
92 dependency: any[], callback: () => Collection): Collection {
93 const storedDependency = useRef<any[]>([]);
94 let storedCollection = useRef<Collection|null>(null);
95 let storedNewCollection = useRef<Collection|null>(null);
96
97 if (storedCollection.current === null ||
98 !storedCollection.current.isValid() ||
99 !arrayElementsEqual(dependency, storedDependency.current)) {
100
101 if (storedCollection.current !== null) {
102 if (storedNewCollection.current !== null) {
103 storedNewCollection.current.close();
104 }
105 storedNewCollection.current = callback();
106 } else {
107 storedCollection.current = callback();
108 }
109 storedDependency.current = [...dependency];
110 } else if (storedNewCollection.current !== null && storedNewCollection.current.isResolved()) {
111 if (storedCollection.current !== null) {
112 storedCollection.current.close();
113 }
114 storedCollection.current = storedNewCollection.current;
115 storedNewCollection.current = null;
116 }
117
118 return storedCollection.current;
119}
120
121export function useDataApiSingleElementQuery<T extends BaseClass, U extends BaseClass>(
122 el: T | null, dependencies: any[], callback: (el: T) => DataCollection<U>): DataCollection<U> {

Callers 1

WaterfallView.tsxFile · 0.85

Calls 4

arrayElementsEqualFunction · 0.85
isValidMethod · 0.65
closeMethod · 0.65
isResolvedMethod · 0.65

Tested by

no test coverage detected