@@ -169,13 +169,11 @@ export function trackGeolocation(
169
169
170
170
// -- watch position
171
171
172
- const saveUnsubscribe = createEvent < Unsubscribe > ( ) ;
173
- const $unsubscribe = restore ( saveUnsubscribe , null ) ;
172
+ const $unsubscribe = createStore < Unsubscribe | null > ( null ) ;
174
173
175
174
const watchPositionFx = createEffect ( ( ) => {
176
175
const boundNewPosition = scopeBind ( newPosition , { safe : true } ) ;
177
176
const boundFailed = scopeBind ( failed , { safe : true } ) ;
178
- const boundSaveUnsubscribe = scopeBind ( saveUnsubscribe , { safe : true } ) ;
179
177
180
178
const unwatchMap = new Map < ( id : number ) => void , number > ( ) ;
181
179
@@ -191,12 +189,12 @@ export function trackGeolocation(
191
189
}
192
190
}
193
191
194
- boundSaveUnsubscribe ( ( ) => {
192
+ return ( ) => {
195
193
for ( const [ unwatch , id ] of unwatchMap ) {
196
194
unwatch ( id ) ;
197
195
unwatchMap . delete ( unwatch ) ;
198
196
}
199
- } ) ;
197
+ } ;
200
198
} ) ;
201
199
202
200
const unwatchPositionFx = attach ( {
@@ -207,7 +205,9 @@ export function trackGeolocation(
207
205
} ) ;
208
206
209
207
sample ( { clock : startWatching , target : watchPositionFx } ) ;
208
+ sample ( { clock : watchPositionFx . doneData , target : $unsubscribe } ) ;
210
209
sample ( { clock : stopWatching , target : unwatchPositionFx } ) ;
210
+ sample ( { clock : unwatchPositionFx . finally , target : $unsubscribe . reinit } ) ;
211
211
212
212
$watchingActive . on ( startWatching , ( ) => true ) . on ( stopWatching , ( ) => false ) ;
213
213
0 commit comments