foldkit 0.158.1 → 0.158.2-canary.40b6ef2babe9

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.
@@ -0,0 +1,42 @@
1
+ import { type EntryResult } from './entry.js';
2
+ /** How {@link handleRequest} renders a page request.
3
+ *
4
+ * @experimental Ships from `foldkit/experimental/server`; expect breaking changes while the API settles.
5
+ */
6
+ export type HandleRequestOptions = Readonly<{
7
+ /**
8
+ * The application's server entry. One Web `Request` in, one delivery
9
+ * result out.
10
+ */
11
+ renderPage: (request: Request) => Promise<EntryResult>;
12
+ /**
13
+ * The unfilled HTML shell. Rendered markup is placed into its container.
14
+ */
15
+ template: string;
16
+ /**
17
+ * The `id` of the empty container in {@link template} the rendered
18
+ * markup replaces. Defaults to `'root'`.
19
+ */
20
+ containerId?: string;
21
+ }>;
22
+ /**
23
+ * Answers one request as a Web `fetch` handler: refuse methods the
24
+ * `Request` constructor cannot represent, classify a static miss so a
25
+ * hashed asset is not answered with the application shell, and otherwise
26
+ * call `renderPage`.
27
+ *
28
+ * Static files are the platform's job. This function is what remains
29
+ * after Vite, a file server, or Worker assets have already missed.
30
+ * Node and workerd both call it, so development predicts production.
31
+ *
32
+ * `Request.url` is trusted as the platform constructed it. On Workers and
33
+ * Deno that is the URL the platform resolved. A Node adapter receives a raw
34
+ * request target instead, which may be an absolute URL or a network-path
35
+ * reference naming another host, so the adapter resolves that target
36
+ * against its configured origin with `resolveRequestUrl` and refuses an
37
+ * off-origin one before constructing the `Request` it passes here.
38
+ *
39
+ * @experimental Ships from `foldkit/experimental/server`; expect breaking changes while the API settles.
40
+ */
41
+ export declare const handleRequest: (request: Request, options: HandleRequestOptions) => Promise<Response>;
42
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/experimental/server/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,YAAY,CAAA;AAYzD;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC;IAC1C;;;OAGG;IACH,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,WAAW,CAAC,CAAA;IACtD;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAC,CAAA;AA8BF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,YACf,OAAO,WACP,oBAAoB,KAC5B,OAAO,CAAC,QAAQ,CA+ClB,CAAA"}
@@ -0,0 +1,75 @@
1
+ import { toResponse } from './entry.js';
2
+ import { HOST_METHOD_ANSWERS, acceptsHtml, classifyRequest, isHostSettledMethod, resolvesToIndexHtml, varyWith, varyWithAccept, } from './host.js';
3
+ const withNegotiatedVary = (response) => {
4
+ const headers = new Headers(response.headers);
5
+ headers.set('vary', varyWith(varyWithAccept(headers.get('vary') ?? undefined), 'Sec-Fetch-Dest'));
6
+ return new Response(response.body, {
7
+ status: response.status,
8
+ statusText: response.statusText,
9
+ headers,
10
+ });
11
+ };
12
+ const emptyResponse = (status, headers) => {
13
+ if (headers === undefined) {
14
+ return new Response(null, { status });
15
+ }
16
+ return new Response(null, { status, headers });
17
+ };
18
+ const injectOptions = (containerId) => containerId === undefined ? undefined : { containerId };
19
+ /**
20
+ * Answers one request as a Web `fetch` handler: refuse methods the
21
+ * `Request` constructor cannot represent, classify a static miss so a
22
+ * hashed asset is not answered with the application shell, and otherwise
23
+ * call `renderPage`.
24
+ *
25
+ * Static files are the platform's job. This function is what remains
26
+ * after Vite, a file server, or Worker assets have already missed.
27
+ * Node and workerd both call it, so development predicts production.
28
+ *
29
+ * `Request.url` is trusted as the platform constructed it. On Workers and
30
+ * Deno that is the URL the platform resolved. A Node adapter receives a raw
31
+ * request target instead, which may be an absolute URL or a network-path
32
+ * reference naming another host, so the adapter resolves that target
33
+ * against its configured origin with `resolveRequestUrl` and refuses an
34
+ * off-origin one before constructing the `Request` it passes here.
35
+ *
36
+ * @experimental Ships from `foldkit/experimental/server`; expect breaking changes while the API settles.
37
+ */
38
+ export const handleRequest = async (request, options) => {
39
+ if (isHostSettledMethod(request.method)) {
40
+ return emptyResponse(HOST_METHOD_ANSWERS.refusedStatus, {
41
+ allow: HOST_METHOD_ANSWERS.allow,
42
+ });
43
+ }
44
+ const requestUrl = request.url;
45
+ const method = request.method.toUpperCase();
46
+ const isGetOrHead = method === 'GET' || method === 'HEAD';
47
+ let negotiated = false;
48
+ if (isGetOrHead && !resolvesToIndexHtml(requestUrl)) {
49
+ const classification = classifyRequest(requestUrl, request.headers.get('sec-fetch-dest') ?? undefined);
50
+ if (classification === 'PathAsset') {
51
+ return emptyResponse(404);
52
+ }
53
+ if (classification === 'DestinationAsset') {
54
+ return emptyResponse(404, {
55
+ vary: varyWith(undefined, 'Sec-Fetch-Dest'),
56
+ });
57
+ }
58
+ negotiated = true;
59
+ if (!acceptsHtml(request.headers.get('accept') ?? undefined)) {
60
+ return emptyResponse(404, {
61
+ vary: varyWith(varyWithAccept(undefined), 'Sec-Fetch-Dest'),
62
+ });
63
+ }
64
+ }
65
+ const result = await options.renderPage(request);
66
+ const rendered = toResponse(options.template, result, injectOptions(options.containerId));
67
+ let response = rendered;
68
+ if (method === 'HEAD') {
69
+ response = emptyResponse(rendered.status, rendered.headers);
70
+ }
71
+ if (negotiated) {
72
+ return withNegotiatedVary(response);
73
+ }
74
+ return response;
75
+ };
@@ -1,4 +1,5 @@
1
1
  export * from './entry.js';
