nandi/frqpublic Fork 0
e20f5ab18600ed3639ac883cb91c590ab278724c
Commits
Clone
git clone https://git.rickub.com/nandi/frq.git
git clone ssh://git@rickub.com/nandi/frq.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

host_js.dart · 56 lines · 2.0 KBDart Blame HistoryRaw
A web version, from the same core 23846db nandi 12h ago1/// The web half of the seam: the same core, compiled by `nim js`.
2///
3/// `nim/web/frq_web.nim` puts one object on `globalThis` and these are its
4/// methods. No pointers and nothing to free — a string is a string — so this
5/// file is short where `host_ffi.dart` is careful.
6///
7/// The functions that are not here in spirit are the ones a browser has no
8/// business calling: the socket is JavaScript's on this target, opened by the
9/// page rather than by Dart, so `connOpenAt` and its neighbours throw rather
10/// than pretend. They are reached only by the native tests and by
11/// `tool/live_ui.dart`.
12library;
13
14import 'dart:js_interop';
15
16@JS('frq')
17external _Frq get _frq;
18
19@JS()
20@staticInterop
21class _Frq {}
22
23extension on _Frq {
24 external JSString render();
25 external JSString dispatch(JSString event);
26 external void demo();
27 external void trace(JSBoolean on);
28}
29
30String? uiRender() => _frq.render().toDart;
31
32/// The same call as [uiRender]. There is no cheaper "has anything changed?"
33/// on this side either — the core drains its queue and builds a tree, and the
34/// comparison that saves the work happens a layer up, on the JSON.
35String? uiPoll() => _frq.render().toDart;
36
37String? uiDispatch(String event) => _frq.dispatch(event.toJS).toDart;
38
39void uiDemo() => _frq.demo();
40
41void uiReset() => _frq.dispatch('{"id":"reset"}'.toJS);
42
43String hostVersion() => 'js';
44
45Never _notHere(String what) => throw UnsupportedError(
46 '$what is not available in the browser build: the page owns the socket '
47 'and the core is reached through globalThis.frq');
48
49String? str1(String symbol, String arg) => _notHere(symbol);
50String? tagValueOf(String tags, String key) => _notHere('tag values');
51void traceTo(String topic, String msg) => _frq.trace(true.toJS);
52void connOpenAt(String host, int port, bool tls) => _notHere('connOpen');
53void connSendLine(String line) => _notHere('connSend');
54void connCloseNow() => _notHere('connClose');
55String? connRecvLine() => _notHere('connRecv');
56String? connEventNext() => _notHere('connEvent');