Skip to content

Commit abc63cf

Browse files
committed
remove need for proxy
1 parent 674e0ec commit abc63cf

3 files changed

Lines changed: 15 additions & 28 deletions

File tree

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"presets": [
33
"react",
44
"es2015"
5+
],
6+
"plugins": [
7+
"transform-object-rest-spread"
58
]
69
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"homepage": "https://github.com/legitcode/tests#readme",
2828
"devDependencies": {
2929
"babel-cli": "^6.6.5",
30+
"babel-plugin-transform-object-rest-spread": "^6.6.5",
3031
"babel-preset-es2015": "^6.6.0",
3132
"babel-preset-react": "^6.5.0",
3233
"babel-register": "^6.7.2",

src/legit-tests.js

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,37 @@ import React from 'react'
33
import findAll from './find-all'
44

55
export default (component) => {
6-
let items, selectedIndex
7-
6+
let items
7+
88
const shallowRenderer = TestUtils.createRenderer()
99
shallowRenderer.render(component)
1010
const instance = shallowRenderer.getRenderOutput();
1111

1212
const find = (term, child) => {
1313
const selector = term.charAt(0)
14+
1415
switch (selector) {
1516
case '.':
1617
items = findAll(instance, child => child.props ? child.props.className == term.slice(1) : false)
17-
return proxy
18+
return { ...items[0].props, ...utils}
1819
case '#':
1920
items = findAll(instance, child => child.props ? child.props.id == term.slice(1) : false)
20-
return proxy
21+
return { ...items[0].props, ...utils}
2122
default:
22-
return proxy
23+
return utils
2324
}
2425
}
2526

26-
const first = () => {
27-
selectedIndex = 0
28-
return proxy
29-
}
30-
31-
const last = () => {
32-
selectedIndex = items.length - 1
33-
return proxy
34-
}
35-
36-
const get = (index) => {
37-
selectedIndex = index
38-
return proxy
39-
}
27+
const first = () => items[0].props
28+
const last = () => items[items.length - 1].props
29+
const get = (index) => items[index].props
4030

4131
const utils = {
42-
props: instance.props,
4332
find,
4433
first,
4534
last,
46-
get
35+
get,
4736
}
4837

49-
const proxy = Proxy.create({
50-
get: (proxy, name) => {
51-
if(utils[name]) return value => utils[name](value)
52-
return items[selectedIndex || 0].props[name]
53-
}
54-
})
55-
return proxy
38+
return utils
5639
}

0 commit comments

Comments
 (0)