Code Monkey home page Code Monkey logo

apprun's Introduction

AppRun Build NPM version Downloads License twitter Discord Chat

AppRun is a 3K library for building reliable, high-performance web applications using the Elm inspired Architecture, event pub-sub and components.

AppRun is a MIT-licensed open source project. Please consider supporting the project on Patreon. ๐Ÿ‘โค๏ธ๐Ÿ™

Architecture Concept

Application logic is broken down into three separated 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 event pub-sub.

Applications built with AppRun have less 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.

AppRun Book from Apress

Order from Amazon

Quick Start

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@latest/dist/apprun-html.js"></script>
  <div id="my-app"></div>
  <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('my-app', state, view, update);
  </script>
</body>
</html>

Web Components

Using apprun@es6, you can convert AppRun components into web components. AppRun components become the custom elements that also can handle AppRun events (Online Demo).

<html>
<head>
  <meta charset="utf-8">
  <title>Counter as web component</title>
</head>
<body>
  <my-app id='counter'></my-app>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/custom-elements/1.1.2/custom-elements.min.js"></script>
  <script src="https://unpkg.com/apprun@es6/dist/apprun-html.js"></script>
  <script>
    class Counter extends Component {
      constructor() {
        super();
        this.state = 0;
        this.view = state => `<div>
          <h1>${state}</h1>
          <button onclick='counter.run("-1")'>-1</button>
          <button onclick='counter.run("+1")'>+1</button>
          </div>`;
        this.update = {
          '+1': state => state + 1,
          '-1': state => state - 1
        };
      }
    }
    app.webComponent('my-app', Counter);
  </script>
</body>
</html>

Install

You can include AppRun in your html directly and use it with JavaScript.

<script src="https://unpkg.com/apprun@latest/dist/apprun-html.js"></script>

CLI

Or you can use AppRun with TypeScript and Webpack. Use the AppRun CLI to initialize a TypeScript and webpack configured project:

npx apprun --init --spa
npm start

To initialize a project that targets ES6/ES2015, use the AppRun CLI with the --es6 flag:

npx apprun --init --spa --es6
npm start

Dev-Tools

To use the AppRun dev-tools, include the the dev-tools script.

<script src="https://unpkg.com/apprun@latest/dist/apprun-dev-tools.js"></script>

Then install the Redux DevTools Extension. You can monitor the events and states in the devtools.

app-dev-tools

VS Code Extension

AppRun has a code snippet extension for VS Code that you can install from the extension marketplace. It inserts AppRun code template for application, component and event handling.

app-dev-tools

Documentation

To explore more about AppRun, read the following.

Video Tutorials

Articles

Examples

Online Demos

See Examples Online @glitch.com and @stackblitz.com

Contribute

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.

License

MIT

Copyright (c) 2015-2019 Yiyi Sun

apprun's People

Contributors

ericsun-brps avatar ludmiloff avatar mnorrish avatar phbalance avatar roa-nyx avatar sebring avatar vitorluizc avatar yysun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.