imp-ui - Imports
Everything imp gives you arrives through a bare specifier that imp resolves for you. In development
it uses the import map imp start injects. In production it uses the bundle imp build produces.
There is nothing to install and nothing to configure.
The library is split by subject, so an import line shows which part of imp a file uses:
| Specifier | What it holds | Page |
|---|---|---|
imp | component, mount, init, env, flag, appMap, interval, delay | Components |
imp/html | el, html, and one factory per HTML tag (div, span, button, ...) | Rendering |
imp/state | initState, useState, computed | State |
imp/router | router, area, redirect, wait, navigate, safeNext, beforeLeave, useRoute, url, screenRegion | Routing |
imp/theme | theme, appliedTheme, applyTheme, colorSchemeOf | Theming |
imp/i18n | t, lang, dir, missingMessages, defaultMessages | Translations |
imp/log | logger, createLogger, setLogLevel, logLevel | Logging |
imp/http | initHttpClient, useHttpClient, createHttpClient, HttpError | HTTP |
imp/icons | luHouse, luUser, luStar, ... from the Lucide icon set | Standard components |
imp/service-worker | startDevMode, precacheBuild, for a service worker of your own | CLI |
imp/analytics | onAnalytics, batch, zone, track | Analytics |
imp/analytics/aly | alySink, a sink that sends the records to your imp-aly servers | Analytics |
imp/std | The standard component library, split by group | Standard components |
imp/test | test, expect, spy, mockModule, and the hooks | Testing |
imp/preview | mockModule, for a *.preview.js file | CLI |
imp/fake | fake, generated data for a mock file, a test or a preview | CLI |
A typical screen imports from the two or three specifiers it uses:
import { component } from 'imp'
import { button, div, h1 } from 'imp/html'
import { initState } from 'imp/state'
Why the library is split
-
The tag factories are most of the surface. One factory per HTML tag is nearly eighty names. They stay behind
imp/html, so the framework itself stays small enough to remember. -
A name can mean two things at two levels.
buttonis a plain<button>fromimp/html, and it is also the styled component fromimp/std. The two never collide, because they arrive through different specifiers, and the import line shows which one a file uses. When a file wants both, give one an alias:import { button } from 'imp/html' import { button as styledButton } from 'imp/std' -
The imports document a file. When you see
imp/routerandimp/stateat the top of a module, you know what the module does before you read a single line.
When you get an import wrong
imp lint catches a name from the wrong specifier, and names the correct one:
error[imp/import-source]: 'div' is not exported by 'imp' - it comes from 'imp/html': import { div } from 'imp/html'
imp lint --fix moves the name to the correct import for you. An imp/... specifier outside the
library fails, and the error lists the real specifiers. A spelling mistake never turns into a
missing module you cannot explain.
Namespace imports
You can also import every subpath as a whole. This reads well for the tag factories, in a file that uses many of them:
import * as h from 'imp/html'
export const card = (title) => h.article(h.h2(title), h.p('...'))