Convert Figma logo to code with AI

yysun logoapprun

AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.

1,175
57
1,175
8

Top Related Projects

37,845

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

19,176

1kB-ish JavaScript framework for building hypertext applications

16,295

:fire: An extremely fast, React-like JavaScript library for building modern user interfaces

14,851

Simple and elegant component-based UI library

30,406

A rugged, minimal framework for composing JavaScript behavior in your markup.

Quick Overview

AppRun is a lightweight JavaScript library for building web applications using the elm-inspired architecture. It combines state management and component-based UI development, offering a simple and efficient way to create reactive web applications with minimal boilerplate code.

Pros

  • Lightweight and fast, with a small footprint (3KB gzipped)
  • Supports both functional and class-based components
  • Integrates well with TypeScript for type-safe development
  • Provides a straightforward and intuitive API for state management

Cons

  • Smaller community compared to more popular frameworks like React or Vue
  • Limited ecosystem of third-party components and plugins
  • May require a learning curve for developers unfamiliar with elm-inspired architecture
  • Documentation could be more comprehensive for advanced use cases

Code Examples

  1. Creating a simple counter component:
import { app, Component } from 'apprun';

const state = 0;
const view = state => <div>
  <h1>{state}</h1>
  <button $onclick="inc">+1</button>
  <button $onclick="dec">-1</button>
</div>;
const update = {
  inc: state => state + 1,
  dec: state => state - 1
};

app.start('app', state, view, update);
  1. Using async actions:
import { app } from 'apprun';

const state = 'Click to fetch';
const view = state => <div>
  <h1>{state}</h1>
  <button $onclick="fetchData">Fetch Data</button>
</div>;
const update = {
  fetchData: async (state) => {
    const response = await fetch('https://api.example.com/data');
    const data = await response.json();
    return data.message;
  }
};

app.start('app', state, view, update);
  1. Creating a class-based component:
import { Component } from 'apprun';

class Counter extends Component {
  state = 0;

  view = state => <div>
    <h1>{state}</h1>
    <button $onclick="inc">+1</button>
    <button $onclick="dec">-1</button>
  </div>;

  update = {
    inc: state => state + 1,
    dec: state => state - 1
  };
}

new Counter().start('app');

Getting Started

To start using AppRun, follow these steps:

  1. Install AppRun using npm:

    npm install apprun
    
  2. Create a new JavaScript or TypeScript file (e.g., app.js or app.ts):

    import { app } from 'apprun';
    
    const state = 'Hello AppRun';
    const view = state => <h1>{state}</h1>;
    const update = {};
    
    app.start('app', state, view, update);
    
  3. Include the AppRun bundle in your HTML file:

    <div id="app"></div>
    <script src="app.js"></script>
    
  4. Run your application using a development server or by opening the HTML file in a browser.

Competitor Comparisons

37,845

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.

Pros of Preact

  • Smaller bundle size (3KB gzipped) compared to AppRun's larger footprint
  • Wider adoption and community support, with more resources and third-party libraries available
  • Closer API compatibility with React, making it easier for developers familiar with React to transition

Cons of Preact

  • Less built-in state management functionality compared to AppRun's integrated state management
  • Fewer out-of-the-box features, requiring additional libraries for routing and other common tasks
  • Steeper learning curve for developers new to React-like frameworks

Code Comparison

AppRun:

import { app, Component } from 'apprun';

class Hello extends Component {
  state = 'AppRun';
  view = state => <h1>Hello {state}</h1>;
}

Preact:

import { h, Component, render } from 'preact';

class Hello extends Component {
  render() {
    return <h1>Hello {this.props.name}</h1>;
  }
}

Both frameworks use a component-based architecture, but AppRun integrates state management more tightly within the component. Preact follows a more React-like approach, separating state and props. AppRun's syntax is slightly more concise, while Preact's may be more familiar to React developers.

19,176

1kB-ish JavaScript framework for building hypertext applications

Pros of Hyperapp

  • Smaller bundle size, leading to faster load times
  • Simpler API with a more focused feature set
  • Better performance for small to medium-sized applications

Cons of Hyperapp

  • Less flexibility for complex state management
  • Smaller ecosystem and community compared to AppRun
  • Limited built-in features, requiring more custom implementations

Code Comparison

AppRun:

import { app, Component } from 'apprun';

class Counter extends Component {
  state = 0;
  view = state => <div>{state}</div>;
  update = {
    '+1': state => state + 1,
    '-1': state => state - 1
  };
}

Hyperapp:

import { h, app } from "hyperapp"

const state = { count: 0 }
const actions = {
  up: state => ({ count: state.count + 1 }),
  down: state => ({ count: state.count - 1 })
}
const view = state => h("div", {}, state.count)

