Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

fix: whitelisting and adding observedAttributes in render #55

Closed
wants to merge 3 commits into from

Conversation

mtscrb
Copy link
Member

@mtscrb mtscrb commented Sep 29, 2016

fixes #54

@treshugart treshugart self-assigned this Oct 4, 2016
Copy link
Contributor

@treshugart treshugart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I approve. Some minor nits and discussion points.

@@ -27,6 +27,13 @@ function syncEvent(node, eventName, newEventHandler) {
}

export default function (CustomElement, opts) {
function whitelistAttrs(props) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if this is the best name for it, but I don't want to 🚲 shed too much on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think it's wrong too. Maybe customElementAttrs or getObservedAttrs ? I'm not so good with names 😆

if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
syncEvent(node, name.substring(2), props[name]);
} else {
node[name] = props[name];
}
});
}
onRef(node) {
if (node != null) {
this.applyProps(node, this.props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation (eslint should have picked this up, though)

if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
syncEvent(node, name.substring(2), props[name]);
} else {
node[name] = props[name];
}
});
}
onRef(node) {
if (node != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can node ever be anything but an element or falsy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is just being defensive. ref callback will always have the element right?

Copy link
Contributor

@treshugart treshugart Oct 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I was conflating this with Skate. React does call ref with null (but I think it's always null). You could probably just use if (node). If you want to be 100% safe, if (node instanceof HTMLElement) would work, but I think that's overkill and truthy / falsy checks here work just fine.

componentDidMount() {
this.componentWillReceiveProps(this.props);
constructor(props) {
super(props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated to this particular fix?

@treshugart
Copy link
Contributor

Closing as I think this doesn't solve a concrete purpose. Happy to revisit if I'm wrong.

@treshugart treshugart closed this Feb 2, 2017
@treshugart treshugart deleted the fix-attrs-render branch February 2, 2017 09:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Current React lifecycle methods problem
3 participants