ActiveJS致力于为JavaScript应用程序提供一个实用的、反应式的状态管理解决方案。ActiveJS的反应性基于RxJS Observable,因此,您可以充分利用RxJS运算符。它是围绕称为Units的反应式数据结构构建的,这些结构类似于JavaScript的原生数据结构,但功能要强大得多。
![]() |
---|
所有这些功能封装的反应式数据结构都具有以下特性:
1. 可观测值
2. 反应值突变
3. 类型安全
4. Cache-enabled
5. Optionally Immutable
6. Optionally Persistent
这些单元可以帮助您以最少的代码和工作量在应用程序的不同部分之间共享数据。此外,ActiveJS有助于简化异步数据API,如XHR、fetch或第三方抽象,如Angular的HttpClient或axios等。
1. 简单示例
// 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
官网地址 :https://activejs.dev/#/
GitHub 地址 : https://github.com/activejs/activejs