API Reference

Lightview provides a small but powerful API. Everything you need, nothing you don't. Keep it light, remember?

Lightview Overview

Function Description
signal(value) Create reactive state that triggers updates when changed
computed(fn) Derive values from signals automatically
effect(fn) Run side effects when dependencies change
element(tag, attrs, children) Create reactive DOM elements
tags.* Shorthand element creators (div, span, button, etc.)
$(selector) Query the DOM and get an element on which you can call 'insert' to place content before, at the start of, and the end of or after the element.

Lightview X Overview

Lightview X automatically enhances the core Lightview instance when loaded, adding hypermedia capabilities, template literal support, and optional Object DOM syntax.

Feature / Function Description
state(obj) Create deep reactive state for complex objects/arrays. Uses Proxy for automatic change tracking.
src="..." Attribute to automatically fetch HTML or JSON content and inject it into the element.
href="..." Attribute for SPA navigation on any element. Supports targeting other elements via CSS selectors.
${signal.get('count').value}${state.get('user').name} Syntax support for using signals and state directly inside string templates.
enhance(el, opts) Manually enhance an existing DOM element with Lightview reactivity.
registerComponent(name, fn) Register components for use within Object DOM structures.
useObjectDOMSyntax(strict) Enable the Object DOM syntax processor for defining UI with JSON objects.

Using Lightview

<!-- Core only -->
<script src="lightview.js"></script>

<!-- Full power -->
<script src="lightview.js"></script>
<script src="lightview-x.js"></script>
// Destructure what you need from the global instances
const { signal, computed, effect, element, tags, $ } = Lightview;
const { state, enhance, registerComponent } = LightviewX; // Deep state + extras

Core Modules