@tanstack/react-router 0.0.1-beta.196 → 0.0.1-beta.198
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.
|
@@ -163,13 +163,16 @@
|
|
|
163
163
|
};
|
|
164
164
|
function createHistory(opts) {
|
|
165
165
|
let location = opts.getLocation();
|
|
166
|
-
let unsub = () => {};
|
|
167
166
|
let subscribers = new Set();
|
|
168
167
|
let blockers = [];
|
|
169
168
|
let queue = [];
|
|
170
|
-
const
|
|
169
|
+
const onUpdate = () => {
|
|
170
|
+
location = opts.getLocation();
|
|
171
|
+
subscribers.forEach(subscriber => subscriber());
|
|
172
|
+
};
|
|
173
|
+
const tryUnblock = () => {
|
|
171
174
|
if (blockers.length) {
|
|
172
|
-
blockers[0]?.(
|
|
175
|
+
blockers[0]?.(tryUnblock, () => {
|
|
173
176
|
blockers = [];
|
|
174
177
|
stopBlocking();
|
|
175
178
|
});
|
|
@@ -178,32 +181,20 @@
|
|
|
178
181
|
while (queue.length) {
|
|
179
182
|
queue.shift()?.();
|
|
180
183
|
}
|
|
181
|
-
|
|
182
|
-
onUpdate();
|
|
183
|
-
}
|
|
184
|
+
onUpdate();
|
|
184
185
|
};
|
|
185
186
|
const queueTask = task => {
|
|
186
187
|
queue.push(task);
|
|
187
|
-
|
|
188
|
-
};
|
|
189
|
-
const onUpdate = () => {
|
|
190
|
-
location = opts.getLocation();
|
|
191
|
-
subscribers.forEach(subscriber => subscriber());
|
|
188
|
+
tryUnblock();
|
|
192
189
|
};
|
|
193
190
|
return {
|
|
194
191
|
get location() {
|
|
195
192
|
return location;
|
|
196
193
|
},
|
|
197
194
|
subscribe: cb => {
|
|
198
|
-
if (subscribers.size === 0) {
|
|
199
|
-
unsub = typeof opts.subscriber === 'function' ? opts.subscriber(onUpdate) : () => {};
|
|
200
|
-
}
|
|
201
195
|
subscribers.add(cb);
|
|
202
196
|
return () => {
|
|
203
197
|
subscribers.delete(cb);
|
|
204
|
-
if (subscribers.size === 0) {
|
|
205
|
-
unsub();
|
|
206
|
-
}
|
|
207
198
|
};
|
|
208
199
|
},
|
|
209
200
|
push: (path, state) => {
|
|
@@ -248,7 +239,9 @@
|
|
|
248
239
|
}
|
|
249
240
|
};
|
|
250
241
|
},
|
|
251
|
-
flush: () => opts.flush?.()
|
|
242
|
+
flush: () => opts.flush?.(),
|
|
243
|
+
destroy: () => opts.destroy?.(),
|
|
244
|
+
update: onUpdate
|
|
252
245
|
};
|
|
253
246
|
}
|
|
254
247
|
function assignKey(state) {
|
|
@@ -332,44 +325,43 @@
|
|
|
332
325
|
scheduled = Promise.resolve().then(() => flush());
|
|
333
326
|
}
|
|
334
327
|
};
|
|
335
|
-
|
|
328
|
+
const history = createHistory({
|
|
336
329
|
getLocation,
|
|
337
|
-
subscriber: onUpdate => {
|
|
338
|
-
window.addEventListener(pushStateEvent, () => {
|
|
339
|
-
currentLocation = parseLocation(getHref(), window.history.state);
|
|
340
|
-
onUpdate();
|
|
341
|
-
});
|
|
342
|
-
window.addEventListener(popStateEvent, () => {
|
|
343
|
-
currentLocation = parseLocation(getHref(), window.history.state);
|
|
344
|
-
onUpdate();
|
|
345
|
-
});
|
|
346
|
-
var pushState = window.history.pushState;
|
|
347
|
-
window.history.pushState = function () {
|
|
348
|
-
let res = pushState.apply(history, arguments);
|
|
349
|
-
if (tracking) onUpdate();
|
|
350
|
-
return res;
|
|
351
|
-
};
|
|
352
|
-
var replaceState = window.history.replaceState;
|
|
353
|
-
window.history.replaceState = function () {
|
|
354
|
-
let res = replaceState.apply(history, arguments);
|
|
355
|
-
if (tracking) onUpdate();
|
|
356
|
-
return res;
|
|
357
|
-
};
|
|
358
|
-
return () => {
|
|
359
|
-
window.history.pushState = pushState;
|
|
360
|
-
window.history.replaceState = replaceState;
|
|
361
|
-
window.removeEventListener(pushStateEvent, onUpdate);
|
|
362
|
-
window.removeEventListener(popStateEvent, onUpdate);
|
|
363
|
-
};
|
|
364
|
-
},
|
|
365
330
|
pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate),
|
|
366
331
|
replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate),
|
|
367
332
|
back: () => window.history.back(),
|
|
368
333
|
forward: () => window.history.forward(),
|
|
369
334
|
go: n => window.history.go(n),
|
|
370
335
|
createHref: path => createHref(path),
|
|
371
|
-
flush
|
|
336
|
+
flush,
|
|
337
|
+
destroy: () => {
|
|
338
|
+
window.history.pushState = pushState;
|
|
339
|
+
window.history.replaceState = replaceState;
|
|
340
|
+
window.removeEventListener(pushStateEvent, history.update);
|
|
341
|
+
window.removeEventListener(popStateEvent, history.update);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
window.addEventListener(pushStateEvent, () => {
|
|
345
|
+
currentLocation = parseLocation(getHref(), window.history.state);
|
|
346
|
+
history.update;
|
|
372
347
|
});
|
|
348
|
+
window.addEventListener(popStateEvent, () => {
|
|
349
|
+
currentLocation = parseLocation(getHref(), window.history.state);
|
|
350
|
+
history.update;
|
|
351
|
+
});
|
|
352
|
+
var pushState = window.history.pushState;
|
|
353
|
+
window.history.pushState = function () {
|
|
354
|
+
let res = pushState.apply(window.history, arguments);
|
|
355
|
+
if (tracking) history.update();
|
|
356
|
+
return res;
|
|
357
|
+
};
|
|
358
|
+
var replaceState = window.history.replaceState;
|
|
359
|
+
window.history.replaceState = function () {
|
|
360
|
+
let res = replaceState.apply(window.history, arguments);
|
|
361
|
+
if (tracking) history.update();
|
|
362
|
+
return res;
|
|
363
|
+
};
|
|
364
|
+
return history;
|
|
373
365
|
}
|
|
374
366
|
function createHashHistory() {
|
|
375
367
|
return createBrowserHistory({
|
|
@@ -388,7 +380,6 @@
|
|
|
388
380
|
const getLocation = () => parseLocation(entries[index], currentState);
|
|
389
381
|
return createHistory({
|
|
390
382
|
getLocation,
|
|
391
|
-
subscriber: false,
|
|
392
383
|
pushState: (path, state) => {
|
|
393
384
|
currentState = state;
|
|
394
385
|
entries.push(path);
|