Ranvier.View.Preview.Traced
0.2.0
dotnet add package Ranvier.View.Preview.Traced --version 0.2.0
NuGet\Install-Package Ranvier.View.Preview.Traced -Version 0.2.0
<PackageReference Include="Ranvier.View.Preview.Traced" Version="0.2.0" />
<PackageVersion Include="Ranvier.View.Preview.Traced" Version="0.2.0" />
<PackageReference Include="Ranvier.View.Preview.Traced" />
paket add Ranvier.View.Preview.Traced --version 0.2.0
#r "nuget: Ranvier.View.Preview.Traced, 0.2.0"
#:package Ranvier.View.Preview.Traced@0.2.0
#addin nuget:?package=Ranvier.View.Preview.Traced&version=0.2.0
#tool nuget:?package=Ranvier.View.Preview.Traced&version=0.2.0
Ranvier.View.Preview
The live component preview of Ranvier.View: the pipe protocol, the knob model and the reflection that the preview host and the editor extension share.
Applications never reference this package. The preview host (Ranvier.View.WebCore.Hmr) loads it from a generated
harness project that lives under .ionide/ranvier/preview/, so nothing is added to an application's own project.
The generated props files reference it too. Preview mode of the
host documents the flags, the exit codes and what a reload keeps.
A props file
A props file defines one Preview: the key of a component and a function that builds its props from knobs.
module RanvierPreview.MyApp_Counter_counter
open Ranvier.View.Preview
let preview: Preview =
Preview.create "MyApp.Counter.counter" (fun p ->
let props: MyApp.Counter.CounterProps =
{ Count = p.Signal("count", Knob.int, 0)
Label = p.Value("label", Knob.string, "") }
Preview.render MyApp.Counter.counter props)
API
Preview
Preview.create key buildmakes aPreviewof the componentkey.buildruns again on each reload, and when a value knob changes.Preview.render definition propsis thePreviewViewof aComponent<'props>mounted withprops.Preview.renderUntypedtakes aTemplateComponentand anobj, for a component that the file cannot name.- A
PreviewViewholds theDefinitionand thePropsthe host mounts.
PreviewContext
The argument of build. Each member names a knob by a path: a record field is parent.field, a union case's field is
parent/Case/field, a function argument is arg:<name>.
| Member | Meaning |
|---|---|
Signal(path, knob, initial) |
A signal knob. The editor writes it in place, and a write by the component reaches the editor. |
Value(path, knob, initial) |
A value knob. Its value is initial until the editor sets it, and a new value runs build again. |
Log(path, args) |
Records a call of the function argument at path, for the editor's log. |
Stylesheet(name, css) |
Registers a named stylesheet. css is read after each run. |
Knob
Knob.int, float, decimal, string, bool and char are the primitive knobs. Knob.cases names is a choice among
named cases. Knob.option, Knob.list and Knob.array take the knob of their element. Knob.readOnly shows a value
that the editor cannot set. A knob carries the codec of its values as JSON text: 5 for an int, "red" with its quotes for a string. A text the
codec refuses gives a reason that quotes it. A knob's value survives a restart of
the host because the editor keeps it and sends it back with restore.
Reflected
Reaches what a generated file cannot name because it is private or internal, by a type's full name:
Reflected.value, Reflected.call, Reflected.record, Reflected.union, Reflected.signal, and
Reflected.ofMembers and Reflected.ofClass, which build a component from a type as Component.ofMembers and
Component.ofClass do. Reflected.resolver finds the type; the host replaces it with one that sees the newest FSI
evaluation. A record, a union case or a call that the values do not fit raises an InvalidOperationException that
names the type and lists the fields, the cases or the signatures it has; a refused value is blamed on its own field.
A type's name is its compiled full name: a module that shares its name with a type is App.CounterModule. A generic
type definition is refused as generic, since Reflected builds closed types only.
PreviewSession
PreviewSession(graph) is what the host builds around a Preview:
Run previewbuilds the preview in a new scope, and disposes the scope of the previous run once the build succeeds. A knob path registered earlier keeps its signal and value when its type is the same. After the run,KnobsandStylesheetslist only what that run registered.Stage previewbuilds the preview asRundoes and keeps the previous run.Committhen disposes the previous run, andRollbackdisposes the staged one and brings the previous one back, with its stylesheets; it givesfalsewhen no run came before the staged one. A host stages a run, mounts its view, and rolls back when the mount fails, so the view it mounts again has live props.StageReset previewstages a run asStagedoes, with every knob at its first value. The previous run keeps its knobs, their values and the restores kept for later runs untilCommitdisposes them;Rollbackbrings them back with the run. A build that throws leaves the knobs as they were. A host resets the preview this way, so a reset whose mount fails leaves the view on live props and knobs.Set(path, json)writes a signal knob, or stores a value knob (the caller runs the preview again). It givesWritten,RebuildorRejected reason.Restoreapplies stored values, and keeps those for a path no run has registered yet.Resetdrops every knob and value.KnobChangedfires when code other thanSetwrote a signal knob.DrainLogtakes the calls logged since the last drain.
Protocol
Ranvier.View.Preview.Protocol is the pipe's wire format, version 1.1: a frame is a 4-byte
little-endian payload length, one byte of kind (0 for UTF-8 JSON, 1 for binary) and the payload,
which is at most 64 MiB (MaxPayload). Frame.encode and FrameReader write and read frames.
- The host's messages.
Hello,Status,Knobs,Knob,LogandFault; for the panel,CursorandClipboard, and binary frames of pixels, whichPixels.encodewrites andPixels.headerreads: a 36-byte header, then the rectangle's RGBA rows. - The editor's messages.
Open,Set,Restore,Reset,Resize,FrontandClose; for the panel,Mouse,Wheel,Key,Focus,Compose,Paste,DrawnandRepaint.
The panel's messages are new in 1.1. The panel of the host says what each does.
Protocol.fs depends on FSharp.Core alone and compiles under .NET and Fable; the package ships it
as a Fable source (fable/Protocol.fs) so the editor extension compiles the same file.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FSharp.Core (>= 8.0.100)
- Ranvier.View.Traced (>= 0.9.0)
-
net8.0
- FSharp.Core (>= 8.0.100)
- Ranvier.View.Traced (>= 0.9.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Ranvier.View.Preview.Traced:
| Package | Downloads |
|---|---|
|
Ranvier.View.WebCore.Hmr.Traced
Hot reload for native Ranvier apps in development: `dotnet run -- dev` keeps the SDL window and WebCore page alive and patches edited components into them, keeping their state. |
GitHub repositories
This package is not used by any popular GitHub repositories.
The API may change before 1.0.