Fundamentals
ActiveJS has 4 fundamental types of constructs, Units, Systems, Action, and Cluster. All these constructs are Observables since they extend RxJS' Observable class.
You don't need to learn all of them to start using ActiveJS; Units and Actions can be used independently without any further understanding of Systems or Clusters. Also, ActiveJS is tree-shakeable, hence the parts that you don't use, will not get bundled in your build.
This data-flow diagram might give you some perspective before we dive into details. It shows how ActiveJS is connected with other parts of a Web app. All parts of an App can communicate with any instance of an ActiveJS construct directly, there is no abstraction layer involved like a Store, Dispatcher, Middleware, or Reducer.
1. Units
Every state management solution relies on a robust storage system, and for that exact purpose, ActiveJS has independent, reactive storage Units. Simply called Units.
Units emulate JavaScript's native data structures. There's a specialized type of Unit for each of the most used native data structures. All the Units are also
Observables.BoolUnit is a
booleancounterpart, it stores and provides abooleanvalue at all times.NumUnit is a
numbercounterpart, it stores and provides anumbervalue at all times.StringUnit is a
stringcounterpart, it stores and provides astringvalue at all times.ListUnit is an
arraycounterpart, it stores and provides anarrayvalue at all times.DictUnit is loosely based on
Map, it stores and provides a simpleobjectvalue at all times.GenericUnit doesn't pertain to any specific data type, it's generic in nature, it can store any type of value.
2. Systems
Reactive storage Systems help with async APIs like XHR and fetch or any third party abstraction.
A System is just a systematic combination of one or more Units with pre-configured inter-relationships.
For example, AsyncSystem can be used to store, share, replay, and wait for async tasks. This is realized by utilizing four Units for every aspect of an async task, it includes three GenericUnits, one each for
query,responseanderror, and one BoolUnit for thepending-statusof an async task.
Our setup is complete, now we can easily share query, data, error and pending-status with different parts of our App.
Now, all we need to do is trigger a new API request, which also can be done from anywhere, like this:
3. Actions
Actions are meant to represent unique reactive events. Action is an RxJS Subject like construct, it also extends RxJS Observable, and implements custom features like replay on demand.
Actions help trigger customized operations in a reactive fashion.
4. Clusters
It creates a master Observable of combined values of provided members of the Cluster.
It also provides direct access to its members and their combined value.
Last updated
Was this helpful?