| 
 | 1 | +Reactive field for Meteor  | 
 | 2 | +=========================  | 
 | 3 | + | 
 | 4 | +Reactive field for [Meteor](https://meteor.com/) provides an alternative syntax for  | 
 | 5 | +[`ReactiveVar`](http://docs.meteor.com/#/full/reactivevar_pkg):  | 
 | 6 | + | 
 | 7 | +```javascript  | 
 | 8 | +foobar = new ReactiveField('initialValue');  | 
 | 9 | +console.log(foobar()); // prints 'initialValue' string  | 
 | 10 | +foobar('newValue');  | 
 | 11 | +console.log(foobar()); // prints 'newValue' string  | 
 | 12 | +```  | 
 | 13 | + | 
 | 14 | +So instead of `.get()` and `.set()`, you can simply call it as a function which (reactively) returns a value,  | 
 | 15 | +or call it with an argument to set the new value. Setter still returns the value.  | 
 | 16 | + | 
 | 17 | +Optionally, you can pass custom equality function:  | 
 | 18 | + | 
 | 19 | +```javascript  | 
 | 20 | +new ReactiveField('initialValue', function (a, b) {return a === b});  | 
 | 21 | +```  | 
 | 22 | + | 
 | 23 | +The main motivation for this package is that you can assign reactive values to template instances and  | 
 | 24 | +[Blaze Components](https://github.com/peerlibrary/meteor-blaze-components) and then you can access them in the template  | 
 | 25 | +by simply doing `{{field}}` instead of `{{field.get}}`. And same for any other objects to which you create reactive  | 
 | 26 | +fields in the constructor and then you or have `this.field.get()` calls all around the code, which is ugly because if  | 
 | 27 | +you ever decide to convert `this.field` into a getter with some additional logic you have to change code everywhere.  | 
 | 28 | +Or you create a `this.field()` getter in advance, which calls `this._field.get()` for you, but that is again a lot of  | 
 | 29 | +work. So the easiest thing is to have reactive fields be methods to begin with so you can change them later on if  | 
 | 30 | +necessary while keeping backwards compatibility.  | 
 | 31 | + | 
 | 32 | +Adding this package to your [Meteor](http://www.meteor.com/) application adds the `ReactiveField` constructor into  | 
 | 33 | +the global scope.  | 
 | 34 | + | 
 | 35 | +Both client and server side.  | 
 | 36 | + | 
 | 37 | +Installation  | 
 | 38 | +------------  | 
 | 39 | + | 
 | 40 | +```  | 
 | 41 | +meteor add peerlibrary:reactive-field  | 
 | 42 | +```  | 
 | 43 | + | 
 | 44 | +Related projects  | 
 | 45 | +----------------  | 
 | 46 | + | 
 | 47 | +* [reactive-var](https://atmospherejs.com/meteor/reactive-var) – official Meteor reactive variable implementation  | 
 | 48 | +which this package just wraps, so the functionality is the same, just syntax how to use it is different  | 
 | 49 | +* [meteor-variable](https://github.com/awwx/meteor-variable) – deprecated package offering similar syntax to this  | 
 | 50 | +package  | 
0 commit comments