Skip to content

Commit a36d98b

Browse files
committed
Added README.
1 parent 69b418d commit a36d98b

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2015, The PeerLibrary Project
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of the PeerLibrary Project nor the
12+
names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
19+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)