@alfalab/bridge-to-native 1.3.2-beta.14525ab → 1.3.2-beta.16c7b6a
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.
|
@@ -148,28 +148,38 @@ class NativeNavigationAndTitleService {
|
|
|
148
148
|
initializeNativeHistoryStack() {
|
|
149
149
|
const { nextPageId, title } = this.nativeParamsService;
|
|
150
150
|
const hasSS = this.hasSavedHistoryStack();
|
|
151
|
-
console.log('
|
|
151
|
+
console.log('⬇️⬇️⬇️⬇️⬇️');
|
|
152
152
|
console.log('Инициализируюсь');
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
153
|
+
try {
|
|
154
|
+
if (nextPageId && !hasSS) {
|
|
155
|
+
console.log(`Есть nextPageId (${nextPageId}) + нет SS → на этом origin ранее не были.`);
|
|
156
|
+
this.nativeHistoryStack = this.initializeForNewOrigin(nextPageId, title);
|
|
157
|
+
}
|
|
158
|
+
else if (nextPageId && hasSS) {
|
|
159
|
+
const savedStack = this.readSavedHistoryStack();
|
|
160
|
+
if (savedStack.length > nextPageId) {
|
|
161
|
+
console.log(`Есть nextPageId (${nextPageId}) + есть SS длиннее nextPageId → back навигация.`);
|
|
162
|
+
this.nativeHistoryStack = this.initializeFromBackwardOrReload(title);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
console.log(`Есть nextPageId (${nextPageId}) + есть SS равный или короче nextPageId → forward навигация.`);
|
|
166
|
+
this.nativeHistoryStack = this.initializeForForward(nextPageId, title);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (!nextPageId && hasSS) {
|
|
170
|
+
console.log('Нет nextPageId + есть SS → back-навигация или reload.');
|
|
171
|
+
this.nativeHistoryStack = this.initializeFromBackwardOrReload(title);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.log('Нет nextPageId + нет SS → старт нового WV, назад идти некуда.');
|
|
175
|
+
this.nativeHistoryStack = [title];
|
|
176
|
+
}
|
|
167
177
|
}
|
|
168
|
-
|
|
169
|
-
// нет nextPageId + нет SS → старт нового WV, назад идти некуда.
|
|
170
|
-
console.log('нет nextPageId + нет SS → старт нового WV, назад идти некуда.');
|
|
178
|
+
catch (_a) {
|
|
171
179
|
this.nativeHistoryStack = [title];
|
|
172
180
|
}
|
|
181
|
+
console.log('this.nativeHistoryStack', '➡️', this.nativeHistoryStack);
|
|
182
|
+
console.log('⬆️⬆️⬆️⬆️⬆️');
|
|
173
183
|
this.saveNativeHistoryStack();
|
|
174
184
|
this.syncHistoryWithNative();
|
|
175
185
|
}
|
|
@@ -177,55 +187,36 @@ class NativeNavigationAndTitleService {
|
|
|
177
187
|
initializeForNewOrigin(nextPageId, title) {
|
|
178
188
|
const stack = new Array(nextPageId).fill(0 /* NativeHistoryStackSpecialValues.ServerSideNavigationStub */);
|
|
179
189
|
stack[stack.length - 1] = title;
|
|
180
|
-
console.log('nextPageId', nextPageId);
|
|
181
|
-
console.log('newStack', stack);
|
|
182
190
|
return stack;
|
|
183
191
|
}
|
|
184
192
|
initializeForForward(nextPageId, title) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
stack[i] = savedStack[i];
|
|
193
|
-
}
|
|
194
|
-
stack[stack.length - 1] = title;
|
|
195
|
-
console.log('nextPageId', nextPageId);
|
|
196
|
-
console.log('newStack', stack);
|
|
197
|
-
return stack;
|
|
198
|
-
}
|
|
199
|
-
if (savedStack.length === nextPageId) {
|
|
200
|
-
savedStack[savedStack.length - 1] = title;
|
|
201
|
-
console.log('nextPageId', nextPageId);
|
|
202
|
-
console.log('newStack', savedStack);
|
|
203
|
-
return savedStack;
|
|
193
|
+
const savedStack = this.readSavedHistoryStack();
|
|
194
|
+
const lastSaved = savedStack[savedStack.length - 1];
|
|
195
|
+
if (lastSaved === 2 /* NativeHistoryStackSpecialValues.ServerSideNavigationNextOrigin */ &&
|
|
196
|
+
savedStack.length < nextPageId) {
|
|
197
|
+
const stack = new Array(nextPageId).fill(0 /* NativeHistoryStackSpecialValues.ServerSideNavigationStub */);
|
|
198
|
+
for (let i = 0; i < savedStack.length; i++) {
|
|
199
|
+
stack[i] = savedStack[i];
|
|
204
200
|
}
|
|
205
|
-
|
|
201
|
+
stack[stack.length - 1] = title;
|
|
202
|
+
return stack;
|
|
206
203
|
}
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
if (savedStack.length === nextPageId) {
|
|
205
|
+
savedStack[savedStack.length - 1] = title;
|
|
206
|
+
return savedStack;
|
|
209
207
|
}
|
|
208
|
+
return this.initializeForNewOrigin(nextPageId, title);
|
|
210
209
|
}
|
|
211
210
|
initializeFromBackwardOrReload(title) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (savedStack.length === 0) {
|
|
216
|
-
console.log('newStack', [title]);
|
|
217
|
-
return [title];
|
|
218
|
-
}
|
|
219
|
-
if (typeof savedStack[savedStack.length - 1] !== 'string') {
|
|
220
|
-
console.log('newStack', this.truncateToLastCrossOriginMarker(savedStack));
|
|
221
|
-
return this.truncateToLastCrossOriginMarker(savedStack);
|
|
222
|
-
}
|
|
223
|
-
console.log('newStack', savedStack);
|
|
224
|
-
return savedStack;
|
|
225
|
-
}
|
|
226
|
-
catch (_a) {
|
|
211
|
+
const savedStack = this.readSavedHistoryStack();
|
|
212
|
+
savedStack.pop();
|
|
213
|
+
if (savedStack.length === 0) {
|
|
227
214
|
return [title];
|
|
228
215
|
}
|
|
216
|
+
if (typeof savedStack[savedStack.length - 1] !== 'string') {
|
|
217
|
+
return this.truncateToLastCrossOriginMarker(savedStack);
|
|
218
|
+
}
|
|
219
|
+
return savedStack;
|
|
229
220
|
}
|
|
230
221
|
// eslint-disable-next-line class-methods-use-this -- удобней использовать метод в контексте экземпляра.
|
|
231
222
|
stackContainsCrossOriginMarker(stack) {
|
|
@@ -246,11 +237,14 @@ class NativeNavigationAndTitleService {
|
|
|
246
237
|
*/
|
|
247
238
|
readSavedHistoryStack() {
|
|
248
239
|
const serialized = sessionStorage.getItem(query_and_headers_keys_1.SS_KEY_BRIDGE_TO_NATIVE_HISTORY_STACK);
|
|
240
|
+
console.log('⬇️⬇️⬇️⬇️⬇️');
|
|
241
|
+
console.log('Читаю стек из SessionStorage');
|
|
242
|
+
console.log('SessionStorage', '➡️', serialized);
|
|
243
|
+
console.log('⬆️⬆️⬆️⬆️⬆️');
|
|
249
244
|
try {
|
|
250
245
|
if (!serialized) {
|
|
251
246
|
throw new Error(`${query_and_headers_keys_1.SS_KEY_BRIDGE_TO_NATIVE_HISTORY_STACK} sessionStorage expected not to be null`);
|
|
252
247
|
}
|
|
253
|
-
console.log('serializedStack', serialized);
|
|
254
248
|
return JSON.parse(serialized);
|
|
255
249
|
}
|
|
256
250
|
catch (e) {
|
|
@@ -290,10 +284,10 @@ class NativeNavigationAndTitleService {
|
|
|
290
284
|
*/
|
|
291
285
|
saveNativeHistoryStack() {
|
|
292
286
|
const serializedNativeHistoryStack = JSON.stringify(this.nativeHistoryStack);
|
|
293
|
-
console.log('
|
|
294
|
-
console.log('
|
|
295
|
-
console.log('
|
|
296
|
-
console.log('
|
|
287
|
+
console.log('⬇️⬇️⬇️⬇️⬇️');
|
|
288
|
+
console.log('Сохраняю стек в SessionStorage');
|
|
289
|
+
console.log(this.nativeHistoryStack, '➡️', serializedNativeHistoryStack);
|
|
290
|
+
console.log('⬆️⬆️⬆️⬆️⬆️');
|
|
297
291
|
sessionStorage.setItem(query_and_headers_keys_1.SS_KEY_BRIDGE_TO_NATIVE_HISTORY_STACK, serializedNativeHistoryStack);
|
|
298
292
|
}
|
|
299
293
|
/**
|
package/package.json
CHANGED