@sigx/lynx-runtime
v0.2.6
Published
Lynx renderer for SignalX (background thread)
Readme
@sigx/lynx-runtime
Background-thread renderer for SignalX on Lynx. Translates sigx component output into the BG → MT op stream that drives the native render tree.
Most apps should depend on
@sigx/lynxinstead, which re-exports this package's public surface alongside@sigx/reactivityand@sigx/runtime-corefor a single import path.
Responsibilities
render/lynxMount— boot the BG renderer against alynx.getJSContext()-style host.nodeOps— sigxRuntimeRendereradapter that turns vnode operations into op-queue entries.- Op queue —
pushOp,scheduleFlush,takeOps,flushNow— the wire protocol carrying renders from BG to MT. - Main-thread refs —
MainThreadRef,useMainThreadRef— the BG-side handle whose.currentvalue lives on the main thread; the build pipeline serializes these into worklet captures via their_wvid. - Cross-thread bridges —
runOnMainThread(BG→MT one-shot),runOnBackground(MT→BG dispatch handle),transformToWorklet(handle → JsFn marshal). - AnimatedValue BG sink —
registerBgSink,unregisterBgSink,ingestAvPublishes— receive MT-publishedAnimatedValuewrites into asignal-backed mirror soeffect(() => av.value)re-runs reactively. The producer side lives in@sigx/gestures; the MT side lives in@sigx/lynx-runtime-main. - JSX types —
MainThread,Define,ViewAttributes, etc.
Wire protocol
Ops are flat-array tuples produced on BG and consumed on MT. The op codes (CREATE, INSERT, SET_STYLE, SET_WORKLET_EVENT, INIT_MT_REF, REGISTER_AV_BRIDGE, ...) are defined in @sigx/lynx-runtime-internal so both sides stay in sync.
A typical batch:
[OP.CREATE, 1, 'view',
OP.SET_STYLE, 1, { width: '100px', height: '100px' },
OP.INSERT, 0, 1, -1,
OP.INIT_MT_REF, 7, null,
OP.SET_MT_REF, 1, 7]Serialized to JSON, shipped via lynx.getNativeApp().callLepusMethod('sigxPatchUpdate', { data }), applied by the MT runtime in @sigx/lynx-runtime-main.
Background event bridge
bg-bridge.ts listens on lynx.getCoreContext() for two MT-originated event types:
Lynx.Sigx.PublishEvent— hybrid worklet → BG event handler dispatch (<view bindtap={…}>style).Lynx.Sigx.AvPublish— coalescedAnimatedValuewrite batches; routed intoingestAvPublishes.
License
MIT
