@typed/navigation 0.13.5 → 0.14.0
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.
- package/dist/cjs/Blocking.js +8 -8
- package/dist/cjs/Blocking.js.map +1 -1
- package/dist/cjs/Layer.js +1 -1
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/Navigation.js +66 -57
- package/dist/cjs/Navigation.js.map +1 -1
- package/dist/cjs/internal/fromWindow.js +32 -32
- package/dist/cjs/internal/fromWindow.js.map +1 -1
- package/dist/cjs/internal/memory.js +18 -20
- package/dist/cjs/internal/memory.js.map +1 -1
- package/dist/cjs/internal/shared.js +88 -88
- package/dist/cjs/internal/shared.js.map +1 -1
- package/dist/dts/Blocking.d.ts +1 -1
- package/dist/dts/Blocking.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +2 -1
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/Navigation.d.ts +122 -199
- package/dist/dts/Navigation.d.ts.map +1 -1
- package/dist/dts/internal/fromWindow.d.ts +1 -1
- package/dist/dts/internal/fromWindow.d.ts.map +1 -1
- package/dist/dts/internal/memory.d.ts +1 -1
- package/dist/dts/internal/memory.d.ts.map +1 -1
- package/dist/dts/internal/shared.d.ts +34 -68
- package/dist/dts/internal/shared.d.ts.map +1 -1
- package/dist/esm/Blocking.js +7 -7
- package/dist/esm/Blocking.js.map +1 -1
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/Navigation.js +55 -46
- package/dist/esm/Navigation.js.map +1 -1
- package/dist/esm/internal/fromWindow.js +25 -25
- package/dist/esm/internal/fromWindow.js.map +1 -1
- package/dist/esm/internal/memory.js +15 -17
- package/dist/esm/internal/memory.js.map +1 -1
- package/dist/esm/internal/shared.js +76 -76
- package/dist/esm/internal/shared.js.map +1 -1
- package/package.json +8 -8
- package/src/Blocking.ts +21 -23
- package/src/Layer.ts +2 -1
- package/src/Navigation.ts +81 -75
- package/src/internal/fromWindow.ts +44 -47
- package/src/internal/memory.ts +17 -23
- package/src/internal/shared.ts +82 -91
|
@@ -14,10 +14,10 @@ var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/
|
|
|
14
14
|
var _Navigation = /*#__PURE__*/require("../Navigation.js");
|
|
15
15
|
var _shared = /*#__PURE__*/require("./shared.js");
|
|
16
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
18
|
-
const memory = options => _Navigation.Navigation.scoped(Effect.gen(function* (
|
|
19
|
-
const getRandomValues = yield*
|
|
20
|
-
const modelAndIntent = yield*
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
const memory = options => _Navigation.Navigation.scoped(Effect.gen(function* () {
|
|
19
|
+
const getRandomValues = yield* _id.GetRandomValues;
|
|
20
|
+
const modelAndIntent = yield* setupMemory(options);
|
|
21
21
|
const current = options.entries[options.currentIndex ?? 0];
|
|
22
22
|
const origin = options.origin ?? (0, _shared.getOriginFromUrl)(current.url);
|
|
23
23
|
const base = options.base ?? "/";
|
|
@@ -25,11 +25,11 @@ const memory = options => _Navigation.Navigation.scoped(Effect.gen(function* (_)
|
|
|
25
25
|
}).pipe(Effect.provide(_id.getRandomValues)));
|
|
26
26
|
exports.memory = memory;
|
|
27
27
|
function initialMemory(options) {
|
|
28
|
-
return _Navigation.Navigation.scoped(Effect.gen(function* (
|
|
29
|
-
const getRandomValues = yield*
|
|
28
|
+
return _Navigation.Navigation.scoped(Effect.gen(function* () {
|
|
29
|
+
const getRandomValues = yield* _id.GetRandomValues;
|
|
30
30
|
const origin = options.origin ?? (0, _shared.getOriginFromUrl)(options.url);
|
|
31
31
|
const base = options.base ?? "/";
|
|
32
|
-
const destination = yield*
|
|
32
|
+
const destination = yield* (0, _shared.makeDestination)((0, _shared.getUrl)(origin, options.url), options.state, origin);
|
|
33
33
|
const memoryOptions = {
|
|
34
34
|
entries: [destination],
|
|
35
35
|
origin,
|
|
@@ -37,29 +37,27 @@ function initialMemory(options) {
|
|
|
37
37
|
currentIndex: 0,
|
|
38
38
|
maxEntries: options.maxEntries
|
|
39
39
|
};
|
|
40
|
-
const modelAndIntent = yield*
|
|
40
|
+
const modelAndIntent = yield* setupMemory(memoryOptions);
|
|
41
41
|
return (0, _shared.setupFromModelAndIntent)(modelAndIntent, origin, base, getRandomValues);
|
|
42
42
|
}).pipe(Effect.provide(_id.getRandomValues)));
|
|
43
43
|
}
|
|
44
44
|
function setupMemory(options) {
|
|
45
|
-
return Effect.gen(function* (
|
|
46
|
-
const state = yield*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
53
|
-
eq: Equivalence.make(_schema.Schema.to(_shared.NavigationState))
|
|
54
|
-
}));
|
|
45
|
+
return Effect.gen(function* () {
|
|
46
|
+
const state = yield* RefSubject.of({
|
|
47
|
+
entries: options.entries,
|
|
48
|
+
index: options.currentIndex ?? options.entries.length - 1,
|
|
49
|
+
transition: Option.none()
|
|
50
|
+
}, {
|
|
51
|
+
eq: Equivalence.make(_schema.Schema.typeSchema(_shared.NavigationState))
|
|
52
|
+
});
|
|
55
53
|
const canGoBack = RefSubject.map(state, s => s.index > 0);
|
|
56
54
|
const canGoForward = RefSubject.map(state, s => s.index < s.entries.length - 1);
|
|
57
55
|
const {
|
|
58
56
|
beforeHandlers,
|
|
59
57
|
formDataHandlers,
|
|
60
58
|
handlers
|
|
61
|
-
} = yield*
|
|
62
|
-
const commit = options.commit ?? (() => Effect.
|
|
59
|
+
} = yield* (0, _shared.makeHandlersState)();
|
|
60
|
+
const commit = options.commit ?? (() => Effect.void);
|
|
63
61
|
return {
|
|
64
62
|
state,
|
|
65
63
|
canGoBack,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","names":["_schema","require","Equivalence","_interopRequireWildcard","RefSubject","_id","Effect","Option","_Navigation","_shared","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","
|
|
1
|
+
{"version":3,"file":"memory.js","names":["_schema","require","Equivalence","_interopRequireWildcard","RefSubject","_id","Effect","Option","_Navigation","_shared","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","memory","options","Navigation","scoped","gen","getRandomValues","GetRandomValues","modelAndIntent","setupMemory","current","entries","currentIndex","origin","getOriginFromUrl","url","base","setupFromModelAndIntent","pipe","provide","exports","initialMemory","destination","makeDestination","getUrl","state","memoryOptions","maxEntries","of","index","length","transition","none","eq","make","Schema","typeSchema","NavigationState","canGoBack","map","s","canGoForward","beforeHandlers","formDataHandlers","handlers","makeHandlersState","commit","void"],"sources":["../../../src/internal/memory.ts"],"sourcesContent":[null],"mappings":";;;;;;;AAAA,IAAAA,OAAA,gBAAAC,OAAA;AACA,IAAAC,WAAA,gBAAAC,uBAAA,eAAAF,OAAA;AACA,IAAAG,UAAA,gBAAAD,uBAAA,eAAAF,OAAA;AACA,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AAK;MACLa,SAAS;MACTG,YAAY;MACZC,cAAc;MACdE,QAAQ;MACRD,gBAAgB;MAChBG;KACQ;EACZ,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -24,11 +24,11 @@ var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/
|
|
|
24
24
|
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option"));
|
|
25
25
|
var _Navigation = /*#__PURE__*/require("../Navigation.js");
|
|
26
26
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
27
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u &&
|
|
28
|
-
const NavigationState = exports.NavigationState = /*#__PURE__*/_schema.Schema.
|
|
29
|
-
entries: /*#__PURE__*/_schema.Schema.
|
|
30
|
-
index: _schema.Schema.
|
|
31
|
-
transition: /*#__PURE__*/_schema.Schema.
|
|
27
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
28
|
+
const NavigationState = exports.NavigationState = /*#__PURE__*/_schema.Schema.Struct({
|
|
29
|
+
entries: /*#__PURE__*/_schema.Schema.Array(_Navigation.Destination),
|
|
30
|
+
index: _schema.Schema.Number,
|
|
31
|
+
transition: /*#__PURE__*/_schema.Schema.OptionFromNullishOr(_Navigation.Transition, null)
|
|
32
32
|
});
|
|
33
33
|
const getUrl = (origin, urlOrPath) => {
|
|
34
34
|
return typeof urlOrPath === "string" ? new URL(urlOrPath, origin) : urlOrPath;
|
|
@@ -48,11 +48,11 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
48
48
|
const entries = RefSubject.map(state, s => s.entries);
|
|
49
49
|
const currentEntry = RefSubject.map(state, s => s.entries[s.index]);
|
|
50
50
|
const transition = RefSubject.map(state, s => s.transition);
|
|
51
|
-
const runBeforeHandlers = event => Effect.gen(function* (
|
|
52
|
-
const handlers = yield*
|
|
51
|
+
const runBeforeHandlers = event => Effect.gen(function* () {
|
|
52
|
+
const handlers = yield* beforeHandlers;
|
|
53
53
|
const matches = [];
|
|
54
54
|
for (const [handler, ctx] of handlers) {
|
|
55
|
-
const exit = yield*
|
|
55
|
+
const exit = yield* handler(event).pipe(Effect.provide(ctx), Effect.either);
|
|
56
56
|
if (Either.isRight(exit)) {
|
|
57
57
|
const match = exit.right;
|
|
58
58
|
if (Option.isSome(match)) {
|
|
@@ -64,7 +64,7 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
64
64
|
}
|
|
65
65
|
if (matches.length > 0) {
|
|
66
66
|
for (const match of matches) {
|
|
67
|
-
const exit = yield*
|
|
67
|
+
const exit = yield* Effect.either(match);
|
|
68
68
|
if (Either.isLeft(exit)) {
|
|
69
69
|
return Option.some(exit.left);
|
|
70
70
|
}
|
|
@@ -72,26 +72,26 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
72
72
|
}
|
|
73
73
|
return Option.none();
|
|
74
74
|
});
|
|
75
|
-
const runHandlers = event => Effect.gen(function* (
|
|
76
|
-
const eventHandlers = yield*
|
|
75
|
+
const runHandlers = event => Effect.gen(function* () {
|
|
76
|
+
const eventHandlers = yield* handlers;
|
|
77
77
|
const matches = [];
|
|
78
78
|
for (const [handler, ctx] of eventHandlers) {
|
|
79
|
-
const match = yield*
|
|
79
|
+
const match = yield* Effect.provide(handler(event), ctx);
|
|
80
80
|
if (Option.isSome(match)) {
|
|
81
81
|
matches.push(Effect.provide(match.value, ctx));
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if (matches.length > 0) {
|
|
85
|
-
yield*
|
|
85
|
+
yield* Effect.all(matches, {
|
|
86
86
|
discard: true
|
|
87
|
-
})
|
|
87
|
+
});
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
|
-
const runFormDataHandlers = event => Effect.gen(function* (
|
|
91
|
-
const handlers = yield*
|
|
90
|
+
const runFormDataHandlers = event => Effect.gen(function* () {
|
|
91
|
+
const handlers = yield* formDataHandlers;
|
|
92
92
|
const matches = [];
|
|
93
93
|
for (const [handler, ctx] of handlers) {
|
|
94
|
-
const exit = yield*
|
|
94
|
+
const exit = yield* handler(event).pipe(Effect.provide(ctx), Effect.either);
|
|
95
95
|
if (Either.isRight(exit)) {
|
|
96
96
|
const match = exit.right;
|
|
97
97
|
if (Option.isSome(match)) {
|
|
@@ -103,7 +103,7 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
103
103
|
}
|
|
104
104
|
if (matches.length > 0) {
|
|
105
105
|
for (const match of matches) {
|
|
106
|
-
const exit = yield*
|
|
106
|
+
const exit = yield* Effect.either(match);
|
|
107
107
|
if (Either.isLeft(exit)) {
|
|
108
108
|
return Either.left(exit.left);
|
|
109
109
|
} else if (Option.isSome(exit.right)) {
|
|
@@ -112,32 +112,32 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
112
112
|
}
|
|
113
113
|
} else {
|
|
114
114
|
// Only if there are 0 matches, we'll make a request to the server ourselves
|
|
115
|
-
const response = yield*
|
|
115
|
+
const response = yield* makeFormDataRequest(event, Option.getOrElse(event.action, () => event.from.url.href));
|
|
116
116
|
return Either.right(Option.some(response));
|
|
117
117
|
}
|
|
118
118
|
return Either.right(Option.none());
|
|
119
119
|
});
|
|
120
|
-
const runNavigationEvent = (beforeEvent, get, set, depth, skipCommit = false) => Effect.gen(function* (
|
|
121
|
-
let current = yield*
|
|
122
|
-
current = yield*
|
|
120
|
+
const runNavigationEvent = (beforeEvent, get, set, depth, skipCommit = false) => Effect.gen(function* () {
|
|
121
|
+
let current = yield* get;
|
|
122
|
+
current = yield* set({
|
|
123
123
|
...current,
|
|
124
124
|
transition: Option.some(beforeEvent)
|
|
125
|
-
})
|
|
125
|
+
});
|
|
126
126
|
if (!skipCommit) {
|
|
127
|
-
const beforeError = yield*
|
|
127
|
+
const beforeError = yield* runBeforeHandlers(beforeEvent);
|
|
128
128
|
if (Option.isSome(beforeError)) {
|
|
129
|
-
return yield*
|
|
129
|
+
return yield* handleError(beforeError.value, get, set, depth);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
const to = isDestination(beforeEvent.to) ? beforeEvent.to : yield*
|
|
132
|
+
const to = isDestination(beforeEvent.to) ? beforeEvent.to : yield* upgradeProposedDestination(beforeEvent.to);
|
|
133
133
|
if (!skipCommit) {
|
|
134
|
-
yield*
|
|
134
|
+
yield* commit(to, beforeEvent);
|
|
135
135
|
}
|
|
136
136
|
if (newNavigationState) {
|
|
137
137
|
const {
|
|
138
138
|
entries,
|
|
139
139
|
index
|
|
140
|
-
} = yield*
|
|
140
|
+
} = yield* set(newNavigationState());
|
|
141
141
|
return entries[index];
|
|
142
142
|
} else {
|
|
143
143
|
const event = {
|
|
@@ -148,70 +148,70 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
148
148
|
if (beforeEvent.type === "push") {
|
|
149
149
|
const index = current.index + 1;
|
|
150
150
|
const entries = current.entries.slice(0, index).concat([to]);
|
|
151
|
-
yield*
|
|
151
|
+
yield* set({
|
|
152
152
|
entries,
|
|
153
153
|
index,
|
|
154
154
|
transition: Option.none()
|
|
155
|
-
})
|
|
155
|
+
});
|
|
156
156
|
} else if (beforeEvent.type === "replace") {
|
|
157
157
|
const index = current.index;
|
|
158
158
|
const before = current.entries.slice(0, index);
|
|
159
159
|
const after = current.entries.slice(index + 1);
|
|
160
160
|
const entries = [...before, to, ...after];
|
|
161
|
-
yield*
|
|
161
|
+
yield* set({
|
|
162
162
|
entries,
|
|
163
163
|
index,
|
|
164
164
|
transition: Option.none()
|
|
165
|
-
})
|
|
165
|
+
});
|
|
166
166
|
} else if (beforeEvent.type === "reload") {
|
|
167
|
-
yield*
|
|
167
|
+
yield* set({
|
|
168
168
|
...current,
|
|
169
169
|
transition: Option.none()
|
|
170
|
-
})
|
|
170
|
+
});
|
|
171
171
|
} else {
|
|
172
172
|
const {
|
|
173
173
|
delta
|
|
174
174
|
} = beforeEvent;
|
|
175
175
|
const nextIndex = current.index + delta;
|
|
176
|
-
yield*
|
|
176
|
+
yield* set({
|
|
177
177
|
...current,
|
|
178
178
|
index: nextIndex,
|
|
179
179
|
transition: Option.none()
|
|
180
|
-
})
|
|
180
|
+
});
|
|
181
181
|
}
|
|
182
|
-
yield*
|
|
182
|
+
yield* runHandlers(event);
|
|
183
183
|
}
|
|
184
184
|
return to;
|
|
185
185
|
}).pipe(_id.GetRandomValues.provide(getRandomValues));
|
|
186
|
-
const handleError = (error, get, set, depth) => Effect.gen(function* (
|
|
186
|
+
const handleError = (error, get, set, depth) => Effect.gen(function* () {
|
|
187
187
|
if (depth >= 25) {
|
|
188
|
-
return yield*
|
|
188
|
+
return yield* Effect.dieMessage(`Redirect loop detected.`);
|
|
189
189
|
}
|
|
190
190
|
const {
|
|
191
191
|
entries,
|
|
192
192
|
index
|
|
193
|
-
} = yield*
|
|
193
|
+
} = yield* get;
|
|
194
194
|
const from = entries[index];
|
|
195
195
|
if (error._tag === "CancelNavigation") {
|
|
196
|
-
yield*
|
|
196
|
+
yield* set({
|
|
197
197
|
entries,
|
|
198
198
|
index,
|
|
199
199
|
transition: Option.none()
|
|
200
|
-
})
|
|
200
|
+
});
|
|
201
201
|
return from;
|
|
202
202
|
} else {
|
|
203
|
-
const event = yield*
|
|
204
|
-
return yield*
|
|
203
|
+
const event = yield* makeRedirectEvent(origin, error, from);
|
|
204
|
+
return yield* runNavigationEvent(event, get, set, depth + 1);
|
|
205
205
|
}
|
|
206
206
|
}).pipe(_id.GetRandomValues.provide(getRandomValues));
|
|
207
207
|
const navigate = (pathOrUrl, options, skipCommit = false) => state.runUpdates(({
|
|
208
208
|
get,
|
|
209
209
|
set
|
|
210
|
-
}) => Effect.gen(function* (
|
|
211
|
-
const state = yield*
|
|
210
|
+
}) => Effect.gen(function* () {
|
|
211
|
+
const state = yield* get;
|
|
212
212
|
const from = state.entries[state.index];
|
|
213
213
|
const history = options?.history ?? "auto";
|
|
214
|
-
const to = yield*
|
|
214
|
+
const to = yield* makeOrUpdateDestination(state, getUrl(origin, pathOrUrl), options?.state, origin).pipe(_id.GetRandomValues.provide(getRandomValues));
|
|
215
215
|
const type = history === "auto" ? from.key === to.key ? "replace" : "push" : history;
|
|
216
216
|
const event = {
|
|
217
217
|
type,
|
|
@@ -220,13 +220,13 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
220
220
|
delta: type === "replace" ? 0 : 1,
|
|
221
221
|
info: options?.info
|
|
222
222
|
};
|
|
223
|
-
return yield*
|
|
223
|
+
return yield* runNavigationEvent(event, get, set, 0, skipCommit);
|
|
224
224
|
}));
|
|
225
225
|
const traverseTo = (key, options, skipCommit = false) => state.runUpdates(({
|
|
226
226
|
get,
|
|
227
227
|
set
|
|
228
|
-
}) => Effect.gen(function* (
|
|
229
|
-
const state = yield*
|
|
228
|
+
}) => Effect.gen(function* () {
|
|
229
|
+
const state = yield* get;
|
|
230
230
|
const {
|
|
231
231
|
entries,
|
|
232
232
|
index
|
|
@@ -234,7 +234,7 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
234
234
|
const from = entries[index];
|
|
235
235
|
const nextIndex = entries.findIndex(e => e.key === key);
|
|
236
236
|
if (nextIndex === -1) return from;
|
|
237
|
-
const id = yield*
|
|
237
|
+
const id = yield* _id.makeUuid.pipe(_id.GetRandomValues.provide(getRandomValues));
|
|
238
238
|
const to = {
|
|
239
239
|
...entries[nextIndex],
|
|
240
240
|
id
|
|
@@ -247,38 +247,38 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
247
247
|
delta,
|
|
248
248
|
info: options?.info
|
|
249
249
|
};
|
|
250
|
-
return yield*
|
|
250
|
+
return yield* runNavigationEvent(event, get, set, 0, skipCommit);
|
|
251
251
|
}));
|
|
252
|
-
const back = (options, skipCommit = false) => Effect.gen(function* (
|
|
252
|
+
const back = (options, skipCommit = false) => Effect.gen(function* () {
|
|
253
253
|
const {
|
|
254
254
|
entries,
|
|
255
255
|
index
|
|
256
|
-
} = yield*
|
|
256
|
+
} = yield* state;
|
|
257
257
|
if (index === 0) return entries[index];
|
|
258
258
|
const {
|
|
259
259
|
key
|
|
260
260
|
} = entries[index - 1];
|
|
261
|
-
return yield*
|
|
261
|
+
return yield* traverseTo(key, options, skipCommit);
|
|
262
262
|
});
|
|
263
|
-
const forward = (options, skipCommit = false) => Effect.gen(function* (
|
|
263
|
+
const forward = (options, skipCommit = false) => Effect.gen(function* () {
|
|
264
264
|
const {
|
|
265
265
|
entries,
|
|
266
266
|
index
|
|
267
|
-
} = yield*
|
|
267
|
+
} = yield* state;
|
|
268
268
|
if (index === entries.length - 1) return entries[index];
|
|
269
269
|
const {
|
|
270
270
|
key
|
|
271
271
|
} = entries[index + 1];
|
|
272
|
-
return yield*
|
|
272
|
+
return yield* traverseTo(key, options, skipCommit);
|
|
273
273
|
});
|
|
274
274
|
const reload = (options, skipCommit = false) => state.runUpdates(({
|
|
275
275
|
get,
|
|
276
276
|
set
|
|
277
|
-
}) => Effect.gen(function* (
|
|
277
|
+
}) => Effect.gen(function* () {
|
|
278
278
|
const {
|
|
279
279
|
entries,
|
|
280
280
|
index
|
|
281
|
-
} = yield*
|
|
281
|
+
} = yield* state;
|
|
282
282
|
const current = entries[index];
|
|
283
283
|
const event = {
|
|
284
284
|
type: "reload",
|
|
@@ -287,7 +287,7 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
287
287
|
delta: 0,
|
|
288
288
|
info: options?.info
|
|
289
289
|
};
|
|
290
|
-
return yield*
|
|
290
|
+
return yield* runNavigationEvent(event, get, set, 0, skipCommit);
|
|
291
291
|
}));
|
|
292
292
|
const beforeNavigation = handler => Effect.contextWithEffect(ctx => {
|
|
293
293
|
const entry = [handler, ctx];
|
|
@@ -308,11 +308,11 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
308
308
|
const updateCurrentEntry = options => state.runUpdates(({
|
|
309
309
|
get,
|
|
310
310
|
set
|
|
311
|
-
}) => Effect.gen(function* (
|
|
311
|
+
}) => Effect.gen(function* () {
|
|
312
312
|
const {
|
|
313
313
|
entries,
|
|
314
314
|
index
|
|
315
|
-
} = yield*
|
|
315
|
+
} = yield* get;
|
|
316
316
|
const current = entries[index];
|
|
317
317
|
const event = {
|
|
318
318
|
type: "replace",
|
|
@@ -324,16 +324,16 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
324
324
|
delta: 0,
|
|
325
325
|
info: null
|
|
326
326
|
};
|
|
327
|
-
return yield*
|
|
327
|
+
return yield* runNavigationEvent(event, get, set, 0);
|
|
328
328
|
}));
|
|
329
329
|
const submit = (data, input) => state.runUpdates(({
|
|
330
330
|
get,
|
|
331
331
|
set
|
|
332
|
-
}) => Effect.gen(function* (
|
|
332
|
+
}) => Effect.gen(function* () {
|
|
333
333
|
const {
|
|
334
334
|
entries,
|
|
335
335
|
index
|
|
336
|
-
} = yield*
|
|
336
|
+
} = yield* get;
|
|
337
337
|
const from = entries[index];
|
|
338
338
|
const event = {
|
|
339
339
|
from,
|
|
@@ -343,9 +343,9 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
343
343
|
method: Option.fromNullable(input?.method),
|
|
344
344
|
encoding: Option.fromNullable(input?.encoding)
|
|
345
345
|
};
|
|
346
|
-
const either = yield*
|
|
346
|
+
const either = yield* runFormDataHandlers(event);
|
|
347
347
|
if (Either.isLeft(either)) {
|
|
348
|
-
yield*
|
|
348
|
+
yield* handleError(either.left, get, set, 0);
|
|
349
349
|
return Option.none();
|
|
350
350
|
} else {
|
|
351
351
|
if (Option.isNone(either.right)) {
|
|
@@ -358,9 +358,9 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
358
358
|
// And we have a location header
|
|
359
359
|
if (Option.isSome(location)) {
|
|
360
360
|
// Then we navigate to that location
|
|
361
|
-
yield*
|
|
361
|
+
yield* navigate(location.value, {
|
|
362
362
|
history: "replace"
|
|
363
|
-
})
|
|
363
|
+
});
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
return Option.some(response);
|
|
@@ -396,9 +396,9 @@ function setupFromModelAndIntent(modelAndIntent, origin, base, getRandomValues,
|
|
|
396
396
|
return navigation;
|
|
397
397
|
}
|
|
398
398
|
function makeRedirectEvent(origin, redirect, from) {
|
|
399
|
-
return Effect.gen(function* (
|
|
399
|
+
return Effect.gen(function* () {
|
|
400
400
|
const url = getUrl(origin, redirect.path);
|
|
401
|
-
const to = yield*
|
|
401
|
+
const to = yield* makeDestination(url, redirect.options?.state, origin);
|
|
402
402
|
const event = {
|
|
403
403
|
type: "replace",
|
|
404
404
|
from,
|
|
@@ -410,11 +410,11 @@ function makeRedirectEvent(origin, redirect, from) {
|
|
|
410
410
|
});
|
|
411
411
|
}
|
|
412
412
|
function makeOrUpdateDestination(navigationState, url, state, origin) {
|
|
413
|
-
return Effect.gen(function* (
|
|
413
|
+
return Effect.gen(function* () {
|
|
414
414
|
const current = navigationState.entries[navigationState.index];
|
|
415
415
|
const isSameOriginAndPath = url.origin === current.url.origin && url.pathname === current.url.pathname;
|
|
416
416
|
if (isSameOriginAndPath) {
|
|
417
|
-
const id = yield*
|
|
417
|
+
const id = yield* _id.makeUuid;
|
|
418
418
|
const destination = {
|
|
419
419
|
id,
|
|
420
420
|
key: current.key,
|
|
@@ -424,12 +424,12 @@ function makeOrUpdateDestination(navigationState, url, state, origin) {
|
|
|
424
424
|
};
|
|
425
425
|
return destination;
|
|
426
426
|
} else {
|
|
427
|
-
return yield*
|
|
427
|
+
return yield* makeDestination(url, state, origin);
|
|
428
428
|
}
|
|
429
429
|
});
|
|
430
430
|
}
|
|
431
431
|
function makeDestination(url, state, origin) {
|
|
432
|
-
return Effect.gen(function* (
|
|
432
|
+
return Effect.gen(function* () {
|
|
433
433
|
if (isPatchedState(state)) {
|
|
434
434
|
const destination = {
|
|
435
435
|
id: state.id,
|
|
@@ -440,8 +440,8 @@ function makeDestination(url, state, origin) {
|
|
|
440
440
|
};
|
|
441
441
|
return destination;
|
|
442
442
|
}
|
|
443
|
-
const id = yield*
|
|
444
|
-
const key = yield*
|
|
443
|
+
const id = yield* _id.makeUuid;
|
|
444
|
+
const key = yield* _id.makeUuid;
|
|
445
445
|
const destination = {
|
|
446
446
|
id,
|
|
447
447
|
key,
|
|
@@ -453,9 +453,9 @@ function makeDestination(url, state, origin) {
|
|
|
453
453
|
});
|
|
454
454
|
}
|
|
455
455
|
function upgradeProposedDestination(proposed) {
|
|
456
|
-
return Effect.gen(function* (
|
|
457
|
-
const id = yield*
|
|
458
|
-
const key = yield*
|
|
456
|
+
return Effect.gen(function* () {
|
|
457
|
+
const id = yield* _id.makeUuid;
|
|
458
|
+
const key = yield* _id.makeUuid;
|
|
459
459
|
const destination = {
|
|
460
460
|
id,
|
|
461
461
|
key,
|
|
@@ -491,16 +491,16 @@ function isDestination(proposed) {
|
|
|
491
491
|
}
|
|
492
492
|
const strictEqual = (a, b) => a === b;
|
|
493
493
|
function makeHandlersState() {
|
|
494
|
-
return Effect.gen(function* (
|
|
495
|
-
const beforeHandlers = yield*
|
|
494
|
+
return Effect.gen(function* () {
|
|
495
|
+
const beforeHandlers = yield* RefSubject.fromEffect(Effect.sync(() => new Set()), {
|
|
496
496
|
eq: strictEqual
|
|
497
|
-
})
|
|
498
|
-
const handlers = yield*
|
|
497
|
+
});
|
|
498
|
+
const handlers = yield* RefSubject.fromEffect(Effect.sync(() => new Set()), {
|
|
499
499
|
eq: strictEqual
|
|
500
|
-
})
|
|
501
|
-
const formDataHandlers = yield*
|
|
500
|
+
});
|
|
501
|
+
const formDataHandlers = yield* RefSubject.fromEffect(Effect.sync(() => new Set()), {
|
|
502
502
|
eq: strictEqual
|
|
503
|
-
})
|
|
503
|
+
});
|
|
504
504
|
return {
|
|
505
505
|
beforeHandlers,
|
|
506
506
|
handlers,
|