reactive-property
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -77,3 +77,4 @@ // UMD boilerplate (from Rollup) | ||
// If there is an initial value, invoke the listener immediately. | ||
if(typeof(value) !== "undefined" && value !== null){ | ||
// null is considered as a defined value. | ||
if(value !== void 0){ | ||
listener(value); | ||
@@ -80,0 +81,0 @@ } |
{ | ||
"name": "reactive-property", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "A small library for getter-setter functions that react to changes.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,29 +0,7 @@ | ||
# reactive-property [![NPM](https://nodei.co/npm/reactive-property.png)](https://npmjs.org/package/reactive-property) [![Build Status](https://travis-ci.org/curran/reactive-property.svg?branch=master)](https://travis-ci.org/curran/reactive-property) | ||
# reactive-property [![Build Status](https://travis-ci.org/curran/reactive-property.svg?branch=master)](https://travis-ci.org/curran/reactive-property) | ||
This [tiny](https://github.com/curran/reactiveProperty/blob/master/index.js) library abstracts the getter-setter pattern described in [Towards Reusable Charts (by Mike Bostock, 2012)](https://bost.ocks.org/mike/chart/) and adds the ability to react to changes in state. | ||
[![NPM](https://nodei.co/npm/reactive-property.png)](https://npmjs.org/package/reactive-property) | ||
## Installation | ||
A small library for getter-setter functions that react to changes. | ||
Install the library by running this command. | ||
`npm install reactive-property` | ||
Require it in your code like this. | ||
```javascript | ||
var ReactiveProperty = require("reactive-property"); | ||
``` | ||
If you're not using NPM, you can require the script in your HTML like this. | ||
```html | ||
<script src="//curran.github.io/reactive-property/reactive-property-v0.6.0.js"></script> | ||
``` | ||
Or, you can use the minified version (1.5K). | ||
```html | ||
<script src="//curran.github.io/reactive-property/reactive-property-v0.6.0.min.js"></script> | ||
``` | ||
## Usage | ||
@@ -83,14 +61,42 @@ | ||
x: ReactiveProperty(5), | ||
y: ReactiveProperty(10), | ||
z: ReactiveProperty(15) | ||
y: ReactiveProperty(10) | ||
}; | ||
my.x(50) | ||
.y(100) | ||
.z(150); | ||
my.x(50).y(100); | ||
``` | ||
For more detailed example code, have a look at the [tests](https://github.com/curran/reactiveProperty/blob/master/test.js).. | ||
That covers the entire API. For more detailed example code, have a look at the [tests](https://github.com/curran/reactiveProperty/blob/master/test.js). | ||
## Installation | ||
Install the library by running this command. | ||
`npm install reactive-property` | ||
Require it in your code like this. | ||
```javascript | ||
var ReactiveProperty = require("reactive-property"); | ||
``` | ||
If you're not using NPM, you can require the script in your HTML like this. | ||
```html | ||
<script src="//curran.github.io/reactive-property/reactive-property-v0.7.0.js"></script> | ||
``` | ||
Or, you can use the minified version (1.5K). | ||
```html | ||
<script src="//curran.github.io/reactive-property/reactive-property-v0.7.0.min.js"></script> | ||
``` | ||
## Background | ||
Related works: | ||
* [Towards Reusable Charts (by Mike Bostock, 2012)](https://bost.ocks.org/mike/chart/) | ||
* [KnockoutJS Observables](http://knockoutjs.com/documentation/observables.html) | ||
* [RxJS Observables](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md) | ||
After many attempts at building "frameworks" for data visualization ([ModelJS](https://github.com/curran/model), [Chiasm](https://github.com/chiasm-project/chiasm)), I have learned that abstractions come at a cost. Much to my dismay, I found that when I wanted to apply Chiasm to a particular project, the abstractions had too much surface area and stood in the way of customization. I found myself starting again from raw D3 examples to get projects done, and noticed that as a project grows in complexity organically, the most common need is to *listen for changes in state*. | ||
@@ -97,0 +103,0 @@ |
@@ -82,7 +82,7 @@ // Unit tests for reactive-property. | ||
it("Should not react to null.", function () { | ||
it("Should react to null.", function () { | ||
var a = ReactiveProperty(null); | ||
var numInvocations = 0; | ||
a.on(function (){ numInvocations++; }); | ||
assert.equal(numInvocations, 0); | ||
assert.equal(numInvocations, 1); | ||
}); | ||
@@ -89,0 +89,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17080
255
176