@tanstack/router-core 0.0.1-beta.196 → 0.0.1-beta.197
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.
|
@@ -43,13 +43,16 @@
|
|
|
43
43
|
};
|
|
44
44
|
function createHistory(opts) {
|
|
45
45
|
let location = opts.getLocation();
|
|
46
|
-
let unsub = () => {};
|
|
47
46
|
let subscribers = new Set();
|
|
48
47
|
let blockers = [];
|
|
49
48
|
let queue = [];
|
|
50
|
-
const
|
|
49
|
+
const onUpdate = () => {
|
|
50
|
+
location = opts.getLocation();
|
|
51
|
+
subscribers.forEach(subscriber => subscriber());
|
|
52
|
+
};
|
|
53
|
+
const tryUnblock = () => {
|
|
51
54
|
if (blockers.length) {
|
|
52
|
-
blockers[0]?.(
|
|
55
|
+
blockers[0]?.(tryUnblock, () => {
|
|
53
56
|
blockers = [];
|
|
54
57
|
stopBlocking();
|
|
55
58
|
});
|
|
@@ -58,32 +61,20 @@
|
|
|
58
61
|
while (queue.length) {
|
|
59
62
|
queue.shift()?.();
|
|
60
63
|
}
|
|
61
|
-
|
|
62
|
-
onUpdate();
|
|
63
|
-
}
|
|
64
|
+
onUpdate();
|
|
64
65
|
};
|
|
65
66
|
const queueTask = task => {
|
|
66
67
|
queue.push(task);
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
const onUpdate = () => {
|
|
70
|
-
location = opts.getLocation();
|
|
71
|
-
subscribers.forEach(subscriber => subscriber());
|
|
68
|
+
tryUnblock();
|
|
72
69
|
};
|
|
73
70
|
return {
|
|
74
71
|
get location() {
|
|
75
72
|
return location;
|
|
76
73
|
},
|
|
77
74
|
subscribe: cb => {
|
|
78
|
-
if (subscribers.size === 0) {
|
|
79
|
-
unsub = typeof opts.subscriber === 'function' ? opts.subscriber(onUpdate) : () => {};
|
|
80
|
-
}
|
|
81
75
|
subscribers.add(cb);
|
|
82
76
|
return () => {
|
|
83
77
|
subscribers.delete(cb);
|
|
84
|
-
if (subscribers.size === 0) {
|
|
85
|
-
unsub();
|
|
86
|
-
}
|
|
87
78
|
};
|
|
88
79
|
},
|
|
89
80
|
push: (path, state) => {
|
|
@@ -128,7 +119,9 @@
|
|
|
128
119
|
}
|
|
129
120
|
};
|
|
130
121
|
},
|
|
131
|
-
flush: () => opts.flush?.()
|
|
122
|
+
flush: () => opts.flush?.(),
|
|
123
|
+
destroy: () => opts.destroy?.(),
|
|
124
|
+
update: onUpdate
|
|
132
125
|
};
|
|
133
126
|
}
|
|
134
127
|
function assignKey(state) {
|
|
@@ -212,44 +205,43 @@
|
|
|
212
205
|
scheduled = Promise.resolve().then(() => flush());
|
|
213
206
|
}
|
|
214
207
|
};
|
|
215
|
-
|
|
208
|
+
const history = createHistory({
|
|
216
209
|
getLocation,
|
|
217
|
-
subscriber: onUpdate => {
|
|
218
|
-
window.addEventListener(pushStateEvent, () => {
|
|
219
|
-
currentLocation = parseLocation(getHref(), window.history.state);
|
|
220
|
-
onUpdate();
|
|
221
|
-
});
|
|
222
|
-
window.addEventListener(popStateEvent, () => {
|
|
223
|
-
currentLocation = parseLocation(getHref(), window.history.state);
|
|
224
|
-
onUpdate();
|
|
225
|
-
});
|
|
226
|
-
var pushState = window.history.pushState;
|
|
227
|
-
window.history.pushState = function () {
|
|
228
|
-
let res = pushState.apply(history, arguments);
|
|
229
|
-
if (tracking) onUpdate();
|
|
230
|
-
return res;
|
|
231
|
-
};
|
|
232
|
-
var replaceState = window.history.replaceState;
|
|
233
|
-
window.history.replaceState = function () {
|
|
234
|
-
let res = replaceState.apply(history, arguments);
|
|
235
|
-
if (tracking) onUpdate();
|
|
236
|
-
return res;
|
|
237
|
-
};
|
|
238
|
-
return () => {
|
|
239
|
-
window.history.pushState = pushState;
|
|
240
|
-
window.history.replaceState = replaceState;
|
|
241
|
-
window.removeEventListener(pushStateEvent, onUpdate);
|
|
242
|
-
window.removeEventListener(popStateEvent, onUpdate);
|
|
243
|
-
};
|
|
244
|
-
},
|
|
245
210
|
pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate),
|
|
246
211
|
replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate),
|
|
247
212
|
back: () => window.history.back(),
|
|
248
213
|
forward: () => window.history.forward(),
|
|
249
214
|
go: n => window.history.go(n),
|
|
250
215
|
createHref: path => createHref(path),
|
|
251
|
-
flush
|
|
216
|
+
flush,
|
|
217
|
+
destroy: () => {
|
|
218
|
+
window.history.pushState = pushState;
|
|
219
|
+
window.history.replaceState = replaceState;
|
|
220
|
+
window.removeEventListener(pushStateEvent, history.update);
|
|
221
|
+
window.removeEventListener(popStateEvent, history.update);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
window.addEventListener(pushStateEvent, () => {
|
|
225
|
+
currentLocation = parseLocation(getHref(), window.history.state);
|
|
226
|
+
history.update;
|
|
252
227
|
});
|
|
228
|
+
window.addEventListener(popStateEvent, () => {
|
|
229
|
+
currentLocation = parseLocation(getHref(), window.history.state);
|
|
230
|
+
history.update;
|
|
231
|
+
});
|
|
232
|
+
var pushState = window.history.pushState;
|
|
233
|
+
window.history.pushState = function () {
|
|
234
|
+
let res = pushState.apply(window.history, arguments);
|
|
235
|
+
if (tracking) history.update();
|
|
236
|
+
return res;
|
|
237
|
+
};
|
|
238
|
+
var replaceState = window.history.replaceState;
|
|
239
|
+
window.history.replaceState = function () {
|
|
240
|
+
let res = replaceState.apply(window.history, arguments);
|
|
241
|
+
if (tracking) history.update();
|
|
242
|
+
return res;
|
|
243
|
+
};
|
|
244
|
+
return history;
|
|
253
245
|
}
|
|
254
246
|
function createHashHistory() {
|
|
255
247
|
return createBrowserHistory({
|
|
@@ -268,7 +260,6 @@
|
|
|
268
260
|
const getLocation = () => parseLocation(entries[index], currentState);
|
|
269
261
|
return createHistory({
|
|
270
262
|
getLocation,
|
|
271
|
-
subscriber: false,
|
|
272
263
|
pushState: (path, state) => {
|
|
273
264
|
currentState = state;
|
|
274
265
|
entries.push(path);
|