Skip to content

Commit dd8d9a4

Browse files
committed
Responding to comments from @evcohen
1 parent d485215 commit dd8d9a4

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

__mocks__/genInteractives.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import JSXElementMock from 'JSXElementMock';
33
import DOMElements from '../src/util/attributes/DOM.json';
44
import roles from '../src/util/attributes/role.json';
55

6-
const pureInteractiveElements = {};
7-
Object.keys(DOMElements)
6+
const pureInteractiveElements = Object.keys(DOMElements)
87
.filter(name => DOMElements[name].interactive === true)
9-
.forEach(name => pureInteractiveElements[name] = []);
8+
.reduce((interactiveElements, name) => {
9+
interactiveElements[name] = [];
10+
return interactiveElements;
11+
}, {});
1012

1113
const interactiveElementsMap = {
1214
...pureInteractiveElements,
@@ -21,10 +23,12 @@ const interactiveElementsMap = {
2123
],
2224
};
2325

24-
const pureNonInteractiveElementsMap = {};
25-
Object.keys(DOMElements)
26+
const pureNonInteractiveElementsMap = Object.keys(DOMElements)
2627
.filter(name => !DOMElements[name].interactive)
27-
.forEach(name => pureNonInteractiveElementsMap[name] = []);
28+
.reduce((nonInteractiveElements, name) => {
29+
nonInteractiveElements[name] = [];
30+
return nonInteractiveElements;
31+
}, {});
2832

2933
const nonInteractiveElementsMap = {
3034
...pureNonInteractiveElementsMap,
@@ -42,14 +46,13 @@ const nonInteractiveRoles = Object.keys(roles).filter(
4246
);
4347

4448
export function genInteractiveElements () {
45-
const elements = [];
46-
for (const name in interactiveElementsMap) {
47-
const attributes = interactiveElementsMap[name].map(
48-
({prop, value}) => JSXAttributeMock(prop, value)
49-
);
50-
elements.push(JSXElementMock(name, attributes));
51-
}
52-
return elements;
49+
return Object.keys(interactiveElementsMap)
50+
.map(name => {
51+
const attributes = interactiveElementsMap[name].map(
52+
({prop, value}) => JSXAttributeMock(prop, value)
53+
);
54+
return JSXElementMock(name, attributes);
55+
});
5356
}
5457

5558
export function genInteractiveRoleElements () {
@@ -61,14 +64,13 @@ export function genInteractiveRoleElements () {
6164
}
6265

6366
export function genNonInteractiveElements () {
64-
const elements = [];
65-
for (const name in nonInteractiveElementsMap) {
66-
const attributes = nonInteractiveElementsMap[name].map(
67-
({prop, value}) => JSXAttributeMock(prop, value)
68-
);
69-
elements.push(JSXElementMock(name, attributes));
70-
}
71-
return elements;
67+
return Object.keys(nonInteractiveElementsMap)
68+
.map(name => {
69+
const attributes = nonInteractiveElementsMap[name].map(
70+
({prop, value}) => JSXAttributeMock(prop, value)
71+
);
72+
return JSXElementMock(name, attributes);
73+
});
7274
}
7375

7476
export function genNonInteractiveRoleElements () {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"babel-cli": "^6.14.0",
3131
"babel-core": "^6.14.0",
3232
"babel-eslint": "^7.0.0",
33-
"babel-jest": "^17.0.1",
33+
"babel-jest": "^18.0.0",
3434
"babel-plugin-transform-object-rest-spread": "^6.20.2",
3535
"babel-polyfill": "^6.16.0",
3636
"babel-preset-es2015": "^6.14.0",

src/util/attributes/role.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,8 @@
18201820
"MENU": {
18211821
"requiredProps": [],
18221822
"abstract": false,
1823-
"interactive": false, "props": [
1823+
"interactive": false,
1824+
"props": [
18241825
"ARIA-EXPANDED",
18251826
"ARIA-ATOMIC",
18261827
"ARIA-BUSY",

src/util/isInteractiveElement.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import DOMElements from './attributes/DOM.json';
44

55
// Map of tagNames to functions that return whether that element is interactive or not.
66

7-
const pureInteractiveElements = {};
8-
Object.keys(DOMElements)
7+
const pureInteractiveElements = Object.keys(DOMElements)
98
.filter(name => DOMElements[name].interactive === true)
10-
.forEach((name) => {
11-
pureInteractiveElements[name] = () => true;
12-
});
9+
.reduce((accumulator, name) => {
10+
const interactiveElements = accumulator;
11+
interactiveElements[name] = () => true;
12+
return interactiveElements;
13+
}, {});
1314

1415
export const interactiveElementsMap = {
1516
...pureInteractiveElements,

0 commit comments

Comments
 (0)