| A web version, from the same core 23846db nandi 14h ago | 1 | /// 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`. |
| 12 | library; |
| 13 | |
| 14 | import 'dart:js_interop'; |
| 15 | |
| 16 | @JS('frq') |
| 17 | external _Frq get _frq; |
| 18 | |
| 19 | @JS() |
| 20 | @staticInterop |
| 21 | class _Frq {} |
| 22 | |
| 23 | extension on _Frq { |
| 24 | external JSString render(); |
| 25 | external JSString dispatch(JSString event); |
| 26 | external void demo(); |
| 27 | external void trace(JSBoolean on); |
| 28 | } |
| 29 | |
| 30 | String? 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. |
| 35 | String? uiPoll() => _frq.render().toDart; |
| 36 | |
| 37 | String? uiDispatch(String event) => _frq.dispatch(event.toJS).toDart; |
| 38 | |
| 39 | void uiDemo() => _frq.demo(); |
| 40 | |
| 41 | void uiReset() => _frq.dispatch('{"id":"reset"}'.toJS); |
| 42 | |
| 43 | String hostVersion() => 'js'; |
| 44 | |
| 45 | Never _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 | |
| 49 | String? str1(String symbol, String arg) => _notHere(symbol); |
| 50 | String? tagValueOf(String tags, String key) => _notHere('tag values'); |
| 51 | void traceTo(String topic, String msg) => _frq.trace(true.toJS); |
| 52 | void connOpenAt(String host, int port, bool tls) => _notHere('connOpen'); |
| 53 | void connSendLine(String line) => _notHere('connSend'); |
| 54 | void connCloseNow() => _notHere('connClose'); |
| 55 | String? connRecvLine() => _notHere('connRecv'); |
| 56 | String? connEventNext() => _notHere('connEvent'); |