Both frameworks offer a simple way to create components and manage state, but AppRun uses a class-based approach while Hyperapp uses a more functional style. Hyperapp's code is slightly more concise, reflecting its minimalist philosophy.

16,295

:fire: An extremely fast, React-like JavaScript library for building modern user interfaces

Pros of Inferno

  • Higher performance and smaller bundle size compared to React
  • More mature project with larger community and ecosystem
  • Better browser support, including IE9+

Cons of Inferno

  • Steeper learning curve for developers new to virtual DOM concepts
  • Less flexibility in component architecture compared to AppRun's event-driven approach
  • Fewer built-in state management options

Code Comparison

AppRun:

import { app, Component } from 'apprun';

class Hello extends Component {
  state = 'AppRun';
  view = state => <h1>Hello {state}</h1>;
}

Inferno:

import { render } from 'inferno';

function Hello({ name }) {
  return <h1>Hello {name}</h1>;
}

render(<Hello name="Inferno" />, document.getElementById('app'));

Both frameworks offer a component-based approach, but AppRun's syntax is more concise and includes built-in state management. Inferno's syntax is closer to React, which may be more familiar to some developers.

AppRun's event-driven architecture allows for more flexible component communication, while Inferno focuses on high-performance rendering and virtual DOM diffing. The choice between the two depends on project requirements, team expertise, and performance needs.

14,851

Simple and elegant component-based UI library

Pros of Riot

  • Larger community and ecosystem, with more resources and third-party components
  • More mature and battle-tested in production environments
  • Supports server-side rendering out of the box

Cons of Riot

  • Steeper learning curve due to its custom tag syntax and lifecycle methods
  • Larger bundle size compared to AppRun's minimal core
  • Less flexible state management compared to AppRun's event-driven architecture

Code Comparison

Riot component:

<my-component>
  <h3>{ props.title }</h3>
  <p>{ state.message }</p>
  <script>
    export default {
      onMounted() {
        this.update({ message: 'Hello, Riot!' })
      }
    }
  </script>
</my-component>

AppRun component:

import { app, Component } from 'apprun';

class MyComponent extends Component {
  state = { message: '' };
  view = state => <div>
    <h3>{this.props.title}</h3>
    <p>{state.message}</p>
  </div>;
  update = {
    '#': state => ({ message: 'Hello, AppRun!' })
  };
}

Both frameworks offer component-based architecture, but Riot uses a custom tag syntax while AppRun leverages more standard JavaScript. Riot's approach may be more intuitive for designers, while AppRun's structure might appeal more to developers familiar with modern JavaScript practices.

30,406

A rugged, minimal framework for composing JavaScript behavior in your markup.

Pros of Alpine

  • Lightweight and minimal, with a smaller footprint than AppRun
  • Easy to learn and integrate into existing projects
  • More widespread adoption and community support

Cons of Alpine

  • Limited to DOM manipulation and lacks full application architecture
  • Less suitable for complex, large-scale applications
  • Doesn't provide built-in state management capabilities

Code Comparison

Alpine:

<div x-data="{ open: false }">
    <button @click="open = !open">Toggle</button>
    <span x-show="open">Content</span>
</div>

AppRun:

import { app, Component } from 'apprun';

class MyComponent extends Component {
  state = { open: false };
  view = state => <div>
    <button onclick={() => this.run('toggle')}>Toggle</button>
    {state.open && <span>Content</span>}
  </div>;
  update = {
    toggle: state => ({ ...state, open: !state.open })
  };
}

Alpine focuses on enhancing HTML with directives, while AppRun uses a more structured component-based approach with separate state management. Alpine is simpler for small interactions, whereas AppRun provides a full framework for building complex applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

AppRun

AppRun Docs AppRun Playground NPM version Downloads License twitter Discord Chat

⭐ NEW instruction: Step-by-step guide to building a Single Page Application (SPA) using the AppRun pattern, with architectural reasoning for each step:

🕵️ We also have rule / prompt files that you can use with your AI Coding Agent:

🚀 July 2025, We have started to improve the codebase using AI - the spec-driven flow. The requirements, implementation plan and final results are stored in the docs folder.

Introduction

AppRun is a lightweight framework for building web apps. It has a unique architecture inspired by the Elm architecture that can help you manage states, routing, and other essential aspects of your web application, leveraging the power of the event publish-subscribe pattern.

AppRun Benefits

  • Clean architecture that needs minimal setup and boilerplate code.
  • Decoupled architecture that is test friendly.
  • No proprietary syntax to learn (no hooks, no reducers, no signals)
  • State management and routing included
  • Use directly in the browser or with a compiler/bundler
  • Advanced features: JSX, Web Components, Dev Tools, SSR, etc.

Examples

Let's use a Counter as an example to demonstrate the AppRun architecture:

// define the initial state
const state = 0;

