Your First App
Build a complete, runnable altseven application with views, events and routing.
Install the framework, serve it to the browser, and run your first application.
altseven is a client-side JavaScript framework. It runs in the browser and is typically served by a web server such as NGINX, Apache or Express. You need:
npm install and for running a dev server)Install via npm:
$ npm install altseven
or clone the source from the Peopoli git server:
$ git clone https://git.peopoli.com/code/altseven
Either way, the browser-ready build lives in the dist/ folder:
| File | Purpose |
|---|---|
dist/a7.js |
The framework, as a single ES module |
dist/a7.min.js |
Minified build |
dist/a7.css |
Base styles used by some framework features |
Your application imports the framework with an ES module import, so dist/a7.js
must be reachable from the browser at a stable URL. Two common setups:
npm install — serve node_modules/altseven under an alias, e.g. with
Express:
app.use( "/lib/altseven", express.static( "node_modules/altseven" ) );
git clone / vendored copy — copy (or symlink) the framework folder into your
project so that /lib/altseven/dist/a7.js resolves.
An altseven application needs three things: an HTML page with a mount point, an
Application instance, and a registered view.
Two rules apply from the very first line of code:
new Application( options ) only stores options and sets up logging. The
modules (ui, events, remote, model, …) are created by
await myApp.init() — nothing that uses them may run before that.remote option, even for an app with no back end: at minimum
remote: {}. Without it, init() throws because the remote manager receives
an undefined module list.index.html
<!doctype html>
<html>
<head>
<title>altseven — hello</title>
<script type="module">
import { application } from "./app.js";
application();
</script>
</head>
<body>
<div name="main"></div>
</body>
</html>
app.js
import { Application, View } from "/lib/altseven/dist/a7.js";
export const myApp = new Application( {
name: "hello",
security: { enabled: false },
remote: {}
} );
export async function application() {
try {
// creates the modules; nothing above this line may use myApp.ui etc.
await myApp.init();
const hello = new View( {
id: "hello",
selector: "div[name='main']"
} );
hello.state = { text: " World!" };
hello.template = function() {
return `<h3>Hello ${ hello.state.text }</h3>`;
};
myApp.ui.register( hello );
myApp.log.info( "App initialized." );
} catch( e ) {
console.error( "App init failed:", e );
}
}
Serve the directory (any static server works — just make sure /lib/altseven
resolves) and open the page. You should see Hello World!
$ npx http-server . -p 8417
new Application( options ) created the application shell and normalized the
options. With security: { enabled: false }, no authentication check runs at
startup. (See Configuring Your Application.)await myApp.init() initialized the modules: logging, model, remote, events,
UI manager.new View( props ) created a view with an id, a selector pointing at the
<div name="main"> mount point, a state object, and a template function
returning an HTML string.myApp.ui.register( hello ) registered the view with the UI manager, which
enqueued it for rendering into its selector.As an application grows, the convention is to move views into their own modules
that import the application instance back from app.js:
// hello.js
import { myApp } from "./app.js";
import { View } from "/lib/altseven/dist/a7.js";
export function Hello( props ) {
const hello = new View( props );
// ... state, template, event handlers ...
myApp.ui.register( hello );
return hello;
}
This circular import is safe because the application instance is only used
inside functions, never at module evaluation time — by the time Hello() runs,
app.js has finished evaluating and init() has completed.
Continue with Your First App to build a complete application with events, routing and views.
Build a complete, runnable altseven application with views, events and routing.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.