nandi/frqpublic Fork 0
627b785fbf6cef0c29d54b82a1ffb5e870ca9f51
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.

A web version, from the same core 23846db · on 627b785fbf6cef0c29d54b82a1ffb5e870ca9f51 · nandi · 12h ago
host_js.dart · 56 lines · 2.0 KBDart Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/// The web half of the seam: the same core, compiled by `nim js`.
///
/// `nim/web/frq_web.nim` puts one object on `globalThis` and these are its
/// methods. No pointers and nothing to free — a string is a string — so this
/// file is short where `host_ffi.dart` is careful.
///
/// The functions that are not here in spirit are the ones a browser has no
/// business calling: the socket is JavaScript's on this target, opened by the
/// page rather than by Dart, so `connOpenAt` and its neighbours throw rather
/// than pretend. They are reached only by the native tests and by
/// `tool/live_ui.dart`.
library;

import 'dart:js_interop';

@JS('frq')
external _Frq get _frq;

@JS()
@staticInterop
class _Frq {}

extension on _Frq {
  external JSString render();
  external JSString dispatch(JSString event);
  external void demo();
  external void trace(JSBoolean on);
}

String? uiRender() => _frq.render().toDart;

/// The same call as [uiRender]. There is no cheaper "has anything changed?"
/// on this side either — the core drains its queue and builds a tree, and the
/// comparison that saves the work happens a layer up, on the JSON.
String? uiPoll() => _frq.render().toDart;

String? uiDispatch(String event) => _frq.dispatch(event.toJS).toDart;

void uiDemo() => _frq.demo();

void uiReset() => _frq.dispatch('{"id":"reset"}'.toJS);

String hostVersion() => 'js';

Never _notHere(String what) => throw UnsupportedError(
    '$what is not available in the browser build: the page owns the socket '
    'and the core is reached through globalThis.frq');

String? str1(String symbol, String arg) => _notHere(symbol);
String? tagValueOf(String tags, String key) => _notHere('tag values');
void traceTo(String topic, String msg) => _frq.trace(true.toJS);
void connOpenAt(String host, int port, bool tls) => _notHere('connOpen');
void connSendLine(String line) => _notHere('connSend');
void connCloseNow() => _notHere('connClose');
String? connRecvLine() => _notHere('connRecv');
String? connEventNext() => _notHere('connEvent');