API Reference
Complete reference for Inglorious Web's public API.
createStore(config)
Creates a new store instance.
Parameters
interface StoreConfig {
types: Record<string, TypeDefinition>
entities?: Record<string, Entity>
middlewares?: Middleware[]
autoCreateEntities?: boolean
}
2
3
4
5
6
Returns
interface Store {
entities: Record<string, Entity>
getEntity(id: string): Entity | undefined
getEntities(): Record<string, Entity>
getEntities(type: string): Entity[]
render(entity: string | Entity): TemplateResult
notify(event: string, payload?: any): void
update(entity: Entity, fn: UpdateFn): void
subscribe(callback: (store: Store) => void): () => void
}
2
3
4
5
6
7
8
9
10
Example
const store = createStore({
types: {
counter: {
increment: (entity) => {
entity.count++
},
render: (entity, api) => html`...`,
},
},
entities: {
counter: { type: "counter", count: 0 },
},
})
2
3
4
5
6
7
8
9
10
11
12
13
Type Definition
interface TypeDefinition {
create?(entity: Entity, payload?: any, api?: API): void | Promise<void>
render?(entity: Entity, api?: API): TemplateResult | null
destroy?(entity: Entity, api?: API): void
[eventName: string]: EventHandler | undefined
}
type EventHandler = (
entity: Entity,
payload?: any,
api?: API,
) => void | Promise<void>
2
3
4
5
6
7
8
9
10
11
12
Event Naming
// Broadcast event (all types)
api.notify("eventName")
// Targeted to type
api.notify("#typeName:eventName")
// Targeted to specific entity
api.notify("#typeName#entityId:eventName")
// Legacy: type#id
api.notify("typeName#entityId:eventName")
2
3
4
5
6
7
8
9
10
11
API Object
Passed as second argument to handlers and render methods.
Methods
render(entity)
Render an entity to HTML. It is just a convenience method that allows to avoid invoking the render method of a type directly:
// Rendering the header entity...
api.render("header")
// is the same as:
header.render(api.getEntity("header"), api)
2
3
4
5
getEntity(id)
Get entity by ID.
const user = api.getEntity("user")
getEntities(type?)
Get entities from state.
// Full entities map
const allEntities = api.getEntities()
// Filter by type
const todos = api.getEntities("todo")
2
3
4
5
select(selector)
Run a selector against the current state.
const activeFilter = (state) => state.toolbar.activeFilter
const filter = api.select(activeFilter)
2
notify(event, payload)
Dispatch an event.
api.notify("#counter:increment", 5)
api.notify("#form:submit", { email: "user@example.com" })
2
dispatch(action)
Dispatch an event, Redux-style.
api.dispatch({ type: "#counter:increment", payload: 5 })
api.dispatch({ type: "#form:submit", payload: { email: "user@example.com" } })
2
Directives
Template literals for special handling, borrowed from lit-html.
when(condition)
Conditional rendering.
html`
${when(entity.isOpen, () => html`<div>Open</div>`)}
${when(!entity.isOpen, () => html`<div>Closed</div>`)}
`
2
3
4
repeat(items, fn)
List rendering with key-based diffing.
html`
<ul>
${repeat(
entity.todos,
(item) => item.id,
(item) => html` <li>${item.title}</li> `,
)}
</ul>
`
2
3
4
5
6
7
8
9
unsafeHTML(html)
Raw HTML (use with caution).
html`<div>${unsafeHTML(entity.richText)}</div>`
mount(store, renderFn, container)
Mount the app to the DOM.
Parameters
store— Store instancerenderFn— Function returning TemplateResultcontainer— DOM element
Example
mount(store, (api) => api.render("app"), document.getElementById("root"))
Utilities
trigger(store, entity, event, payload)
Dispatch event and wait for completion (testing).
await trigger(store, todo, "toggle")
assert.equal(todo.completed, true)
2
render(store, entity)
Render entity to string (testing).
const html = await render(store, todoItem)
assert.include(html, "Buy milk")
2
compute(fn, inputs)
Memoize expensive computation.
const total = compute(
() => items.reduce((sum, item) => sum + item.price, 0),
[items],
)
2
3
4
Middleware
Intercept and modify events.
interface Middleware {
(store: Store, event: Event): Event | null
}
interface Event {
type: string
targetType?: string
targetId?: string
payload?: any
}
2
3
4
5
6
7
8
9
10
Example
const loggingMiddleware = (store, event) => {
console.log("Event:", event.type, event.payload)
return event // Always return event
}
const store = createStore({
types,
middlewares: [loggingMiddleware],
})
2
3
4
5
6
7
8
9
Built-in Components
Router
interface RouterConfig {
routes: {
[path: string]: ComponentDef
}
notFound?: ComponentDef
}
interface RouterEntity {
currentPath: string
params: Record<string, string>
}
// Usage
const router = {
routes: {
"/": Home,
"/about": About,
"/:id": Detail,
},
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Form
interface FormConfig {
initialValues: Record<string, any>
onSubmit: (values) => void | Promise<void>
validate?: (values) => Record<string, string>
}
interface FormEntity {
values: Record<string, any>
errors: Record<string, string>
touched: Record<string, boolean>
isSubmitting: boolean
isDirty: boolean
}
2
3
4
5
6
7
8
9
10
11
12
13
Table
interface TableConfig {
data: any[]
columns: ColumnDef[]
onRowClick?: (row: any) => void
}
interface ColumnDef {
key: string
label: string
format?: (value: any) => string
}
2
3
4
5
6
7
8
9
10
11
Select
interface SelectConfig {
options: SelectOption[]
value?: any | any[]
multiple?: boolean
searchable?: boolean
}
interface SelectOption {
value: any
label: string
disabled?: boolean
}
2
3
4
5
6
7
8
9
10
11
12
Virtual List
interface ListConfig {
items: any[]
renderItem: (item: any) => TemplateResult
itemHeight: number
bufferSize?: number
}
2
3
4
5
6
Environment Variables
import.meta.env.DEV
Is development mode.
if (import.meta.env.DEV) {
console.log("Debug info")
}
2
3
import.meta.env.PROD
Is production mode.
if (import.meta.env.PROD) {
// Enable analytics
}
2
3
TypeScript
Entity Type
interface Entity {
type: string
[key: string]: any
}
2
3
4
Template Result
type TemplateResult = import("lit-html").TemplateResult
Update Function
type UpdateFn<T extends Entity = Entity> = (draft: Draft<T>) => void
Packages
Core Packages
- @inglorious/web — Main package (Web + Store)
- @inglorious/store — State management only
- @inglorious/jsx — JSX support
- @inglorious/vite-plugin-jsx — Vite JSX plugin
Related Packages
- @inglorious/engine — Game framework
- @inglorious/ssx — Static site generation
- @inglorious/vite-plugin-vue — Vue template support
- @inglorious/create-app — Scaffolding tool
Changelog
See CHANGELOG.md for version history and breaking changes.
Migration Guides
- React → Inglorious Web — View comparison
Related
- Guide — Getting started guide
- Featured Types — Built-in types documentation
- Advanced — Advanced patterns
Need help? Report an issue or ask on discussions.
Inglorious Web