UNPKG

2.21 kBMarkdownView Raw
1# Armature
2```sh
3npm install @lpghatguy/armature --save
4```
5
6Armature is a modern component model targeted at TypeScript and ES2015+ workflows. It runs in browsers and servers alike, allowing for a full-featured isomorphic view system without the complexity of larger frameworks.
7
8Armature leverages the power of classes, decorators, and template strings to reduce API surface and improve interoperability.
9
10## Requirements
11Armature releases are compiled to ES5 and should run on any compliant ES5 runtime.
12
13## Usage
14
15### ES6 and TypeScript
16```js
17import { Component } from "armature";
18
19console.log(Component) // yay
20```
21
22### CommonJS (Node and Browserify)
23```js
24const armature = require("armature");
25const Component = armature.Component;
26
27console.log(Component) // yay
28```
29
30### Global
31Armature is exposed as `armature` when no module system is detected.
32
33```js
34console.log(armature.Component); // yay
35```
36
37## Examples
38**All examples are written in ES2015 plus decorators, which is also valid TypeScript**
39
40Components start with classes that extend Armature's base `Component`. They're decorated to include data about the component.
41
42```ts
43import { Component, Properties } from "@lpghatguy/armature";
44
45const template = (component) => `
46 We have this name: ${ component.$data.name }
47 <button class="alert">Alert!</button>
48`;
49
50@Properties({
51 tag: "hello-world",
52 template: template
53})
54class HelloWorld extends Component {
55 $hydrate() {
56 super.$hydrate();
57
58 const button = this.$element.querySelector("button.alert");
59 button.addEventListener("click", e => {
60 alert("The alert button was pressed!");
61 });
62 }
63}
64```
65
66We can then instantiate and use the component:
67
68```ts
69const hello = new HelloWorld({
70 name: "Hello, world!"
71});
72
73// reify: manifest this component as an HTML element
74hello.$reify();
75document.body.appendChild(hello.$element);
76```
77
78## Building
79Download the source, and then install dependencies and their typings using [typings](https://www.npmjs.com/package/typings):
80
81```sh
82npm install
83typings install
84```
85
86Use `npm run build` to build the source once, or use `npm run dev` to continuously rebuild the source as it changes.
87
88Tests can be run on both Node.js and via Karma using `npm test`.
\No newline at end of file