1 | # Armature
|
2 | ```sh
|
3 | npm install @lpghatguy/armature --save
|
4 | ```
|
5 |
|
6 | Armature 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 |
|
8 | Armature leverages the power of classes, decorators, and template strings to reduce API surface and improve interoperability.
|
9 |
|
10 | ## Requirements
|
11 | Armature releases are compiled to ES5 and should run on any compliant ES5 runtime.
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ### ES6 and TypeScript
|
16 | ```js
|
17 | import { Component } from "armature";
|
18 |
|
19 | console.log(Component) // yay
|
20 | ```
|
21 |
|
22 | ### CommonJS (Node and Browserify)
|
23 | ```js
|
24 | const armature = require("armature");
|
25 | const Component = armature.Component;
|
26 |
|
27 | console.log(Component) // yay
|
28 | ```
|
29 |
|
30 | ### Global
|
31 | Armature is exposed as `armature` when no module system is detected.
|
32 |
|
33 | ```js
|
34 | console.log(armature.Component); // yay
|
35 | ```
|
36 |
|
37 | ## Examples
|
38 | **All examples are written in ES2015 plus decorators, which is also valid TypeScript**
|
39 |
|
40 | Components start with classes that extend Armature's base `Component`. They're decorated to include data about the component.
|
41 |
|
42 | ```ts
|
43 | import { Component, Properties } from "@lpghatguy/armature";
|
44 |
|
45 | const 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 | })
|
54 | class 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 |
|
66 | We can then instantiate and use the component:
|
67 |
|
68 | ```ts
|
69 | const hello = new HelloWorld({
|
70 | name: "Hello, world!"
|
71 | });
|
72 |
|
73 | // reify: manifest this component as an HTML element
|
74 | hello.$reify();
|
75 | document.body.appendChild(hello.$element);
|
76 | ```
|
77 |
|
78 | ## Building
|
79 | Download the source, and then install dependencies and their typings using [typings](https://www.npmjs.com/package/typings):
|
80 |
|
81 | ```sh
|
82 | npm install
|
83 | typings install
|
84 | ```
|
85 |
|
86 | Use `npm run build` to build the source once, or use `npm run dev` to continuously rebuild the source as it changes.
|
87 |
|
88 | Tests can be run on both Node.js and via Karma using `npm test`. |
\ | No newline at end of file |