https://github.com/remcoder/computron
Computron is for creating reactive computations, just like ReactiveVar is for reactive values
https://github.com/remcoder/computron
Last synced: 8 months ago
JSON representation
Computron is for creating reactive computations, just like ReactiveVar is for reactive values
- Host: GitHub
- URL: https://github.com/remcoder/computron
- Owner: remcoder
- License: mit
- Created: 2015-05-08T22:22:57.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-05-27T07:31:56.000Z (almost 7 years ago)
- Last Synced: 2024-04-11T08:53:29.399Z (almost 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Computron [](https://travis-ci.org/remcoder/computron)

Computron is for creating reactive _computations_, just like ReactiveVar is for reactive _values_ and was inspired by computed values from [Knockout](http://knockoutjs.com/documentation/computedObservables.html) and [Vue.js](http://vuejs.org/api/options.html#computed).
### Example
var r1 = new ReactiveVar(21);
var r2 = new ReactiveVar(21);
var sum = new Computron(function () {
return r1.get() + r2.get();
});
## Installation
$ meteor add remcoder:computron
## Rationale
While Meteor offers a very flexible way of doing reactivity, having to wrap code in an autorun doesn't always lead to
code that makes the intent clear. This becomes most apparent when you have a cascade of reactive vars that each depend
on one of the other, mixed with side-effects.
TODO: some good examples
## Demo
See in in action [here](http://meteorpad.com/pad/aExzaQ48FAT89Bwba/Computron)
## API
### Creation
var comp = new Computron()
`computation` : _a function that returns a value. It can make use of reactive sources like Session, ReactiveVar etc._
### Example
var taxRate = 0.2;
var priceAfterTax = new Computron(function(){
return Session.get('price') * (1 + taxRate);
});
To get the current value of the computation, call the `get()` method it. For instance:
Session.set('priceLabel', 'total :' + priceAfterTax.get() )
The computed value will be updated reactively and propagated to the dependents of the Computron.
### Advanced
The underlying `Tracker.Computation` is accessible from within the callback. Using that you could for instance `stop()` the computation.
var priceAfterTax = new Computron(function(comp) {
if (sometging)
comp.stop();
return Session.get('price') * (1 + taxRate);
});