LogoLogo
  • Introduction
  • Intro
    • πŸš€Getting Started
    • Key Characteristics
    • Fundamentals
    • Motivation
  • Fundamentals
    • πŸ’ΎUnits
      • BoolUnit
      • NumUnit
      • StringUnit
      • DictUnit
      • ListUnit
      • GenericUnit
    • 🀝Systems
      • AsyncSystem
      • Custom AsyncSystem
    • 🀜Action
    • πŸ“¦Cluster
  • πŸ”¨Utilities
    • Stream
    • Selection
  • Integrations
    • Angular
    • React
      • useObservable Hook
      • useUnit Hook
  • πŸ“–Guides
    • Configuration
    • Nesting
    • Events
    • Typings
    • Caching
    • Persistence
    • Immutability
    • Freeze and Mute
    • Development Environment
    • General Guidelines
  • More
    • πŸ‘€Examples
    • ✍️Articles
Powered by GitBook
On this page
  • Installation
  • Quick Example
  • Quick Comparisons
  • Quick Overview

Was this helpful?

Introduction

NextGetting Started

Last updated 4 years ago

Was this helpful?

ActiveJS strives to be a pragmatic, reactive state management solution for JavaScript apps.

ActiveJS' reactivity is based on , hence, you can take full advantage of .

It's built around reactive data structures called that resemble JavaScript's native data structures but are much more powerful. All these feature-packed reactive data structures share the following qualities:

  • Observable value

  • Reactive value mutation

  • Type-safety

  • Cache-enabled

  • Optionally Immutable

  • Optionally Persistent

These Units help you share data among different parts of an app with minimum code and effort. Furthermore, ActiveJS helps in streamlining asynchronous data APIs like XHR, fetch, or third party abstractions like Angular's HttpClient or axios, etc.

Installation

npm i @activejs/core

Quick Example

// initialize a reactive data structure to store numbers
const counter = new NumUnit() // with default initial-value 0

// two pure functions to produce an appropriate new value
const increment = value => value + 1 
const decrement = value => value - 1

// subscribe for reactive value access, and log the value
counter.subscribe(value => console.log(value))
// immediately logs 0, and will log any future values

// increment
counter.dispatch(increment); // you'll see 1 in the console
// the pure function is called with the current value and
// the returned value is dispatched automatically

// decrement
counter.dispatch(decrement); // you'll see 0 in the console
// that's it our counter is complete

// you can also access the value directly
console.log(counter.value()) // logs 0

Quick Comparisons

It's hard to Compare with NgRx without involving Angular, but for argument's sake let's pretend that this stripped-down code is valid.

Quick Overview

The following data-flow diagram roughly shows where ActiveJS comes into play. ActiveJS holds the state and every other part of the application directly shares it without any obscure faΓ§ade.

ActiveJS is really small in size, and it's tree-shakeable too. Also, there're no reducers, no middleware, and not even a store for that matter. It's much simpler than that.

If you don't have installed already, you'll need to install it first npm install rxjs, and then

This is how an implementation of a simple "counter" looks like, using a , one of the reactive data structures that ActiveJS provides. The stores and provides a number value at all times ensuring the type-safety.

You never have to worry if the value of this counter is number or not, the will ensure that it's a number, it'll ignore any non-number value dispatch. We'll talk about it in detail later.

A "counter" implemented in vanilla Redux vs ActiveJS. It's not a fair comparison because a can do so much more alone, and Redux is powerful in its own way. But it is what it is.

ActiveJS is fully with 99.99% code-coverage.

RxJS
NumUnit
NumUnit
NumUnit
NumUnit
fuzz-tested
RxJS Observable
RxJS operators
Units
Redux vs ActiveJS
NgRx vs ActiveJS
A very high level data-flow diagram of an App using ActiveJS.