2
+ export * from './fetch.js';
2
3
  export * from './host.js';
3
4
  export * from './server.js';
4
5
  export * from './template.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export * from './entry.js';
2
+ export * from './fetch.js';
2
3
  export * from './host.js';
3
4
  export * from './server.js';
4
5
  export * from './template.js';
@@ -1,3 +1,3 @@
1
- export { FOLDKIT_APP_ATTRIBUTE, FOLDKIT_FLAGS_ATTRIBUTE, FlagsEncodeError, HOST_METHOD_ANSWERS, InvalidHydrationRoot, InvalidRuntimeId, InvalidUrl, MissingBuildId, Rendered, Responded, SerializationError, acceptsHtml, classifyRequest, injectIntoTemplate, isHostSettledMethod, renderToString, resolveRequestUrl, resolvesToIndexHtml, toResponse, varyWith, varyWithAccept, } from './index.js';
2
- export type { InjectIntoTemplateOptions, RequestClassification, ResponseOptions, RenderedApplication, HydratableRenderOptions, StaticRenderOptions, RenderOptions, RenderUrlOptions, RenderFlagsOptions, RenderUrlFlagsOptions, ApplicationConfig, ApplicationConfigWithFlags, EntryModule, EntryResult, RenderError, RoutingApplicationConfig, RoutingApplicationConfigWithFlags, } from './index.js';
1
+ export { FOLDKIT_APP_ATTRIBUTE, FOLDKIT_FLAGS_ATTRIBUTE, FlagsEncodeError, HOST_METHOD_ANSWERS, InvalidHydrationRoot, InvalidRuntimeId, InvalidUrl, MissingBuildId, Rendered, Responded, SerializationError, acceptsHtml, classifyRequest, handleRequest, injectIntoTemplate, isHostSettledMethod, renderToString, resolveRequestUrl, resolvesToIndexHtml, toResponse, varyWith, varyWithAccept, } from './index.js';
2
+ export type { HandleRequestOptions, InjectIntoTemplateOptions, RequestClassification, ResponseOptions, RenderedApplication, HydratableRenderOptions, StaticRenderOptions, RenderOptions, RenderUrlOptions, RenderFlagsOptions, RenderUrlFlagsOptions, ApplicationConfig, ApplicationConfigWithFlags, EntryModule, EntryResult, RenderError, RoutingApplicationConfig, RoutingApplicationConfigWithFlags, } from './index.js';
3
3
  //# sourceMappingURL=public.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/experimental/server/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,QAAQ,EACR,cAAc,GACf,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,yBAAyB,EACzB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,0BAA0B,EAC1B,WAAW,EACX,WAAW,EACX,WAAW,EACX,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/experimental/server/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,QAAQ,EACR,cAAc,GACf,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,0BAA0B,EAC1B,WAAW,EACX,WAAW,EACX,WAAW,EACX,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,YAAY,CAAA"}
