Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Aug 8, 2024
1 parent 86e159f commit 9e53130
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 68 deletions.
17 changes: 0 additions & 17 deletions src/combine-observers.ts

This file was deleted.

15 changes: 5 additions & 10 deletions src/create-apis.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import {
HandleAccessRequest,
PermissionStore,
createPermissionObserver,
createPermissionStore,
createPermissions,
} from "fake-permissions";
import {
combineObservers,
type GeolocationAndGeolocationPermissionObserver,
} from "./combine-observers.js";
import { createGeolocationObserver } from "./geolocation-observer.js";
createGeolocationObserver,
type GeolocationObserver,
} from "./geolocation-observer.js";
import { createGeolocation } from "./geolocation.js";
import {
MutableLocationServices,
Expand All @@ -32,7 +30,7 @@ export function createAPIs({
} = {}): {
geolocation: Geolocation;
locationServices: MutableLocationServices;
observer: GeolocationAndGeolocationPermissionObserver;
observer: GeolocationObserver;
permissions: Permissions;
permissionStore: PermissionStore;
user: User;
Expand All @@ -53,10 +51,7 @@ export function createAPIs({
user,
});

const observer = combineObservers(
createGeolocationObserver(geolocation),
createPermissionObserver(permissions, { name: "geolocation" }),
);
const observer = createGeolocationObserver(geolocation, permissions);

return {
geolocation,
Expand Down
17 changes: 6 additions & 11 deletions src/create-wrapped-apis.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {
PermissionStore,
createDelegatedPermissions,
createPermissionObserver,
type HandleAccessRequest,
} from "fake-permissions";
import {
combineObservers,
type GeolocationAndGeolocationPermissionObserver,
} from "./combine-observers.js";
import { createAPIs } from "./create-apis.js";
import { createDelegatedGeolocation } from "./delegated-geolocation.js";
import { createGeolocationObserver } from "./geolocation-observer.js";
import {
createGeolocationObserver,
type GeolocationObserver,
} from "./geolocation-observer.js";
import { MutableLocationServices } from "./location-services.js";
import { User } from "./user.js";

Expand All @@ -34,7 +32,7 @@ export function createWrappedAPIs({
geolocation: Geolocation;
isUsingSuppliedAPIs: () => boolean;
locationServices: MutableLocationServices;
observer: GeolocationAndGeolocationPermissionObserver;
observer: GeolocationObserver;
permissions: Permissions;
permissionStore: PermissionStore;
selectAPIs: (useSuppliedAPIs: boolean) => void;
Expand Down Expand Up @@ -70,10 +68,7 @@ export function createWrappedAPIs({
delegates: [fakePermissions, suppliedPermissions],
});

const observer = combineObservers(
createGeolocationObserver(geolocation),
createPermissionObserver(permissions, { name: "geolocation" }),
);
const observer = createGeolocationObserver(geolocation, permissions);

return {
geolocation,
Expand Down
12 changes: 12 additions & 0 deletions src/geolocation-observer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
createPermissionObserver,
type PermissionObserver,
} from "fake-permissions";
import type { PartialGeolocationCoordinates } from "./geolocation-coordinates.js";
import { type GeolocationPositionErrorCode } from "./geolocation-position-error.js";

Expand All @@ -14,11 +18,17 @@ export type GeolocationObserver = {
task?: () => Promise<void>,
positionOptions?: PositionOptions,
): Promise<void>;
waitForPermissionState: PermissionObserver["waitForState"];
};

export function createGeolocationObserver(
geolocation: Geolocation,
permissions: Permissions,
): GeolocationObserver {
const permissionObserver = createPermissionObserver(permissions, {
name: "geolocation",
});

return {
async waitForCoordinates(matcherOrMatchers = [], task, positionOptions) {
const matchers = normalizeMatchers(matcherOrMatchers);
Expand Down Expand Up @@ -57,6 +67,8 @@ export function createGeolocationObserver(
Promise.resolve(task?.()),
]);
},

waitForPermissionState: permissionObserver.waitForState,
};

function isMatchingCoords(
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export type { GeolocationAndGeolocationPermissionObserver } from "./combine-observers.js";
export { compareCoordinates } from "./compare-coordinates.js";
export { createAPIs } from "./create-apis.js";
export { createWrappedAPIs } from "./create-wrapped-apis.js";
Expand Down
4 changes: 2 additions & 2 deletions test/vitest/create-wrapped-apis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
createAPIs,
createPosition,
createWrappedAPIs,
type GeolocationAndGeolocationPermissionObserver,
type GeolocationObserver,
} from "fake-geolocation";
import {
afterEach,
Expand All @@ -24,7 +24,7 @@ describe("createWrappedAPIs()", () => {
let suppliedUser: User;

let geolocation: Geolocation;
let observer: GeolocationAndGeolocationPermissionObserver;
let observer: GeolocationObserver;
let permissions: Permissions;
let user: User;
let selectAPIs: (useSuppliedAPIs: boolean) => void;
Expand Down
Loading

0 comments on commit 9e53130

Please sign in to comment.