foldkit 0.15.0-canary.1 → 0.15.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.
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
2
|
import { Html } from '../html';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const noOpDispatch: {
|
|
4
|
+
dispatchAsync: (_message: unknown) => Effect.Effect<void, never, never>;
|
|
5
|
+
dispatchSync: (_message: unknown) => void;
|
|
6
|
+
};
|
|
4
7
|
export declare const defaultErrorView: (error: Error, viewError?: unknown) => Html;
|
|
5
8
|
//# sourceMappingURL=errorUI.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorUI.d.ts","sourceRoot":"","sources":["../../src/runtime/errorUI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"errorUI.d.ts","sourceRoot":"","sources":["../../src/runtime/errorUI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,IAAI,EAAQ,MAAM,SAAS,CAAA;AAEpC,eAAO,MAAM,YAAY;8BACG,OAAO;6BACR,OAAO;CACjC,CAAA;AAmBD,eAAO,MAAM,gBAAgB,GAAI,OAAO,KAAK,EAAE,YAAY,OAAO,KAAG,IA4LpE,CAAA"}
|
package/dist/runtime/errorUI.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { h } from 'snabbdom';
|
|
3
2
|
import { html } from '../html';
|
|
4
|
-
|
|
5
|
-
import { Dispatch } from './runtime';
|
|
6
|
-
const noOpDispatch = {
|
|
3
|
+
export const noOpDispatch = {
|
|
7
4
|
dispatchAsync: (_message) => Effect.void,
|
|
8
5
|
dispatchSync: (_message) => { },
|
|
9
6
|
};
|
|
10
|
-
export const renderHtml = (container, html) => html.pipe(Effect.map((vnode) => {
|
|
11
|
-
const targetVNode = vnode ?? h('#text', {}, '');
|
|
12
|
-
patch(toVNode(container), targetVNode);
|
|
13
|
-
}), Effect.provideService(Dispatch, noOpDispatch));
|
|
14
7
|
const colors = {
|
|
15
8
|
bg: '#f9fafb',
|
|
16
9
|
cardBg: '#ffffff',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,OAAO,EACP,MAAM,EASN,MAAM,EACN,MAAM,EAGP,MAAM,QAAQ,CAAA;AAGf,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,GAAG,EAA+B,MAAM,QAAQ,CAAA;AAOzD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;;4BAKb,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;2BAC1C,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI;;AAJrD,qBAAa,QAAS,SAAQ,aAM3B;CAAG;AAEN,MAAM,MAAM,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAErD,MAAM,MAAM,aAAa,CAAC,OAAO,IAAI;IACnC,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAA;IACvD,QAAQ,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAA;CAC5C,CAAA;AAED,MAAM,WAAW,aAAa,CAC5B,KAAK,EACL,OAAO,EACP,aAAa,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CA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;AAkDpB,eAAO,MAAM,GAAG,GAAI,gBAAgB,iBAAiB,KAAG,IAUvD,CAAA"}
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BrowserRuntime } from '@effect/platform-browser/index';
|
|
2
|
-
import { Cause,
|
|
2
|
+
import { Cause, Context, Effect, Either, Function, Option, Predicate, Queue, Record, Ref, Runtime, Schema, Stream, SubscriptionRef, pipe, } from 'effect';
|
|
3
3
|
import { h } from 'snabbdom';
|
|
4
4
|
import { fromString as urlFromString } from '../url';
|
|
5
5
|
import { patch, toVNode } from '../vdom';
|
|
6
6
|
import { addBfcacheRestoreListener, addNavigationEventListeners, } from './browserListeners';
|
|
7
|
-
import { defaultErrorView,
|
|
7
|
+
import { defaultErrorView, noOpDispatch } from './errorUI';
|
|
8
8
|
export class Dispatch extends Context.Tag('@foldkit/Dispatch')() {
|
|
9
9
|
}
|
|
10
10
|
export const makeCommandStreams = (CommandStreamsDeps) => (configs) => Record.map(configs, ({ modelToDeps, depsToStream }, key) => ({
|
|
@@ -43,14 +43,25 @@ const makeRuntime = ({ Model, Flags: _Flags, flags: flags_, init, update, view,
|
|
|
43
43
|
}
|
|
44
44
|
yield* Effect.forEach(commands, (command) => Effect.forkDaemon(command.pipe(Effect.flatMap(enqueueMessage))));
|
|
45
45
|
});
|
|
46
|
+
const runProcessMessage = (messageEffect) => (runtime) => {
|
|
47
|
+
try {
|
|
48
|
+
Runtime.runSync(runtime)(messageEffect);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const squashed = Runtime.isFiberFailure(error)
|
|
52
|
+
? Cause.squash(error[Runtime.FiberFailureCauseId])
|
|
53
|
+
: error;
|
|
54
|
+
const appError = squashed instanceof Error ? squashed : new Error(String(squashed));
|
|
55
|
+
renderErrorView(appError, errorView, container, maybeCurrentVNodeRef);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
46
58
|
const dispatchSync = (message) => {
|
|
47
|
-
const maybeRuntime = Ref.get(maybeRuntimeRef)
|
|
59
|
+
const maybeRuntime = Effect.runSync(Ref.get(maybeRuntimeRef));
|
|
48
60
|
Option.match(maybeRuntime, {
|
|
49
61
|
onNone: Function.constVoid,
|
|
50
|
-
onSome: (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
62
|
+
onSome: runProcessMessage(
|
|
63
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
|
|
64
|
+
processMessage(message)),
|
|
54
65
|
});
|
|
55
66
|
};
|
|
56
67
|
const dispatchAsync = (message) =>
|
|
@@ -77,30 +88,14 @@ const makeRuntime = ({ Model, Flags: _Flags, flags: flags_, init, update, view,
|
|
|
77
88
|
discard: true,
|
|
78
89
|
}));
|
|
79
90
|
}
|
|
80
|
-
yield* Effect.forever(Effect.gen(function* () {
|
|
91
|
+
yield* pipe(Effect.forever(Effect.gen(function* () {
|
|
81
92
|
const message = yield* Queue.take(messageQueue);
|
|
82
93
|
yield* processMessage(message);
|
|
83
|
-
}))
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
yield* Console.error('[foldkit] Application error:', error);
|
|
89
|
-
if (errorView) {
|
|
90
|
-
yield* Effect.try({
|
|
91
|
-
try: () => errorView(error),
|
|
92
|
-
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
93
|
-
}).pipe(Effect.matchEffect({
|
|
94
|
-
onSuccess: (view) => renderHtml(container, view),
|
|
95
|
-
onFailure: (viewError) => Effect.gen(function* () {
|
|
96
|
-
yield* Console.error('[foldkit] Custom errorView failed:', viewError);
|
|
97
|
-
yield* renderHtml(container, defaultErrorView(error, viewError));
|
|
98
|
-
}),
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
yield* renderHtml(container, defaultErrorView(error));
|
|
103
|
-
}
|
|
94
|
+
})), Effect.catchAllCause((cause) => Effect.sync(() => {
|
|
95
|
+
const squashed = Cause.squash(cause);
|
|
96
|
+
const appError = squashed instanceof Error ? squashed : new Error(String(squashed));
|
|
97
|
+
renderErrorView(appError, errorView, container, maybeCurrentVNodeRef);
|
|
98
|
+
})));
|
|
104
99
|
});
|
|
105
100
|
const patchVNode = (maybeCurrentVNode, nextVNodeNullish, container) => {
|
|
106
101
|
const nextVNode = Predicate.isNotNull(nextVNodeNullish)
|
|
@@ -111,6 +106,24 @@ const patchVNode = (maybeCurrentVNode, nextVNodeNullish, container) => {
|
|
|
111
106
|
onSome: (currentVNode) => patch(currentVNode, nextVNode),
|
|
112
107
|
});
|
|
113
108
|
};
|
|
109
|
+
const renderErrorView = (appError, errorView, container, maybeCurrentVNodeRef) => {
|
|
110
|
+
console.error('[foldkit] Application error:', appError);
|
|
111
|
+
try {
|
|
112
|
+
const errorHtml = errorView
|
|
113
|
+
? errorView(appError)
|
|
114
|
+
: defaultErrorView(appError);
|
|
115
|
+
const maybeCurrentVNode = Ref.get(maybeCurrentVNodeRef).pipe(Effect.runSync);
|
|
116
|
+
const vnode = errorHtml.pipe(Effect.provideService(Dispatch, noOpDispatch), Effect.runSync);
|
|
117
|
+
patchVNode(maybeCurrentVNode, vnode, container);
|
|
118
|
+
}
|
|
119
|
+
catch (viewError) {
|
|
120
|
+
console.error('[foldkit] Custom errorView failed:', viewError);
|
|
121
|
+
const maybeCurrentVNode = Ref.get(maybeCurrentVNodeRef).pipe(Effect.runSync);
|
|
122
|
+
const fallbackViewError = viewError instanceof Error ? viewError : new Error(String(viewError));
|
|
123
|
+
const vnode = defaultErrorView(appError, fallbackViewError).pipe(Effect.provideService(Dispatch, noOpDispatch), Effect.runSync);
|
|
124
|
+
patchVNode(maybeCurrentVNode, vnode, container);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
114
127
|
export function makeElement(config) {
|
|
115
128
|
const baseConfig = {
|
|
116
129
|
Model: config.Model,
|