All Projects → andrejewski → Raj

andrejewski / Raj

Licence: mit
The Elm Architecture for JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Raj

Venom
Venom is the most complete javascript library for Whatsapp, 100% Open Source.
Stars: ✭ 3,457 (+1945.56%)
Mutual labels:  framework, message
Messagethrottle
A lightweight Objective-C message throttle and debounce library.
Stars: ✭ 710 (+320.12%)
Mutual labels:  message, runtime
Helma
Helma web framework
Stars: ✭ 18 (-89.35%)
Mutual labels:  framework, runtime
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (-4.14%)
Mutual labels:  framework
Primitiv
A Neural Network Toolkit.
Stars: ✭ 164 (-2.96%)
Mutual labels:  framework
Toucheffects
Android View点击特效TouchEffects,几行代码为所有控件添加点击效果
Stars: ✭ 167 (-1.18%)
Mutual labels:  effects
Blink Mind
Fully customizable mindmap framework for react.js. 支持插件的,可被完全定制的思维导图库,基于react.js和immutable.js。
Stars: ✭ 169 (+0%)
Mutual labels:  framework
Qframework
Unity3D System Design Architecture
Stars: ✭ 2,326 (+1276.33%)
Mutual labels:  framework
Ncf
NeuCharFramework Template Project
Stars: ✭ 167 (-1.18%)
Mutual labels:  framework
Ignition Go
Bootstrap4 /Codeigniter 3 Modular (HMVC) App Building Framework - to build enterprise class web applications... Versions: CodeIgniter 3.1.9 AdminLTE 3.4 Bootstrap 4.5.0
Stars: ✭ 166 (-1.78%)
Mutual labels:  framework
Unityskidmarks
A simple skidmark effect generator for Unity3D
Stars: ✭ 165 (-2.37%)
Mutual labels:  effects
Fuselibs
Fuselibs is the Uno-libraries that provide the UI framework used in Fuse apps.
Stars: ✭ 164 (-2.96%)
Mutual labels:  framework
Framework
This repository contains the core code of Laravel Zero
Stars: ✭ 167 (-1.18%)
Mutual labels:  framework
Guitarstack
Digital guitar effects right in your browser!
Stars: ✭ 164 (-2.96%)
Mutual labels:  effects
Wasm Micro Runtime
WebAssembly Micro Runtime (WAMR)
Stars: ✭ 2,440 (+1343.79%)
Mutual labels:  runtime
Uhaha
High Availability Framework for Happy Data
Stars: ✭ 164 (-2.96%)
Mutual labels:  framework
Extensible Effects
Extensible Effects: An Alternative to Monad Transformers
Stars: ✭ 167 (-1.18%)
Mutual labels:  effects
Threejs Sandbox
Set of experiments and extensions to THREE.js.
Stars: ✭ 163 (-3.55%)
Mutual labels:  effects
Rechorus
“Chorus” of recommendation models: a light and flexible PyTorch framework for Top-K recommendation.
Stars: ✭ 164 (-2.96%)
Mutual labels:  framework
Lovepotion
💖 Lua + LÖVE + 3DS = LövePotion
Stars: ✭ 166 (-1.78%)
Mutual labels:  framework

Raj

The Elm Architecture for JavaScript

npm install raj

npm Build Status Greenkeeper badge

Features

  • Understandable
    Raj is 34 lines; 190 bytes minified. This framework can fit in your head or even a tweet.

  • Testable
    Raj forces us to design for better separated concerns, simpler logic, and easier tests.

  • Minimal
    Raj provides a tiny foundation for libraries and applications.

  • Portable
    Raj is view layer agnostic. The view is a side effect of state.

Check out the homepage for resources and ecosystem packages.

Example

A counter that increments by one every time the user confirms.

import { runtime } from 'raj'

runtime({
  init: [0], // State is an integer to count
  update (message, state) {
    return [state + 1] // Increment the state
  },
  view (state, dispatch) {
    const keepCounting = window.confirm(`Count is ${state}. Increment?`)
    if (keepCounting) {
      dispatch()
    }
  }
})

Note: Raj is view layer agnostic. Here we use the browser's built-in view to play the part.

Architecture

Raj applications are structured as programs.

Every program begins with an initial state, which can be anything, and an optional effect. These are put into an array which is the init property of the program.

const init = [initialState, /* optional */ initialEffect]

"Effects" are functions which receive a function dispatch. Effects handle asynchronous work like data-fetching, timers, and managing event listeners. They can pass dispatch messages and Raj uses those to update the state.

function effect (dispatch) {
  // do anything or nothing; preferably something asynchronous
  // call dispatch 0, 1, or N times
  dispatch(message)
}

A "message" can be anything; a server response, the current time, even undefined.

When a message is dispatched, Raj passes that message and the current state to update. The update function returns a new state and optional effect. The business logic of the program is handled with this function.

function update (message, currentState) {
  return [newState, /* optional */ effect]
}

The view is a special effect that receives both the current state and the dispatch function. The view can return anything. For the React view layer, the view returns React elements to be rendered.

function view (currentState, dispatch) {
  // anything, depending on choice of view library
}

The init, update, and view form a "program" which is just an object with those properties:

const program = {
  init: [initialState, /* optional */ initialEffect],
  update (message, currentState) {
    return [newState, /* optional */ effect]
  },
  view (currentState, dispatch) {
    // anything, depending on choice of view library
  }
};

Building any program follows the same steps:

  1. Define the initial state and effect with init
  2. Define the state transitions and effects with update(message, state)
  3. Define the view with view(state, dispatch)
  4. Tie it all together into a program

Programs compose, so a parent program might contain child programs.

  • The parent's init may contain the child's init.
  • The parent's update may call the child's update with messages for the child and the child's state.
  • The parent's view may call the child's view with the child's state and dispatch.

In this way, programs most often compose into a tree structure.

The root program is passed to Raj's runtime. The runtime calls the program, manages its state, and runs its effects.

import { runtime } from 'raj'
import { program } from './app'

runtime(program)

The Raj by Example documentation covers this in greater detail.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].