Skip to content

Commit

Permalink
Fix #39 - remove Map polyfill.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 4, 2015
1 parent 6ca2837 commit a431782
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This module implements the core concept of D3: manipulating the DOM by selecting

* [Multi-value map](http://bl.ocks.org/mbostock/3305515) variants of selection.attr, selection.style, selection.property, selection.class and selection.on are now implemented as distinct methods in the [d3-selection-multi plugin](https://github.com/d3/d3-selection-multi), rather than overloading the arguments. See [#2109](https://github.com/mbostock/d3/issues/2109).

* The d3.ns.prefix namespace map has been renamed to d3.namespaces and is now a Map rather than an object.
* The d3.ns.prefix namespace map has been renamed to d3.namespaces.

* The d3.ns.qualify method has been renamed to d3.namespace.

Expand Down
25 changes: 0 additions & 25 deletions d3.js

This file was deleted.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-selection",
"version": "0.4.8",
"version": "0.4.9",
"description": "Data-driven DOM manipulation: select elements and join them to data.",
"keywords": [
"d3",
Expand All @@ -14,19 +14,19 @@
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"main": "build/d3",
"main": "build/selection",
"jsnext:main": "index",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-selection.git"
},
"scripts": {
"pretest": "mkdir -p build && d3-bundler --polyfill-map --format=umd --name=d3 -- d3.js > build/d3.js",
"pretest": "mkdir -p build && d3-bundler --format=umd --name=selection -- index.js > build/selection.js",
"test": "faucet `find test -name '*-test.js'`",
"prepublish": "npm run test && uglifyjs build/d3.js -c -m -o build/d3.min.js && rm -f build/d3.zip && zip -j build/d3.zip -- LICENSE README.md build/d3.js build/d3.min.js"
"prepublish": "npm run test && uglifyjs build/selection.js -c -m -o build/selection.min.js && rm -f build/selection.zip && zip -j build/selection.zip -- LICENSE README.md build/selection.js build/selection.min.js"
},
"devDependencies": {
"d3-bundler": "~0.2.5",
"d3-bundler": "~0.3.0",
"faucet": "0.0",
"jsdom": "3",
"tape": "4",
Expand Down
2 changes: 1 addition & 1 deletion src/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import namespaces from "./namespaces";
export default function(name) {
var i = name.indexOf(":"), prefix = name;
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
return namespaces.has(prefix) ? {space: namespaces.get(prefix), local: name} : name;
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
};
13 changes: 7 additions & 6 deletions src/namespaces.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default (new Map)
.set("svg", "http://www.w3.org/2000/svg")
.set("xhtml", "http://www.w3.org/1999/xhtml")
.set("xlink", "http://www.w3.org/1999/xlink")
.set("xml", "http://www.w3.org/XML/1998/namespace")
.set("xmlns", "http://www.w3.org/2000/xmlns/");
export default {
svg: "http://www.w3.org/2000/svg",
xhtml: "http://www.w3.org/1999/xhtml",
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/"
};
18 changes: 10 additions & 8 deletions src/selection-data.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var keyPrefix = "$";

// The value may either be an array or a function that returns an array.
// An optional key function may be specified to control how data is bound;
// if no key function is specified, data is bound to nodes by index.
Expand Down Expand Up @@ -96,7 +98,7 @@ export default function(value, key) {
node,
dataLength = data.length,
nodeLength = update.length,
nodeByKeyValue = new Map,
nodeByKeyValue = {},
keyStack = new Array(2).concat(stack),
keyValues = new Array(nodeLength),
keyValue;
Expand All @@ -109,17 +111,17 @@ export default function(value, key) {
for (i = 0; i < nodeLength; ++i) {
if (node = update[i]) {
keyStack[0] = node.__data__, keyStack[1] = i;
keyValues[i] = keyValue = key.apply(node, keyStack);
keyValues[i] = keyValue = keyPrefix + key.apply(node, keyStack);

// Is this a duplicate of a key we’ve previously seen?
// If so, this node is moved to the exit selection.
if (nodeByKeyValue.has(keyValue)) {
if (nodeByKeyValue[keyValue]) {
exit[i] = node;
}

// Otherwise, record the mapping from key to node.
else {
nodeByKeyValue.set(keyValue, node);
nodeByKeyValue[keyValue] = node;
}
}
}
Expand All @@ -130,11 +132,11 @@ export default function(value, key) {
// Compute the keys for each datum.
for (i = 0; i < dataLength; ++i) {
keyStack[0] = data[i], keyStack[1] = i;
keyValue = key.apply(update._parent, keyStack);
keyValue = keyPrefix + key.apply(update._parent, keyStack);

// Is there a node associated with this key?
// If not, this datum is added to the enter selection.
if (!(node = nodeByKeyValue.get(keyValue))) {
if (!(node = nodeByKeyValue[keyValue])) {
enter[i] = new EnterNode(update._parent, data[i]);
}

Expand All @@ -147,13 +149,13 @@ export default function(value, key) {
}

// Record that we consumed this key, either to enter or update.
nodeByKeyValue.set(keyValue, true);
nodeByKeyValue[keyValue] = true;
}

// Take any remaining nodes that were not bound to data,
// and place them in the exit selection.
for (i = 0; i < nodeLength; ++i) {
if ((node = nodeByKeyValue.get(keyValues[i])) !== true) {
if ((node = nodeByKeyValue[keyValues[i]]) !== true) {
exit[i] = node;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/selection-event.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import requote from "./requote";

var filterEvents = new Map;
var filterEvents = {};

export var event = null;

if (typeof document !== "undefined") {
var element = document.documentElement;
if (!("onmouseenter" in element)) {
filterEvents.set("mouseenter", "mouseover").set("mouseleave", "mouseout");
filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
}
}

Expand All @@ -21,7 +21,7 @@ export default function(type, listener, capture) {

if (n < 3) capture = false;
if ((n = type.indexOf(".")) > 0) type = type.slice(0, n);
if (filter = filterEvents.has(type)) type = filterEvents.get(type);
if (filter = filterEvents.hasOwnProperty(type)) type = filterEvents[type];

function add() {
var ancestor = root, i = arguments.length >> 1, ancestors = new Array(i);
Expand Down

0 comments on commit a431782

Please sign in to comment.