-
Notifications
You must be signed in to change notification settings - Fork 50
Add key to the element wrapped in the Route #40
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,15 @@ | |
"bundle": "rollup -i src/index.js -o dist/router.js -f umd -mn router -g hyperapp:hyperapp", | ||
"minify": "uglifyjs dist/router.js -o dist/router.js -mc pure_funcs=Object.defineProperty --source-map includeSources,url=router.js.map", | ||
"prepublish": "npm run build", | ||
"format": "prettier --semi false --write 'src/**/*.js'", | ||
"format": "prettier --semi false --write \"src/**/*.js\"", | ||
"release": "npm run build && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish" | ||
}, | ||
"babel": { | ||
"presets": "env" | ||
}, | ||
"jest": { | ||
"testURL": "http://test/test" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just leaving a comment here: https://facebook.github.io/jest/docs/en/configuration.html#testurl-string Nice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to do it in the test, but couldn't figure out how to do that |
||
}, | ||
"devDependencies": { | ||
"babel-preset-env": "^1.6.1", | ||
"hyperapp": "0.18.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,14 @@ export function Route(props) { | |
exact: !props.parent | ||
}) | ||
|
||
return ( | ||
match && | ||
props.render({ | ||
match: match, | ||
location: location | ||
}) | ||
) | ||
if (!match) return | ||
|
||
var child = props.render({ | ||
match: match, | ||
location: location | ||
}) | ||
|
||
child.props.key = child.props.key || props.path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ForsakenHarmony @zaceno Is this infallible? Anyone familiar with ReactRouter, what's going on there? I like this though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, I mean does ReactRouter also add a key to the route component? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. afaik, no, but they have component methods, which don't depend on elements that might be reused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jorgebucaran is it infallible? ...well... this: <main>
<Route path="/show/secrets" render={SecretComponent} />
<AComponent />
<AnotherComponent />
<Route path="/show/secrets" render={AnotherSecretComponent} />
<ThirdComponent />
</main> I e using the route as a switch to turn on or off multiple sibling components. Then the siblings will be keyed with the same key which of course is no good. ...unless the components have their own keys, in which case those keys will be used instead. So: A - Before: By default B - This proposal: You get automatic keys which make sense for the most part. And hence a lower threshold for beginners. But you run the risk of key-collisions and you don't understand why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this? var key =
props.key ||
props.path + (props.render ? props.render.name + props.render.length : "") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arrow functions have no name. 😞 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They do if you assign them to a variable, but anonymously used, they don't, just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keys have a pivotal role in the VDOM, and instead of hiding this them, we should ask users to properly key their routes instead. Only /cc @frenzzy |
||
|
||
return child | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ForsakenHarmony Are you on windows? What's the purpose of this? Just curious.