Home Reference Source

flatout

Lightweight Single-Page-Application framework for JavaScript

Concepts

Features

Provides Classes

Document

https://tilfin.github.io/flatout/

Setup

$ npm install -save @tilfin/flatout

Generate documents

$ npm run doc

Start example apps

$ npm run example

Routing

Support 2 type

Specify the root path by the base tag if it isn't /. ex) <base href="/<root path>/">

Plain data or event handling

Plain data

Plain data is an Object or an Array.

Data with binding views

Use Application

History mode

<!DOCTYPE html>
<html>
<head>
<title>History mode</title>
<base href="/app/">
</head>
<body>
<nav><a href="about">About</a></nav>
<main id="frame">
<!-- content area -->
</main>
<script type="module">
import { App, Page, View } from 'flatout.js'

class MainView extends View {
  constructor() {
    super(document.body, { container: 'frame' })
  }
}

const routeMap = {
  index: HomePage,   // /
  about: AboutPage,  // /about
  ':userId': UserPage  // /:userId
}

App.activate(MainView, routeMap, { mode: 'HISTORY' })
</script>
</body>
</html>

Hash mode

<!DOCTYPE html>
<html>
<head>
<title>Hash mode</title>
</head>
<body>
<nav><a href="#!/about">About</a></nav>
<main id="frame">
<!-- content area -->
</main>
<script type="module">
import { App, Page, View } from 'flatout.js'

class MainView extends View {
  constructor() {
    super(document.body, { container: 'frame' })
  }
}

const routeMap = {
  index: HomePage,       // /
  about: AboutPage,      // /about
  books: {
    index: BookListPage, // /books/
    ':bookId': BookPage, // /books/:bookId
  }
}

App.activate(MainView, routeMap, { mode: 'HASH' })
</script>
</body>
</html>