Skip to content
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

Adds the ability to pass a conversion object like JSON #15

Merged
merged 3 commits into from
Oct 18, 2019

Conversation

cherifGsoul
Copy link
Member

Fixes #11

Make it possible to pass a JSON like conversion object:

person: { type: Object, bind: fromAttribute( JSON ) }

or:

person: { type: Object, bind: fromAttribute( 'attr-name', JSON ) }

@@ -24,7 +32,12 @@ function initializeFromAttribute (propertyName, ctr, attributeName) {
if (ctr[metaSymbol]._attributeChangedCallbackHandler === undefined) {
ctr[metaSymbol]._attributeChangedCallbackHandler = {};
}
if (attributeName === undefined) {
if (typeof attributeName === 'object') {
if (isJSONLike(attributeName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we give a warning when the wrong thing is passed? This can happen in a future PR.

Copy link
Collaborator

@phillipskevin phillipskevin left a comment

Choose a reason for hiding this comment

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

This looks good. I just had one small comment. Also, we'll need to document these uses, but we can do that in a future PR if you want.

}

attributes.forEach(attribute => {
const makeFromAttribute = fromAttribute(attribute, JSON);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should make sure that this works correctly if attribute is different from the attribute passed in setAttribute.

@cherifGsoul
Copy link
Member Author

@phillipskevin I updated the PR as requested, can you review it again, please?

@cherifGsoul cherifGsoul merged commit f0c5786 into master Oct 18, 2019
@cherifGsoul cherifGsoul deleted the i11-conversion-function-fromattribute branch October 18, 2019 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to pass a conversion function to fromAttribute
2 participants