@@ -1 +1 @@
1
- export { FOLDKIT_APP_ATTRIBUTE, FOLDKIT_FLAGS_ATTRIBUTE, FlagsEncodeError, HOST_METHOD_ANSWERS, InvalidHydrationRoot, InvalidRuntimeId, InvalidUrl, MissingBuildId, Rendered, Responded, SerializationError, acceptsHtml, classifyRequest, injectIntoTemplate, isHostSettledMethod, renderToString, resolveRequestUrl, resolvesToIndexHtml, toResponse, varyWith, varyWithAccept, } from './index.js';
1
+ export { FOLDKIT_APP_ATTRIBUTE, FOLDKIT_FLAGS_ATTRIBUTE, FlagsEncodeError, HOST_METHOD_ANSWERS, InvalidHydrationRoot, InvalidRuntimeId, InvalidUrl, MissingBuildId, Rendered, Responded, SerializationError, acceptsHtml, classifyRequest, handleRequest, injectIntoTemplate, isHostSettledMethod, renderToString, resolveRequestUrl, resolvesToIndexHtml, toResponse, varyWith, varyWithAccept, } from './index.js';
@@ -1,4 +1,4 @@
1
- import { Effect } from 'effect';
1
+ import { Cause, Effect } from 'effect';
2
2
  import type { Ports } from '../port/index.js';
3
3
  import { type EmbedHandle } from './hostConnector.js';
4
4
  import type { BootMode } from './hydrationHandoff.js';
@@ -18,6 +18,9 @@ type RuntimeProgram = Readonly<{
18
18
  /** Starts a program Effect with explicit boot inputs for runtime tests.
19
19
  * @internal */
20
20
  export declare const __startProgram: (program: RuntimeProgram, hmrModel: unknown, bootMode: BootMode, flags?: Effect.Effect<unknown, never, any>, buildId?: string) => Effect.Effect<void>;
21
+ /** Reports unhandled non-interrupt Causes using Effect's runtime policy.
22
+ * @internal */
23
+ export declare const __reportUnhandledCause: <E>(cause: Cause.Cause<E>) => Effect.Effect<void>;
21
24
  /** Starts a Foldkit runtime that owns the page for the page's whole lifetime,
22
25
  * with HMR support for development. The first render builds the DOM fresh in
23
26
  * the container, replacing whatever is there. On a server-rendered page use
@@ -1 +1 @@
1
- {"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/runtime/start.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAOP,MAAM,QAAQ,CAAA;AAEf,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAG7C,OAAO,EACL,KAAK,WAAW,EAGjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,KAAK,iBAAiB,EAAoB,MAAM,cAAc,CAAA;AAEvE;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,QAAQ,CAAC;IAC1D,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;CAC9C,CAAC,CAAA;AAEF,KAAK,cAAc,GAAG,QAAQ,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAClD,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;CACzB,CAAC,CAAA;AAEF;eACe;AACf,eAAO,MAAM,cAAc,YAChB,cAAc,YACb,OAAO,YACP,QAAQ,UACV,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,YAChC,MAAM,KACf,MAAM,CAAC,MAAM,CAAC,IAAI,CAqBpB,CAAA;AA6BD;;;;8CAI8C;AAC9C,wBAAgB,GAAG,CACjB,CAAC,SAAS,KAAK,GAAG,SAAS,EAC3B,SAAS,EACT,IAAI,SAAS,aAAa,GAAG,SAAS,EAC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Aa,GAAG,SAAS,EAEtC,OAAO,EAAE,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EACrD,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,GACpC,WAAW,CAAC,CAAC,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { Effect, Fiber, Function, Option, Predicate, Runtime, pipe, } from 'effect';
1
+ import { Cause, Effect, Fiber, Function, Option, Predicate, Runtime, pipe, } from 'effect';
2
2
  import { provideBrowserScheduler } from './browserScheduler.js';
3
3
  import { resolveHmrModel } from './hmrModelBridge.js';
4
4
  import { buildPortHandles, makeHostConnector, } from './hostConnector.js';
@@ -25,11 +25,23 @@ export const __startProgram = (program, hmrModel, bootMode, flags, buildId) => {
25
25
  // put the container element back empty, so the page is left alive with no app
26
26
  // in it. A page-owning runtime gains nothing from tearing itself down while
27
27
  // the document is on its way out, so it starts with no page-lifecycle
28
- // interrupt at all and lets the document take the runtime with it. Error
29
- // reporting and the keep-alive interval come from `makeRunMain` either way.
28
+ // interrupt at all and lets the document take the runtime with it. The
29
+ // keep-alive interval still comes from `makeRunMain`; Foldkit owns the shared
30
+ // error-reporting policy used by page-owning and embedded runtimes below.
30
31
  const runMainWithoutUnloadInterrupt = Runtime.makeRunMain(Function.constVoid);
32
+ /** Reports unhandled non-interrupt Causes using Effect's runtime policy.
33
+ * @internal */
34
+ export const __reportUnhandledCause = (cause) => {
35
+ if (Cause.hasInterruptsOnly(cause)) {
36
+ return Effect.void;
37
+ }
38
+ return Runtime.getErrorReported(Cause.squash(cause))
39
+ ? Effect.logError(cause)
40
+ : Effect.void;
41
+ };
42
+ const withUnhandledCauseReporting = (effect) => Effect.tapCause(effect, __reportUnhandledCause);
31
43
  const startProgram = (program, bootMode, flags, buildId) => {
32
- runMainWithoutUnloadInterrupt(provideBrowserScheduler(Effect.flatMap(resolveHmrModel(program.runtimeId), hmrModel => __startProgram(program, hmrModel, bootMode, flags, buildId))));
44
+ runMainWithoutUnloadInterrupt(withUnhandledCauseReporting(provideBrowserScheduler(Effect.flatMap(resolveHmrModel(program.runtimeId), hmrModel => __startProgram(program, hmrModel, bootMode, flags, buildId)))), { disableErrorReporting: true });
33
45
  };
34
46
  export function run(program, options) {
35
47
  startProgram(program, 'Fresh', options?.flags);
@@ -82,7 +94,7 @@ export function embed(program, options) {
82
94
  onNone: () => Effect.void,
83
95
  onSome: previousFiber => Effect.asVoid(Fiber.await(previousFiber)),
84
96
  }), Effect.andThen(resolveHmrModel(program.runtimeId)), Effect.flatMap(hmrModel => internals.startWith(Option.some(connector), hmrModel, 'Fresh', options?.flags)));
