@tokamakdev/plugin-location 0.1.0-beta.116 → 0.1.0-beta.117

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/plugin-location",
3
- "version": "0.1.0-beta.116",
3
+ "version": "0.1.0-beta.117",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/mantty/tokamak.git",
@@ -14,7 +14,7 @@
14
14
  "./android": "./android/bindings.ts"
15
15
  },
16
16
  "peerDependencies": {
17
- "@tokamakdev/plugin": "0.1.0-beta.116"
17
+ "@tokamakdev/plugin": "0.1.0-beta.117"
18
18
  },
19
19
  "files": [
20
20
  "android",
package/src/index.ts CHANGED
@@ -22,11 +22,8 @@ import type {
22
22
  export type * from "./types.js";
23
23
 
24
24
  class Location extends Plugin {
25
- readonly #ctx: TokamakContext;
26
-
27
25
  constructor(ctx: TokamakContext) {
28
26
  super(ctx, "location");
29
- this.#ctx = ctx;
30
27
  }
31
28
 
32
29
  /**
@@ -45,28 +42,18 @@ class Location extends Plugin {
45
42
  */
46
43
  async getCurrentPosition(options: PositionOptions = {}): Promise<Position> {
47
44
  await this.#authorize();
48
- const position = await this.#platform().currentPosition(this.#ctx, options);
45
+ const position = await this.#platform().currentPosition(this.ctx, options);
49
46
  if (position) return position;
50
47
  // Android finds no position in the background without background permission.
51
- const background = await lifecycleStage(this.#ctx) === "background";
48
+ const background = await lifecycleStage(this.ctx) === "background";
52
49
  throw background && (await this.permission()).background !== "granted" ? backgroundDenied() : unavailable("Location is unavailable");
53
50
  }
54
51
 
55
52
  /** Positions as the device moves, after `getCurrentPosition`'s permission checks. A slow reader receives the newest. */
56
53
  watchPosition(): JsonStream<Position> {
57
- return valueStream<Position>((next, error) => {
58
- let stop: (() => void) | undefined;
59
- let stopped = false;
60
- this.#authorize()
61
- .then(() => this.#platform().watchPositions(this.#ctx, next, error))
62
- .then((started) => {
63
- if (stopped) started();
64
- else stop = started;
65
- }, error);
66
- return () => {
67
- stopped = true;
68
- stop?.();
69
- };
54
+ return valueStream<Position>(async (next, error) => {
55
+ await this.#authorize();
56
+ return this.#platform().watchPositions(this.ctx, next, error);
70
57
  }, "dropOldest");
71
58
  }
72
59
 
@@ -80,7 +67,7 @@ class Location extends Plugin {
80
67
 
81
68
  /** The platform's composition of its location SDK. */
82
69
  #platform(): typeof apple | typeof android {
83
- switch (this.#ctx.platform) {
70
+ switch (this.ctx.platform) {
84
71
  case "ios":
85
72
  case "macos":
86
73
  return apple;