AppRun is a JavaScript library for building reliable, high-performance web applications using the Elm inspired Architecture, events, and components.
AppRun is an MIT-licensed open source project. Please consider supporting the project on Patreon. ๐โค๏ธ๐
- Write less code
- No proprietary syntax to learn
- Compiler/transpiler is optional
- State management and routing included
- Run side-by-side with jQuery, chartjs, D3, lit-html ...
Applications built with AppRun have ** fewer lines of code**, smaller js files, and better performance. See a comparison from A Real-World Comparison of Front-End Frameworks with Benchmarks (2019 update). You can also see the performance results compared to other frameworks and libraries in the js-framework-benchmark project.
Application logic is broken down into three separate parts in the AppRun architecture.
- State (a.k.a. Model) โ the state of your application
- View โ a function to display the state
- Update โ a collection of event handlers to update the state
AppRun ties the three parts together and drives the applications using events.
AppRun is distributed on npm.
npm install apprun
You can also load AppRun directly from the unpkg.com CDN:
<script src="https://unpkg.com/apprun/dist/apprun-html.js"></script>
Or use it as ES module from unpkg.com:
<script type="module">
import { app, Component } from 'https://unpkg.com/apprun@next/esm/apprun-html?module';
</script>
Below is a counter application using AppRun (Online Demo).
<html>
<head>
<meta charset="utf-8">
<title>Counter</title>
</head>
<body>
<script src="https://unpkg.com/apprun/dist/apprun-html.js"></script>
<script>
const state = 0;
const view = state => {
return `<div>
<h1>${state}</h1>
<button onclick='app.run("-1")'>-1</button>
<button onclick='app.run("+1")'>+1</button>
</div>`;
};
const update = {
'+1': state => state + 1,
'-1': state => state - 1
};
app.start(document.body, state, view, update);
</script>
</body>
</html>
Below is a counter web component using AppRun as ES module (Online Demo).
<html>
<head>
<meta charset="utf-8">
<title>Counter Web Component</title>
</head>
<body>
<wc-lit-html></wc-lit-html>
<script type="module">
import { app, Component, html } from 'https://unpkg.com/apprun@next/esm/apprun-html?module';
class Counter extends Component {
state = 0;
view = (state) => html`<div>
<h1>${state}</h1>
<button @click=${()=>this.run("add", -1)}>-1</button>
<button @click=${()=>this.run("add", +1)}>+1</button>
</div>`;
update =[
['add', (state, n) => state + n]
]
}
app.webComponent('wc-lit-html', Counter);
</script>
</body>
</html>
We recommend using TypeScript and JSX. TypeScript provides strong typing. JSX provides more advanced features. For examples:
import app from 'apprun';
import * as d3 from 'd3';
import * as topojson from 'topojson';
const map = ({ datum }) => { /* D3 logic */};
const state = d3.json('world-110m.json').then(world => ({
datum: topojson.feature(world, world.objects.land)
}));
const view = state => <svg id="svg" ref={() => map(state)}></svg>;
const view = state => {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
state.chart = new Chart(ctx, state.data);
return (
<Card header={<div>Chart JS</div>}>
<div>{canvas}</div>
</Card>
);
};
app.on('$', ({key, props}) => {
if (key === '$animation') {
const value = props[key];
if (typeof value === 'string') {
props.class = `animated ${value}`;
}
}
});
const view = () => <>
<img $animation={'bounce infinite'} src='logo.png' />
Try the AppRun Playground to see more examples.
Use the AppRun CLI to initialize a TypeScript and webpack configured project:
npx apprun --init
npm start
You can also initialize a SPA project.
npx apprun --init --spa
To initialize a project that targets ES5, use the AppRun CLI with the --es5 flag:
npx apprun --init --spa --es5
Optionally, you can directly scaffold AppRun projects from the AppRun starter templates.
npx degit apprunjs/apprun-rollup my-app
npx degit apprunjs/apprun-rollup-lit-html my-app
npx degit apprunjs/apprun-webpack my-app
npx degit apprunjs/apprun-parcel my-app
npx degit apprunjs/apprun-web-components my-app
npx degit apprunjs/apprun-bootstrap my-app
npx degit apprunjs/apprun-coreui my-app
npx degit apprunjs/apprun-pwa my-app
npx degit apprunjs/apprun-pwa-workbox my-app
npx degit yysun/apprun-d3 my-app
npx degit yysun/apprun-electron my-app
npx degit yysun/apprun-electron-forge my-app
npx degit yysun/apprun-websockets my-app
npx degit yysun/apprun-websockets-sqlite my-app
In the past, the AppRun default version on npm is 1.x. The CLI creates tsconfig for es5. You can use --es6 option to create tsconfig for 2.x.
On Feb 21, 2020, the default version on npm has been changed from 1.x to 2.x. And the CLI creates tsconfig for es2015. You can use --es5 option for 1.x.
When upgrading projects to the latest version (2.x), please modify the tsconfig from targeting es5 to es2015.
Currently, the npm tags are as following:
- apprun@es5: 1.x, stable, es5
- apprun@latest: 2.x, stable, es2015, web components
- apprun@next: 3.x, dev, es2015, web components, lit-html
AppRun CLI also runs in the console.
To use the AppRun dev-tools CLI, include the dev-tools script.
<script src="https://unpkg.com/apprun@latest/dist/apprun-dev-tools.js"></script>
AppRun supports the Redux DevTools Extension. To use the dev-tools, install the Redux DevTools Extension. You can monitor the events and states in the devtools.
AppRun has a code snippet extension for VS Code that you can install from the extension marketplace. It inserts the AppRun code template for application, component and event handling.
You can launch the webpack dev-server and the demo app from the demo folder with the following npm commands:
npm install
npm start
You can run the unit tests from the tests folder.
npm test
Unit tests can serve as functional specifications.
Finally, to build optimized js files to the dist folder, just run:
npm run build
Have fun and send pull requests.
MIT
Copyright (c) 2015-2020 Yiyi Sun