-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/fix props vs attrs #356
Conversation
src/components/a-icon/_preview.html
Outdated
<axa-icon icon="logo-AXA" classes="a-icon"></axa-icon> | ||
<axa-icon id="axa-icon-test" icon="logo-AXA" classes="a-icon"></axa-icon> | ||
|
||
<script> |
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.
ahahahaha like this!
a98429e
to
729edd9
Compare
BROKEN right now by an infinite loop %cWeb Component %cAXA-HEADER-MOBILE%c#2 has an error while loading its template:
RangeError: Maximum call stack size exceeded
Stack Trace: RangeError: Maximum call stack size exceeded
at HTMLElement._makeContextReady (http://localhost:3000/components/m-header-mobile/index.js:1385:16)
at HTMLElement.connectedCallback (http://localhost:3000/components/m-header-mobile/index.js:1134:14)
at HTMLElement.connectedCallback (http://localhost:3000/components/m-header-mobile/index.js:2033:127)
at HTMLElement.didRenderCallback (http://localhost:3000/components/m-header-mobile/index.js:2057:14)
at HTMLElement.render (http://localhost:3000/components/m-header-mobile/index.js:1284:14)
at HTMLElement.connectedCallback (http://localhost:3000/components/m-header-mobile/index.js:1131:12)
at HTMLElement.connectedCallback (http://localhost:3000/components/m-header-mobile/index.js:2033:127)
at HTMLElement.didRenderCallback (http://localhost:3000/components/m-header-mobile/index.js:2057:14)
at HTMLElement.render (http://localhost:3000/components/m-header-mobile/index.js:1284:14)
at HTMLElement.connectedCallback (http://localhost:3000/components/m-header-mobile/index.js:1131:12) |
ad00df1
to
5743fed
Compare
|
||
const key = camelize(name); | ||
|
||
this[key] = toProp(newValue); |
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.
@LucaMele
I would be keen to know, how removal
is detected. Guess just an empty string ''
.
May we should add something like prop-types but in separate PR, as soon as it becomes an issue. And I would realy like to have automatic tests for this...
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.
me too... me too
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.
this is a bit dangerous to be honest.. What if we override a DOM property like style or so on?
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.
Absolutely, may we add a blacklist for ['style',
className,
id, etc]
which throws?
Or I could a check if the property exists already, then throw 😇
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.
yes better with check + throw
@@ -182,7 +246,7 @@ export default class BaseComponent extends HTMLElement { | |||
}); | |||
} | |||
|
|||
const items = template(getAttributes(this), this.childrenFragment); | |||
const items = template(this._props, this.childrenFragment); |
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.
i have a mixed feeling trying to reactify standard web components. I like this solution, dont get me wrong, but im just a bit scared :) U can ignore this comment :)
|
||
const key = camelize(name); | ||
|
||
this[key] = toProp(newValue); |
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.
this is a bit dangerous to be honest.. What if we override a DOM property like style or so on?
if (this.hasAttribute(attr)) { | ||
const value = getAttribute(this, attr); | ||
|
||
this[key] = value; |
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.
this is a bit dangerous to be honest.. What if we override a DOM property like style or so on?
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.
i understand we need it for react thought just want to be sure
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.
I agree. We need to document it and could check if a prop
exists already, if so throw
c97cf61
to
2f5e197
Compare
hope that super[key] works on all browsers... |
@LucaMele |
OK then it should work |
Fixes #321 and foundations for #39 .
Changes proposed in this pull request:
The idea is that first-class props can be set by DOM properties. In case of HTML's
setAttribute
is used, we parse the attributes value once for JSON and store the result as first-class DOM property. This way it will be much easier to bridge with frameworks like React or Angular andgetAttribute/s
won't be needed any more, just simple prop access.Type of change
How Has This Been Tested?
Locally
Checklist: