@flemo/core 1.10.0 → 1.10.1

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.
@@ -16,6 +16,7 @@ export interface HistoryStore {
16
16
  popHistory: (index: number) => void;
17
17
  popHistories: (count: number) => void;
18
18
  setPendingIndex: (index: number) => void;
19
+ adoptHistory: (history: History) => void;
19
20
  setTransitionName: (index: number, transitionName: TransitionName) => void;
20
21
  }
21
22
  export type HistoryStoreApi = StoreApi<HistoryStore>;
package/dist/index.mjs CHANGED
@@ -206,6 +206,7 @@ function o(t = [], n = -1) {
206
206
  });
207
207
  },
208
208
  setPendingIndex: (t) => e({ pendingIndex: t }),
209
+ adoptHistory: (t) => e((e) => ({ histories: e.histories.slice(0, e.index).concat(t) })),
209
210
  setTransitionName: (t, n) => e((e) => {
210
211
  let r = e.histories[t];
211
212
  if (!r || r.transitionName === n) return {};
@@ -330,20 +331,30 @@ function _() {
330
331
  //#endregion
331
332
  //#region src/history/createHistorySync.ts
332
333
  function v(e) {
333
- let { stores: t, driver: n = p(), consume: r = _ } = e;
334
- return n.subscribe(async (e) => {
335
- if (r()) return;
336
- let n = e.state, i = a.generateTaskId();
334
+ let { stores: t, driver: n = p(), consume: r = _ } = e, i = !1, o = n.subscribe(async (e) => {
335
+ if (i || r()) return;
336
+ let n = e.state, o = a.generateTaskId();
337
337
  (await a.addTask(async (r) => {
338
- let { setStatus: a, setTransitionTaskId: o } = t.navigate.getState(), { index: s, addHistory: c, popHistory: l, setPendingIndex: u } = t.history.getState(), d = n?.index, f = d !== void 0 && d < s, p = n?.status === "PUSHING" && d !== void 0 && d > s, m = n?.status === "REPLACING" && d !== void 0 && d > s;
339
- if (!f && !p && !m) {
338
+ if (i) {
340
339
  r.abort();
341
340
  return;
342
341
  }
343
- if (o(i), f) u(d), a("POPPING");
342
+ let { setStatus: a, setTransitionTaskId: s } = t.navigate.getState(), { index: c, addHistory: l, popHistory: u, setPendingIndex: d } = t.history.getState(), f = n?.index, p = f !== void 0 && f < c, m = n?.status === "PUSHING" && f !== void 0 && f > c, h = n?.status === "REPLACING" && f !== void 0 && f > c;
343
+ if (!p && !m && !h) {
344
+ let i = t.history.getState().histories[c];
345
+ n?.id && i && n.id !== i.id && t.history.getState().adoptHistory({
346
+ id: n.id,
347
+ pathname: e.pathname,
348
+ params: n.params,
349
+ transitionName: n.transitionName,
350
+ layoutId: n.layoutId
351
+ }), r.abort();
352
+ return;
353
+ }
354
+ if (s(o), p) d(f), a("POPPING");
344
355
  else {
345
356
  let t = n;
346
- a(p ? "PUSHING" : "REPLACING"), c({
357
+ a(m ? "PUSHING" : "REPLACING"), l({
347
358
  id: t.id,
348
359
  pathname: e.pathname,
349
360
  params: t.params,
@@ -352,13 +363,16 @@ function v(e) {
352
363
  });
353
364
  }
354
365
  return async () => {
355
- f && d !== void 0 && l(d + 1), a("COMPLETED");
366
+ p && f !== void 0 && u(f + 1), a("COMPLETED");
356
367
  };
357
368
  }, {
358
- id: i,
369
+ id: o,
359
370
  control: { manual: !0 }
360
371
  })).result?.();
361
372
  });
373
+ return () => {
374
+ i = !0, o();
375
+ };
362
376
  }
363
377
  //#endregion
364
378
  //#region src/history/memoryHistoryDriver.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemo/core",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "Framework-agnostic primitives for flemo: history, navigation, transitions, task manager.",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",