Skip to content

Commit 61841e2

Browse files
committed
Move creator a separate file.
This matches matcher, selector and selectorAll.
1 parent 231b38e commit 61841e2

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/creator.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import namespace from "./namespace";
2+
3+
function creatorInherit(name) {
4+
return function() {
5+
var document = this.ownerDocument,
6+
uri = this.namespaceURI;
7+
return uri && uri !== document.documentElement.namespaceURI
8+
? document.createElementNS(uri, name)
9+
: document.createElement(name);
10+
};
11+
}
12+
13+
function creatorFixed(fullname) {
14+
return function() {
15+
return this.ownerDocument.createElementNS(fullname.space, fullname.local);
16+
};
17+
}
18+
19+
export default function(name) {
20+
var fullname = namespace(name);
21+
return (fullname.local
22+
? creatorFixed
23+
: creatorInherit)(fullname);
24+
}

src/selection/append.js

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
import namespace from "../namespace";
1+
import creator from "../creator";
22
import selector from "../selector";
33

4-
function creatorInherit(name) {
5-
return function() {
6-
var document = this.ownerDocument,
7-
uri = this.namespaceURI;
8-
return uri && uri !== document.documentElement.namespaceURI
9-
? document.createElementNS(uri, name)
10-
: document.createElement(name);
11-
};
12-
}
13-
14-
function creatorFixed(fullname) {
15-
return function() {
16-
return this.ownerDocument.createElementNS(fullname.space, fullname.local);
17-
};
18-
}
19-
20-
function creator(name) {
21-
var fullname = namespace(name);
22-
return (fullname.local
23-
? creatorFixed
24-
: creatorInherit)(fullname);
25-
}
26-
274
function append(create) {
285
return function() {
296
return this.appendChild(create.apply(this, arguments));

test/selection/index-test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ var tape = require("tape"),
33
d3 = require("../../");
44

55
tape("d3.selection() returns a selection of the document element", function(test) {
6+
var document = global.document = jsdom.jsdom();
67
try {
7-
var document = global.document = jsdom.jsdom(),
8-
s = d3.selection();
9-
test.equal(s.node(), document.documentElement);
8+
test.equal(d3.selection().node(), document.documentElement);
109
test.end();
1110
} finally {
1211
delete global.document;

0 commit comments

Comments
 (0)