Getting Started

Install altseven and run a minimal application.

Install the framework, serve it to the browser, and run your first application.

Prerequisites

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:

  • Node.js (for npm install and for running a dev server)
  • A modern browser with ES module support

Installation

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

Serve the framework to the browser

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.

A minimal application

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:

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

What just happened?

  1. 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.)
  2. await myApp.init() initialized the modules: logging, model, remote, events, UI manager.
  3. 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.
  4. myApp.ui.register( hello ) registered the view with the UI manager, which enqueued it for rendering into its selector.

Organizing larger applications

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.


Your First App

Build a complete, runnable altseven application with views, events and routing.