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,178
57
1,178
9

Top Related Projects

36,692

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

19,062

1kB-ish JavaScript framework for building hypertext applications

16,083

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

14,820

Simple and elegant component-based UI library

27,910

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

36,692

⚛️ 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,062

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,083

: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,820

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.

27,910

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 Build NPM version Downloads License twitter Discord Chat

Introduction

AppRun is a lightweight alternative to other frameworks and libraries. 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.

Use a Counter as an example.

// 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);

  • AppRun is lightweight, only 6KB gzipped, but includes state management, rendering, event handling, and routing.

  • With only three functions: app.start, app.run, and app.on in its API makes it easy to learn and use. And no worries about the incompatibility of version upgrades.

  • One more thing, you can use AppRun with React to simplify state management and routing of your React applications.

At its core, AppRun harnesses the power of the event PubsSub pattern to streamline your application’s state handling and routing. The result? Cleaner, more maintainable code and a smoother development experience.

AppRun Benefits

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

Getting Started

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

npm install apprun

You can also load AppRun directly from the unpkg.com CDN:

<html>
<body>
<script src="https://unpkg.com/apprun/dist/apprun-html.js"></script>
<script>
  const view = state => `<div>${state}</div>`;
  app.start(document.body, 'hello AppRun', 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, or with a compiler/bundler like Webpack or Vite.

You can run the npm create apprun-app command to create an AppRun project.

npm create apprun-app [my-app]

Learn More

You can get started with AppRun Docs and the AppRun Playground.

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-2024 Yiyi Sun

NPM DownloadsLast 30 Days