d3-dispatch
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -1,1 +0,1 @@ | ||
var version = "0.2.4"; export * from "../index"; export {version}; | ||
var version = "0.2.5"; export * from "../index"; export {version}; |
@@ -99,3 +99,3 @@ (function (global, factory) { | ||
var version = "0.2.4"; | ||
var version = "0.2.5"; | ||
@@ -102,0 +102,0 @@ exports.version = version; |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define("d3-dispatch",["exports"],n):n(e.d3_dispatch={})}(this,function(e){"use strict";function n(){return new t(arguments)}function t(e){function n(e){var n=(e+="").indexOf("."),t=e;if(n>=0?e=e.slice(0,n):t+=".",e&&!a.hasOwnProperty(e))throw new Error("unknown type: "+e);return{type:e,name:t}}function t(e){return function(){for(var n,t,r=a[e],i=-1,o=r.length;++i<o;)(t=(n=r[i]).value)&&t.apply(this,arguments);return f}}var r,i=-1,o=e.length,a={},u={},f=this;for(f.on=function(e,t){if(e=n(e),arguments.length<2)return(t=u[e.name])&&t.value;if(e.type){var r,i=a[e.type],o=u[e.name];o&&(o.value=null,r=i.indexOf(o),a[e.type]=i=i.slice(0,r).concat(i.slice(r+1)),delete u[e.name]),t&&(t={value:t},u[e.name]=t,i.push(t))}else if(null==t)for(var l in a)if(t=u[l+e.name]){t.value=null;var i=a[l],r=i.indexOf(t);a[l]=i.slice(0,r).concat(i.slice(r+1)),delete u[t.name]}return f};++i<o;){if(r=e[i]+"",!r||r in f)throw new Error("illegal or duplicate type: "+r);a[r]=[],f[r]=t(r)}}n.prototype=t.prototype;var r="0.2.4";e.version=r,e.dispatch=n}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define("d3-dispatch",["exports"],n):n(e.d3_dispatch={})}(this,function(e){"use strict";function n(){return new t(arguments)}function t(e){function n(e){var n=(e+="").indexOf("."),t=e;if(n>=0?e=e.slice(0,n):t+=".",e&&!a.hasOwnProperty(e))throw new Error("unknown type: "+e);return{type:e,name:t}}function t(e){return function(){for(var n,t,r=a[e],i=-1,o=r.length;++i<o;)(t=(n=r[i]).value)&&t.apply(this,arguments);return f}}var r,i=-1,o=e.length,a={},u={},f=this;for(f.on=function(e,t){if(e=n(e),arguments.length<2)return(t=u[e.name])&&t.value;if(e.type){var r,i=a[e.type],o=u[e.name];o&&(o.value=null,r=i.indexOf(o),a[e.type]=i=i.slice(0,r).concat(i.slice(r+1)),delete u[e.name]),t&&(t={value:t},u[e.name]=t,i.push(t))}else if(null==t)for(var l in a)if(t=u[l+e.name]){t.value=null;var i=a[l],r=i.indexOf(t);a[l]=i.slice(0,r).concat(i.slice(r+1)),delete u[t.name]}return f};++i<o;){if(r=e[i]+"",!r||r in f)throw new Error("illegal or duplicate type: "+r);a[r]=[],f[r]=t(r)}}n.prototype=t.prototype;var r="0.2.5";e.version=r,e.dispatch=n}); |
{ | ||
"name": "d3-dispatch", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Register named callbacks and call them with arguments.", | ||
@@ -12,3 +12,3 @@ "keywords": [ | ||
"homepage": "https://github.com/d3/d3-dispatch", | ||
"license" : "BSD-3-Clause", | ||
"license": "BSD-3-Clause", | ||
"author": { | ||
@@ -15,0 +15,0 @@ "name": "Mike Bostock", |
# d3-dispatch | ||
Register named callbacks and call them with arguments. Dispatching is a convenient mechanism for separating concerns with loosely-coupled code. A variety of D3 components, such as [d3-xhr](https://github.com/d3/d3-xhr), use d3-dispatch to emit events. Think of this like Node’s [EventEmitter](https://nodejs.org/api/events.html), except every listener has a well-defined name so it’s easy to remove or replace them. | ||
Dispatching is a convenient mechanism for separating concerns with loosely-coupled code: register named callbacks and then call them with arbitrary arguments. A variety of D3 components, such as [d3-request](https://github.com/d3/d3-request), use this mechanism to emit events to listeners. Think of this like Node’s [EventEmitter](https://nodejs.org/api/events.html), except every listener has a well-defined name so it’s easy to remove or replace them. | ||
For example, if you create a dispatch `d` for `"start"` and `"end"` callbacks: | ||
For example, if you create a dispatch for `"start"` and `"end"` callbacks: | ||
```js | ||
var d = dispatch("start", "end"); | ||
var dispatch = d3_dispatch.dispatch("start", "end"); | ||
``` | ||
@@ -14,5 +14,5 @@ | ||
```js | ||
d.on("start", callback1); | ||
d.on("start.foo", callback2); | ||
d.on("end", callback3); | ||
dispatch.on("start", callback1); | ||
dispatch.on("start.foo", callback2); | ||
dispatch.on("end", callback3); | ||
``` | ||
@@ -23,3 +23,3 @@ | ||
```js | ||
d.start("pass arguments to callbacks here"); | ||
dispatch.start("pass arguments to callbacks here"); | ||
``` | ||
@@ -31,7 +31,13 @@ | ||
If you use NPM, `npm install d3-dispatch`. Otherwise, download the [latest release](https://github.com/d3/d3-dispatch/releases/latest). | ||
If you use NPM, `npm install d3-dispatch`. Otherwise, download the [latest release](https://github.com/d3/d3-dispatch/releases/latest). The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom build using [Rollup](https://github.com/rollup/rollup) or your preferred bundler. You can also load directly from [d3js.org](https://d3js.org): | ||
```html | ||
<script src="https://d3js.org/d3-dispatch.v0.2.min.js"></script> | ||
``` | ||
In a vanilla environment, a `d3_dispatch` global is exported. [Try d3-dispatch in your browser.](https://tonicdev.com/npm/d3-dispatch) | ||
## API Reference | ||
<a name="dispatch" href="#dispatch">#</a> <b>dispatch</b>(<i>types…</i>) | ||
<a name="dispatch" href="#dispatch">#</a> d3_dispatch.<b>dispatch</b>(<i>types…</i>) | ||
@@ -61,9 +67,1 @@ Creates a new dispatch object for the specified *types*. Each *type* is a string representing the name of a callback type, such as `"zoom"` or `"change"`; for each type, a method is exposed on the returned dispatch object for invoking the callbacks of that type. | ||
You can pass whatever arguments you want to callbacks; most commonly, you might create an object that represents an event, or pass the current datum (*d*) and index (*i*). See [function.call](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/Call) and [function.apply](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/Apply) for further information. | ||
## Changes from D3 3.x: | ||
* It is now an error to attempt to register a callback type that: conflicts with a built-in property on all objects, such as `__proto__` or `hasOwnProperty`; conflicts with a built-in method on dispatch (e.g., `on`); conflicts with another type on the same dispatch (e.g., `dispatch("foo", "foo")`); is the empty string. | ||
* The exposed [*dispatch*.*type*](#type) field is now strictly a method for invoking callbacks. Use `dispatch.on(type, …)` to get or set callbacks, rather than `dispatch[type].on(…)`. | ||
* The `instanceof` operator now works as expected with dispatch objects. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
13710
64