0.3.3 • Published 5 years ago

jetstart v0.3.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

jetstart

Small, simple, functional JavaScript library for building web interfaces.

Jetstart integrates lit-html, page.js, and statezero.

See the jetstart-boilerplate project to get started.

Getting Started

Install from npm.

npm install jetstart --save

Jetstart is packaged using the Universal Module Definition pattern, so it can be loaded in various environments:

Browser Global

<script src="./node_modules/jetstart/dist/jetstart.js"></script>
<script>
  const { action, router, view } = window.jetstart;
</script>

ES6 Module

import { action, router, view } from 'jetstart';

Node

const { action, router, view } = require('jetstart');

Concepts

Views

Views are invoked with a context argument, which can be destructured like so:

view(({ render, state }) => render`${state}`);

The context object contains all of the names exported by lit-html, including all of its directives, as well as a few Jetstart-specific properties:

NameTypeDescription
htmlFunctionWraps lit-html's html() to add support for Jetstart views
renderFunctionViews in jetstart typically return the result of calling render on a tagged template literal
repeatViewFunctionLike repeat, but called with a function that returns a view instead of a template
state  ObjectThe result of calling statezero's getState() function

Views can also accept arbitrary parameters, such as the text parameter of the span view below:

import { renderView, view } from 'jetstart';

const span = view(({ render }, text) => render`<span>${text}</span>`);

const header = view(({ render }, left, right) => render`<h1>${span(left)} ${span(right)}</h1>`);

renderView(header('hello', 'world'), document.body);

See lit-html for more information.

State

Jetstart uses statezero to manage a single, global, immutable state graph. Changes to state can be applied by calling commit(newState), which causes all views to be (efficiently) re-rendered.

import { action, renderView, view } from 'jetstart';

const time = view(({ render, state }, placeholder) => render`<time>${state.time || placeholder}</time>`);

const updateTime = action(({ commit, state }) => {
  state.time = new Date();
  commit(state);
});

renderView(time('Loading...'), document.body);

setInterval(updateTime);

See statezero for more information.

Routing

import { router, view } from 'jetstart';

const foo = view(({ render }) => render`<h1>foo</h1><a href="/bar">bar</a>`);

const bar = view(({ render }) => render`<h1>bar</h1><a href="/foo">foo</a>`);

router(document.body, ['/', '/foo'], ['/foo', foo], ['/bar', bar]).start();

See page.js for more information.

Developing

npm install
npm run build
0.3.3

5 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.3-1

6 years ago

0.0.2

6 years ago

0.0.1-rc1

6 years ago

0.0.1

6 years ago