Skip to content

Commit 0366dcc

Browse files
committed
Refactoring
1 parent ebaf2d8 commit 0366dcc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/web-api/src/geolocation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,11 @@ export function trackGeolocation(
169169

170170
// -- watch position
171171

172-
const saveUnsubscribe = createEvent<Unsubscribe>();
173-
const $unsubscribe = restore(saveUnsubscribe, null);
172+
const $unsubscribe = createStore<Unsubscribe | null>(null);
174173

175174
const watchPositionFx = createEffect(() => {
176175
const boundNewPosition = scopeBind(newPosition, { safe: true });
177176
const boundFailed = scopeBind(failed, { safe: true });
178-
const boundSaveUnsubscribe = scopeBind(saveUnsubscribe, { safe: true });
179177

180178
const unwatchMap = new Map<(id: number) => void, number>();
181179

@@ -191,12 +189,12 @@ export function trackGeolocation(
191189
}
192190
}
193191

194-
boundSaveUnsubscribe(() => {
192+
return () => {
195193
for (const [unwatch, id] of unwatchMap) {
196194
unwatch(id);
197195
unwatchMap.delete(unwatch);
198196
}
199-
});
197+
};
200198
});
201199

202200
const unwatchPositionFx = attach({
@@ -207,7 +205,9 @@ export function trackGeolocation(
207205
});
208206

209207
sample({ clock: startWatching, target: watchPositionFx });
208+
sample({ clock: watchPositionFx.doneData, target: $unsubscribe });
210209
sample({ clock: stopWatching, target: unwatchPositionFx });
210+
sample({ clock: unwatchPositionFx.finally, target: $unsubscribe.reinit });
211211

212212
$watchingActive.on(startWatching, () => true).on(stopWatching, () => false);
213213

0 commit comments

Comments
 (0)