// view is a function to display the state (JSX)
const view = state => <div>
  <h1>{state}</h1>
  <button onclick="app.run('-1')">-1</button>
  <button onclick="app.run('+1')">+1</button>
</div>;

// update is a collection of event handlers
const update = {
  '+1': state => state + 1,
  '-1': state => state - 1
};

// start the app
app.start(document.body, state, view, update);

With directives syntax sugar you can write more concise code:

// define the initial state
const state = 0;

// view is a function to display the state (JSX)
const view = state => <div>
  <h1>{state}</h1>
  <button $onclick="-1">-1</button>
  <button $onclick="+1">+1</button>
</div>;

// update is a collection of event handlers
const update = {
  '+1': state => state + 1,
  '-1': state => state - 1
};

// start the app
app.start(document.body, state, view, update);

Alternatively, you can invoke state update functions without events for local state updates:

// define the initial state
const state = 0;

// state update function
const add = (state, value) => state + value;

// view is a function to display the state (JSX)
const view = state => <div>
  <h1>{state}</h1>
  <button $onclick={[add, -1]}>-1</button>
  <button $onclick={[add, 1]}>+1</button>
</div>;

// start the app
app.start(document.body, state, view);

One cool feature of AppRun is that you can use async generator functions for event handlers to return multiple values. AppRun will render each value in the order they are generated.

const state = {};
const view = state => html`
  <div><button @click=${run(getComic)}>fetch ...</button></div>
  ${state.loading && html`<div>loading ... </div>`}
  ${state.comic && html`<img src=${state.comic.img} />`}
`;
async function* getComic() {  // async generator function returns loading flag and then the comic object
  yield { loading: true };
  const response = await fetch('https://xkcd-api.netlify.app');
  const comic = await response.json();
  yield { comic };
}

app.start(document.body, state, view);

And, of course, you can use Components to encapsulate the logic blocks, e.g., SPA pages. Each component can have its own state, view, and update functions. Each component has its own handlers to handle the routing events. AppRun routes /<path>, #<path>, and #/<path> URLs to components. AppRun also does this with hierarchical routing.

class Home extends Component {
  view = () => <div>Home</div>;
  update = {'/, /home': state => state };
}

class Contact extends Component {
  view = () => <div>Contact</div>;
  update = {'/contact': state => state };
}

class About extends Component {
  view = () => <div>About</div>;
  update = {'/about': state => state };
}

const App = () => <>
  <div id="menus">
    <a href="/home">Home</a>{' | '}
    <a href="/contact">Contact</a>{' | '}
    <a href="/about">About</a></div>
  <div id="pages"></div>
</>

app.render(document.body, <App />);
[About, Contact, Home].map(C => new C().start('pages'));

Finally, you can use AppRun with React. The app.use_react function allows you to use React for rendering the view.

import React from 'react'
import ReactDOM from 'react-dom/client'
import app from 'apprun';
use_react(React, ReactDOM);

The app.use_render function allows you to use a other render library for rendering the view. Enjoy the rich ecosystem of React.

import { render } from 'preact'
import app from 'apprun';
app.use_render(render);

There are many more examples and interactive demos available in the AppRun Playground.

Getting Started

AppRun is distributed on npm. To get it, run:

npm install apprun

When you want to do a rapid prototyping or demo, you can use AppRun directly in the browser without JSX or any build step. The app, html and run functions are available globally. The html is a HTML template from lit-html. The run function is a equivalent to the $on directive, which can be used to invoke state update functions.

<html>
<body>
<script src="https://unpkg.com/apprun/dist/apprun-html.js"></script>
<script>
  const add = (state, delta) => state + delta;
  const view = state => {
    return html`<div>
    <h1>${state}</h1>
      <button @click=${run(add, -1)}>-1</button>
      <button @click=${run(add, +1)}>+1</button>
    </div>`;
  };
  app.start(document.body, 0, view);
</script>
</body>
</html>

Or, use the ESM version:

<html>
<body>
<script type="module">
  import { app, html } from 'https://unpkg.com/apprun/dist/apprun-html.esm.js';
  const view = state => html`<div>${state}</div>`;
  app.start(document.body, 'hello ESM', view);
</script>
</body>
</html>

In addition to run directly in the browser, you can run the npm create apprun-app command to create an AppRun project for using a compiler/bundler like Webpack, esbuild or Vite.

npm create apprun-app [my-app]

Learn More

You can read AppRun Docs.

AppRun Book from Apress

Order from Amazon

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.

Contributors

Support

AppRun is an MIT-licensed open-source project. Please consider supporting the project on Patreon. 👍❤️🙏

Thank you for your support

  • Athkahden Asura
  • Alfred Nerstu
  • Gyuri Lajos
  • Lorenz Glißmann
  • Kevin Shi
  • Chancy Kennedy

License

MIT

Copyright (c) 2015-2025 Yiyi Sun

NPM DownloadsLast 30 Days