effect-appkit apps. For a new app, install Effect SwiftUI.EffectAppKit Swift library and a bundled JavaScript entry that calls start. Swift owns the surface’s lifetime; TypeScript owns the component’s model, messages, and updates. Bun is a build tool, not a process your app needs to launch.https://github.com/tanvesh01/effect-swiftui.git, and select Exact Version: 0.2.1. Link EffectAppKit to your macOS app target. Set the deployment target to macOS 14 or later.package.json, use Bun to install the TypeScript adapter from npm and the dependencies imported by the counter below:1bun add --exact effect-appkit@0.2.1 effect@4.1.7 'https://pkg.pr.new/Effect-TS/ui/@effect/ui@dec1ca9'
bun.lock. Only @effect/ui comes from a pinned upstream preview; fresh installs depend on that preview remaining available. No repository clone or npm login is required. People running your finished app don’t need Bun or npm.src/main.ts in the app. Import the runtime first: Effect needs TextEncoder and TextDecoder during module evaluation, and JavaScriptCore does not provide these browser globals.import "effect-appkit/runtime" import * as UiSchema from "@effect/ui/UiSchema" import { component, start } from "effect-appkit" import * as Schema from "effect/Schema" const Message = UiSchema.TaggedEnum({ Count: {} }) const Counter = component({ name: "Counter", model: Schema.Struct({ count: Schema.Number }), message: Message }).make({ init: () => ({ count: 0 }), update: { Count: ({ model }) => ({ count: model.count + 1 }) }, view: (h, model) => h.button .prop("title", `Count: ${model.count}`) .on("press", Message.Count()) }) start(Counter, {})
1bun build src/main.ts --target=browser --format=iife --conditions=production --minify --outfile=dist/main.js
dist/main.js to the app target’s Copy Bundle Resources, so it is available as main.js in the main bundle. Rebuild the JavaScript after changing TypeScript; SwiftPM does not run Bun. The browser build target does not supply a DOM, fetch, or Node APIs at runtime.12345678import Foundation func loadMainScript() throws -> String { guard let url = Bundle.main.url(forResource: "main", withExtension: "js") else { throw CocoaError(.fileNoSuchFile) } return try String(contentsOf: url, encoding: .utf8) }
body.import EffectAppKit import SwiftUI @main struct CounterApp: App { private let script = Result { try loadMainScript() } var body: some Scene { WindowGroup { switch script { case .success(let source): EffectAppKitSurface(script: source) .frame(minWidth: 240, minHeight: 140) case .failure(let error): Text("Cannot load main.js: \(error.localizedDescription)") } } } }
close() when dismantled. Changing the script bytes or the identity or order of registrations remounts the surface and starts a fresh model. Reuse registration instances across body evaluations.start(...) or add instrumentation to your components.try surface.updateProps(next) takes a complete Encodable value; updateProps(json:) takes UTF-8 JSON Data. The running start root decodes against its props schema before calling Root.setProps. Invalid input throws without changing the root. Neither a valid update nor a window move reinitializes the component. SwiftUI can supply EffectAppKitSurface(script: script, registrations: registrations, props: jsonData); unchanged bytes are skipped, and nil means “do not send a props update.” Like a mount error, a SwiftUI decoding error replaces the content with an error label.mount(bridge, root, props, options) returns the scoped upstream root; start(root, props, options) owns its scope and returns cleanup. Both forward key, onEmit, fallback, query and head to the pinned Renderer.mount. Props may be an Effect (including asynchronous initialization); scoped mount can receive caller-supplied services, while start provides only the framework environment. start begins immediately. A props update before initialization completes is applied to the root after mount (latest update wins); closing the surface interrupts pending work. An asynchronous mount failure is logged, not thrown retroactively by the Swift initializer.Head.title(...) supplies the containing window’s title, including after attachment or movement to another window. Removing the title or closing restores the prior title if the surface still owns the displayed value. Give just one root in a window this responsibility: pass { head: false } to embedded panels. $.viewTransition() runs the flush once with a short native crossfade; Reduce Motion and unattached surfaces skip animation, not the update. Transition type strings do not select CSS animations.