85
- const fiber = Effect.runFork(provideBrowserScheduler(startEffect));
97
+ const fiber = Effect.runFork(withUnhandledCauseReporting(provideBrowserScheduler(startEffect)));
86
98
  internals.maybeActiveFiber = Option.some(fiber);
87
99
  let isHandleDisposed = false;
88
100
  const dispose = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"fileUpload.d.ts","sourceRoot":"","sources":["../../../src/test/apps/fileUpload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAE5D,OAAO,KAAK,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAIpD,MAAM,MAAM,KAAK,GAAG,QAAQ,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;CACnC,CAAC,CAAA;AAEF,eAAO,MAAM,YAAY,EAAE,KAA6B,CAAA;AAIxD,eAAO,MAAM,OAAO;;QACD,KAAK;;EACtB,CAAA;AAEF,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIzC,eAAO,MAAM,MAAM,UAAW,KAAK,WAAW,OAAO;;uBAfpC,aAAa,CAAC,IAAI,CAAC;;;;;;;EAoBhC,CAAA;AAIJ,eAAO,MAAM,IAAI,UAAW,KAAK,KAAK,WAAW,CAAC,OAAO,CAAC,KAAG,IA4B5D,CAAA"}
1
+ {"version":3,"file":"fileUpload.d.ts","sourceRoot":"","sources":["../../../src/test/apps/fileUpload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAG5D,OAAO,KAAK,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAIpD,MAAM,MAAM,KAAK,GAAG,QAAQ,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;CACnC,CAAC,CAAA;AAEF,eAAO,MAAM,YAAY,EAAE,KAA6B,CAAA;AAIxD,eAAO,MAAM,OAAO;;QACD,KAAK;;EACtB,CAAA;AAEF,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIzC,eAAO,MAAM,MAAM,UAAW,KAAK,WAAW,OAAO;;uBAfpC,aAAa,CAAC,IAAI,CAAC;;;;;;;EAoBhC,CAAA;AAIJ,eAAO,MAAM,IAAI,UAAW,KAAK,KAAK,WAAW,CAAC,OAAO,CAAC,KAAG,IA4B5D,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import { Schema } from 'effect';
2
2
  import { File } from '../../file/index.js';
3
3
  import { defineMessageUnion } from '../../message/index.js';
4
+ import { evo } from '../../struct/index.js';
4
5
  export const initialModel = { receivedFiles: [] };
5
6
  // MESSAGE
6
7
  export const Message = defineMessageUnion({
@@ -9,7 +10,7 @@ export const Message = defineMessageUnion({
9
10
  // UPDATE
10
11
  export const update = (model, message) => Message.match(message, {
11
12
  ReceivedFiles: ({ files }) => ({
12
- model: { ...model, receivedFiles: files },
13
+ model: evo(model, { receivedFiles: () => files }),
13
14
  }),
14
15
  });
15
16
  // VIEW
@@ -76,7 +76,7 @@ const foldChildOutMessage = ChildOutMessage.match({
76
76
  const foldChildUpdate = Update.foldChild({
77
77
  update: childUpdate,
78
78
  read: (model) => Option.some(model.child),
79
- write: (model, nextChild) => ({ ...model, child: nextChild }),
79
+ write: (model, nextChild) => evo(model, { child: () => nextChild }),
80
80
  toParentMessage: message => ParentMessage.GotChildMessage({ message }),
81
81
  foldOutMessage: foldChildOutMessage,
82
82
  });
@@ -1 +1 @@
1
- {"version":3,"file":"pointer.d.ts","sourceRoot":"","sources":["../../../src/test/apps/pointer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEvC,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAE5D,OAAO,KAAK,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAIpD,eAAO,MAAM,KAAK;;;;EAIhB,CAAA;AACF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAA;AAIrC,QAAA,MAAM,OAAO;;QACW,WAAW;;;QACZ,WAAW;;EAChC,CAAA;AACF,KAAK,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIlC,eAAO,MAAM,YAAY,EAAE,KAI1B,CAAA;AAID,eAAO,MAAM,MAAM,UAAW,KAAK,WAAW,OAAO;;;;;;;;;;;;;;EAgBjD,CAAA;AAIJ,eAAO,MAAM,IAAI,UAAW,KAAK,KAAK,WAAW,CAAC,OAAO,CAAC,KAAG,IA4B5D,CAAA"}
1
+ {"version":3,"file":"pointer.d.ts","sourceRoot":"","sources":["../../../src/test/apps/pointer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAG5D,OAAO,KAAK,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAIpD,eAAO,MAAM,KAAK;;;;EAIhB,CAAA;AACF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAA;AAIrC,QAAA,MAAM,OAAO;;QACW,WAAW;;;QACZ,WAAW;;EAChC,CAAA;AACF,KAAK,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIlC,eAAO,MAAM,YAAY,EAAE,KAI1B,CAAA;AAID,eAAO,MAAM,MAAM,UAAW,KAAK,WAAW,OAAO;;;;;;;;;;;;;;EAcjD,CAAA;AAIJ,eAAO,MAAM,IAAI,UAAW,KAAK,KAAK,WAAW,CAAC,OAAO,CAAC,KAAG,IA4B5D,CAAA"}
@@ -1,5 +1,6 @@
1
- import { Option, Schema } from 'effect';
1
+ import { Number, Option, Schema } from 'effect';
2
2
  import { defineMessageUnion } from '../../message/index.js';
3
+ import { evo } from '../../struct/index.js';
3
4
  // MODEL
4
5
  export const Model = Schema.Struct({
5
6
  pointerDownCount: Schema.Number,
@@ -20,18 +21,16 @@ export const initialModel = {
20
21
  // UPDATE
21
22
  export const update = (model, message) => Message.match(message, {
22
23
  PressedPointerDown: ({ pointerType }) => ({
23
- model: {
24
- ...model,
25
- pointerDownCount: model.pointerDownCount + 1,
26
- lastPointerType: pointerType,
27
- },
24
+ model: evo(model, {
25
+ pointerDownCount: Number.increment,
26
+ lastPointerType: () => pointerType,
27
+ }),
28
28
  }),
29
29
  ReleasedPointerUp: ({ pointerType }) => ({
30
- model: {
31
- ...model,
32
- pointerUpCount: model.pointerUpCount + 1,
33
- lastPointerType: pointerType,
34
- },
30
+ model: evo(model, {
31
+ pointerUpCount: Number.increment,
32
+ lastPointerType: () => pointerType,
33
+ }),
35
34
  }),
36
35
  });
37
36
  // VIEW
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit",
3
- "version": "0.158.1",
3
+ "version": "0.158.2-canary.40b6ef2babe9",
4
4
  "description": "A TypeScript frontend framework, built on Effect and architected like Elm",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",