solid-fuse

Communicating with Dart

Send messages between JS and Dart with channels

Channels are a simple messaging system for communication outside the widget tree. Use them for analytics, auth, native API calls, background tasks — anything that doesn't map to a widget or controller.

Sending messages to Dart

import { send } from "solid-fuse";

send("analytics", { event: "page_view", page: "home" });

On the Dart side, register a handler:

runtime.channels.on('analytics', (data) {
  Analytics.track(data['event'], data['page']);
});

Receiving messages from Dart

import { on } from "solid-fuse";

on("auth:token", (data) => {
  setToken(data.token);
});

The Dart side sends:

await runtime.channels.send('auth:token', {'token': jwt});

Complete example: auth flow

JS side
import { createSignal } from "solid-js";
import { send, on } from "solid-fuse";

const [token, setToken] = createSignal<string | null>(null);
const [error, setError] = createSignal<string | null>(null);

// Listen for auth responses
on("auth:success", (data) => setToken(data.token));
on("auth:error", (data) => setError(data.message));

function login(email: string, password: string) {
  send("auth:login", { email, password });
}
Dart side
runtime.channels.on('auth:login', (data) async {
  try {
    final token = await AuthService.login(
      data['email'] as String,
      data['password'] as String,
    );
    runtime.channels.send('auth:success', {'token': token});
  } catch (e) {
    runtime.channels.send('auth:error', {'message': e.toString()});
  }
});

Channels vs controllers

ChannelsControllers
PatternFire-and-forget messagesPersistent object with state
LifecycleGlobal, no cleanup neededTied to component lifecycle
StateNo built-in reactivityReactive signals (e.g. scrollOffset())
Use forEvents, one-off requestsOngoing imperative control

Use channels when you need to send a message. Use controllers when you need a persistent native object you can call methods on and read state from.

Reserved channels

Channel names starting with _ are reserved for Fuse internals (_ops, _functionCall, _ws). Use your own names for app channels.

On this page