peerlibrary:computed-field

v0.1.0Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Reactively computed field for Meteor

Reactively computed field for Meteor provides an easy way to define a reactive variable which gets value from another reactive function. This allows you to minimize propagation of a reactive change because if the reactive function returns the value equal to the previous value, reactively computed field will not invalidate reactive contexts where it is used.

1var foobar = new ComputedField(function () {
2  var sum = 0;
3  collection.find({}, {fields: {value: 1}}).forEach(function (doc) {
4    sum += doc.value;
5  });
6  return sum;
7});
8
9console.log(foobar());

You get current value by calling the field as a function. A reactive dependency is then registered. This is useful when you are assigning them to objects because they behave like object methods. You can also access them in Blaze Components template by simply doing {{foobar}} when they are assigned to the component.

Optionally, you can pass custom equality function:

1new ComputedField(reactiveFunction, function (a, b) {return a === b});

Adding this package to your Meteor application adds the ComputedField constructor into the global scope.

Both client and server side.

Installation

meteor add peerlibrary:computed-field

minimizing reactivity propagation