Skip to content

Commit

Permalink
Bower updates
Browse files Browse the repository at this point in the history
  • Loading branch information
randyzwitch committed Jul 31, 2016
1 parent 6a93e48 commit 22a2b81
Show file tree
Hide file tree
Showing 17 changed files with 517 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
"stacky": "^1.3.0",
"test-fixture": "polymerelements/test-fixture#^1.0.0"
},
"version": "4.3.0",
"version": "4.3.1",
"devDependencies": {
"polymer": "Polymer/polymer#^1.5.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.22"
},
"homepage": "https://github.com/Polymer/web-component-tester",
"_release": "4.3.0",
"_release": "4.3.1",
"_resolution": {
"type": "version",
"tag": "4.3.0",
"commit": "1aff4fb2f5a08dc670bfda53b3642b90e5b914a5"
"tag": "4.3.1",
"commit": "0a56c4de27a316fd9941582401a17a0ee08a8bbd"
},
"_source": "https://github.com/Polymer/web-component-tester.git",
"_target": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"stacky": "^1.3.0",
"test-fixture": "polymerelements/test-fixture#^1.0.0"
},
"version": "4.3.0",
"version": "4.3.1",
"devDependencies": {
"polymer": "Polymer/polymer#^1.5.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.22"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "d3-cloud",
"version": "1.2.1",
"version": "1.2.2",
"main": "build/d3.layout.cloud.js",
"dependencies": {
"d3-dispatch": "0.2.x"
},
"ignore": [
".DS_Store",
".git",
Expand All @@ -13,11 +16,11 @@
"package.json"
],
"homepage": "https://github.com/jasondavies/d3-cloud",
"_release": "1.2.1",
"_release": "1.2.2",
"_resolution": {
"type": "version",
"tag": "v1.2.1",
"commit": "08001a7723697ee4f17d55739e9bc625ff882aa1"
"tag": "v1.2.2",
"commit": "4cede153d3cbdca41ffb1338157724f0fc7378bc"
},
"_source": "git://github.com/jasondavies/d3-cloud.git",
"_target": "~1.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "d3-cloud",
"version": "1.2.1",
"version": "1.2.2",
"main": "build/d3.layout.cloud.js",
"dependencies": {
"d3-dispatch": "0.2.x"
},
"ignore": [
".DS_Store",
".git",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "d3-dispatch",
"homepage": "https://github.com/d3/d3-dispatch",
"version": "0.2.6",
"_release": "0.2.6",
"_resolution": {
"type": "version",
"tag": "v0.2.6",
"commit": "bd1ead61f8f15eb0de5dde145bb07d06167d98b4"
},
"_source": "https://github.com/d3/d3-dispatch.git",
"_target": "0.2.x",
"_originalSource": "d3-dispatch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ecmaFeatures:
modules: true

env:
es6: true
browser: true

extends:
"eslint:recommended"

rules:
no-cond-assign: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.sublime-workspace
.DS_Store
build/
node_modules
npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.sublime-*
build/*.zip
test/
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2010-2015 Mike Bostock
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the author nor the names of contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# d3-dispatch

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, to create a dispatch for *start* and *end* events:

```js
var dispatch = d3.dispatch("start", "end");
```

You can then register callbacks for these events using [*dispatch*.on](#dispatch_on):

```js
dispatch.on("start", callback1);
dispatch.on("start.foo", callback2);
dispatch.on("end", callback3);
```

Then, you can dispatch a *start* event using [*dispatch*.*type*](#dispatch_type):

```js
dispatch.start("pass arguments to callbacks here");
```

Want a more involved example? See how to use [d3-dispatch for coordinated views](http://bl.ocks.org/mbostock/5872848).

## Installing

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> d3.<b>dispatch</b>(<i>types…</i>)

Creates a new dispatch for the specified event *types*. Each *type* is a string, such as `"start"` or `"end"`; for each type, [a method](#dispatch_type) is exposed on the returned dispatch for invoking the callbacks of that type.

<a name="dispatch_on" href="#dispatch_on">#</a> *dispatch*.<b>on</b>(<i>name</i>[, <i>callback</i>])

Adds, removes or gets a *callback* of the specified *name*.

The *name* is a string, such as `"start"` or `"end"`. A name consists of a event type optionally followed by a period (“.”) and a namespace; the optional namespace allows multiple callbacks to be registered to receive events of the same type, such as `"start.foo"` and `"start.bar"`. You can remove all callbacks for the namespace “foo” by saying `dispatch.on(".foo", null)`.

If a *callback* function is specified, it is registered for the specified (fully-qualified) *name*. If a callback was already registered for the same name, the existing callback is removed before the new callback is added. If *callback* is not specified, returns the current callback for the specified *name*, if any. The specified *callback* is invoked with the context and arguments specified by the caller; see [*dispatch*.*type*](#dispatch_type).

<a name="dispatch_type" href="#dispatch_type">#</a> *dispatch*.<b>*type*</b>(<i>arguments…</i>)

The *type* method (such as `dispatch.start` for the *start* event) invokes each registered callback for the given type, passing the callback the specified *arguments*. The `this` context will be used as the context of the registered callbacks.

For example, if you wanted to dispatch your *custom* callbacks after handling a native *click* event, while preserving the current `this` context and arguments, you could say:

```js
selection.on("click", function() {
dispatch.custom.apply(this, arguments);
});
```

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"folders": [
{
"path": ".",
"file_exclude_patterns": [
"*.sublime-workspace"
],
"folder_exclude_patterns": [
"build"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default as dispatch} from "./src/dispatch";
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "d3-dispatch",
"version": "0.2.6",
"description": "Register named callbacks and call them with arguments.",
"keywords": [
"d3",
"event",
"listener",
"dispatch"
],
"homepage": "https://github.com/d3/d3-dispatch",
"license": "BSD-3-Clause",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"main": "build/d3-dispatch.js",
"jsnext:main": "index",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-dispatch.git"
},
"scripts": {
"pretest": "mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export * from \\\"../index\\\"; export {version};\");' > build/bundle.js && rollup -f umd -n d3_dispatch -o build/d3-dispatch.js -- build/bundle.js",
"test": "faucet `find test -name '*-test.js'` && eslint index.js src",
"prepublish": "npm run test && uglifyjs build/d3-dispatch.js -c -m -o build/d3-dispatch.min.js && rm -f build/d3-dispatch.zip && zip -j build/d3-dispatch.zip -- LICENSE README.md build/d3-dispatch.js build/d3-dispatch.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-dispatch.js ../d3.github.com/d3-dispatch.v0.2.js && cp build/d3-dispatch.min.js ../d3.github.com/d3-dispatch.v0.2.min.js && cd ../d3.github.com && git add d3-dispatch.v0.2.js d3-dispatch.v0.2.min.js && git commit -m \"d3-dispatch ${VERSION}\" && git push"
},
"devDependencies": {
"faucet": "0.0",
"rollup": "0.25",
"tape": "4",
"uglify-js": "2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
function dispatch() {
return new Dispatch(arguments);
}

function Dispatch(types) {
var i = -1,
n = types.length,
callbacksByType = {},
callbackByName = {},
type,
that = this;

that.on = function(type, callback) {
type = parseType(type);

// Return the current callback, if any.
if (arguments.length < 2) {
return (callback = callbackByName[type.name]) && callback.value;
}

// If a type was specified…
if (type.type) {
var callbacks = callbacksByType[type.type],
callback0 = callbackByName[type.name],
i;

// Remove the current callback, if any, using copy-on-remove.
if (callback0) {
callback0.value = null;
i = callbacks.indexOf(callback0);
callbacksByType[type.type] = callbacks = callbacks.slice(0, i).concat(callbacks.slice(i + 1));
delete callbackByName[type.name];
}

// Add the new callback, if any.
if (callback) {
callback = {value: callback};
callbackByName[type.name] = callback;
callbacks.push(callback);
}
}

// Otherwise, if a null callback was specified, remove all callbacks with the given name.
else if (callback == null) {
for (var otherType in callbacksByType) {
if (callback = callbackByName[otherType + type.name]) {
callback.value = null;
callbacks = callbacksByType[otherType];
i = callbacks.indexOf(callback);
callbacksByType[otherType] = callbacks.slice(0, i).concat(callbacks.slice(i + 1));
delete callbackByName[callback.name];
}
}
}

return that;
};

while (++i < n) {
type = types[i] + "";
if (!type || (type in that)) throw new Error("illegal or duplicate type: " + type);
callbacksByType[type] = [];
that[type] = applier(type);
}

function parseType(type) {
var i = (type += "").indexOf("."), name = type;
if (i >= 0) type = type.slice(0, i); else name += ".";
if (type && !callbacksByType.hasOwnProperty(type)) throw new Error("unknown type: " + type);
return {type: type, name: name};
}

function applier(type) {
return function() {
var callbacks = callbacksByType[type], // Defensive reference; copy-on-remove.
callbackValue,
i = -1,
n = callbacks.length;

while (++i < n) {
if (callbackValue = callbacks[i].value) {
callbackValue.apply(this, arguments);
}
}

return that;
};
}
}

dispatch.prototype = Dispatch.prototype; // allow instanceof

export default dispatch;
Loading

0 comments on commit 22a2b81

Please sign in to comment.