Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshaughnessy committed Jan 22, 2023
1 parent bbbe398 commit e0772f4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
9 changes: 1 addition & 8 deletions src/bit-systems/pdf-menu-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,9 @@ function render(world: HubsWorld, menu: EntityID, frozen: boolean) {
}
}

let menu: EntityID;
preload(
repeatUntilTrue(() => {
menu = (window.APP && APP.world && anyEntityWith(APP.world, PDFMenu)) as EntityID;
return !!menu;
})
);

const hoveredQuery = defineQuery([HoveredRemoteRight]);
export function pdfMenuSystem(world: HubsWorld, sceneIsFrozen: boolean) {
const menu = anyEntityWith(world, PDFMenu)!;
findPDFMenuTarget(world, menu, sceneIsFrozen);
if (PDFMenu.targetRef[menu]) {
moveToTarget(world, menu);
Expand Down
16 changes: 0 additions & 16 deletions src/utils/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,3 @@ export function waitForPreloads() {
export function preload<T>(p: Promise<T>) {
preloads.push(p);
}

export function repeatUntilTrue(predicate: () => boolean) {
let resolve: (arg?: any) => void;
const promise = new Promise(function (r) {
resolve = r;
});

const interval = setInterval(function () {
if (predicate()) {
clearInterval(interval);
resolve!();
}
}, 0);

return promise;
}

0 comments on commit e0772f4

Please sign in to comment.