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

Add selectedPropertyValue to dynamically set property #148

Closed

Conversation

TimvdLippe
Copy link
Contributor

Please see PolymerElements/app-route#164 for the motivation of this PR. In general, it is not possible to dynamically change the value of selected-attribute and alike. Therefore this PR introduces a new property that does so. Since attribute values can not cope with objects (which was the original usecase) I decided to dircectly set it as property instead.

Fixes PolymerElements/app-route#164

@jsilvermist
Copy link

Ping to @bicknellr.

Copy link

@jsilvermist jsilvermist left a comment

Choose a reason for hiding this comment

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

Tested using Polymer 2 PSK and found some things not working exactly as expected, see screenshot below.

image

this._selectionChange();
this.fire('iron-' + (isSelected ? 'select' : 'deselect'), {item: item});
},

_updatePropertyValue: function(selectedItem, selectedAttribute, propertyValue) {
if (selectedAttribute && propertyValue) {
selectedItem[selectedAttribute] = propertyValue;

Choose a reason for hiding this comment

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

This crashes on first load as selectedItem is undefined.
Works with if (selectedItem && ...) on the line above.

Copy link

Choose a reason for hiding this comment

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

I believe another issue will raise its head here..

Assuming we are using it for the purpose of fixing the subroute issue then we don't want the selectedPropertyValue to be set on pages unless they are the expected page for the route.

Assuming subroute is bound to selectedPropertyValue..
The problem happens because when the route is changed (and subroute triggers the selectedPropertyValue change) the selectedItem hasn't been updated to the new page yet.. so the _updatePropertyValue will be triggered with the new selectedPropertyValue (subroute) but still with the old page still being the selectedItem!

So the new value is set on the old page, which isn't desired.
Note: the new value will also be set correctly on the new page when the selectedItem is changed.

Instead we could just toss out the _updatePropertyValue observer entirely. This fixes the issue I have raised above, and the value will be set correctly in _applySelection anyway, though this also means any changes to selectedPropertyValue require a page change before they will be reflected down to the pages accordingly - though for my purposes this isn't really a problem.

Choose a reason for hiding this comment

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

That would break subviews though wouldn't it? We would have app-location intercepting the new route which would be passed down through subroute, but then the view never gets notified of a page change because the view's route didn't get updated.

Copy link

Choose a reason for hiding this comment

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

Not sure if I understand.. the view's selectedPropertyValue would be updated on _applySelection.

Choose a reason for hiding this comment

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

Yes but _applySelection would only be called on change of the selected item, if you have an app-route inside your view binding to the route property and then handling other views, how would it get updates for when the page changes?

Copy link

Choose a reason for hiding this comment

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

Ah ya.. yup you're correct, it would break that :(

@@ -336,10 +346,19 @@
if (this.selectedAttribute) {
this.toggleAttribute(this.selectedAttribute, isSelected, item);
}
if (this.selectedPropertyValue) {
item[this.selectedAttribute] = this.selectedPropertyValue;
}
Copy link

Choose a reason for hiding this comment

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

Seems like the assignment of the value should be contingent on if selectedAttribute exists, and also probably needs to check if isSelected and if !isSelected then set to null (or something?).. eg:

if (this.selectedAttribute) {
    if (this.selectedPropertyValue) {
        item[this.selectedAttribute] = isSelected ? this.selectedPropertyValue : null;
    }
    else {
        this.toggleAttribute(this.selectedAttribute, isSelected, item);
    }
}

@jsilvermist
Copy link

@TimvdLippe Now that the Polymer Summit is over, would it be possible to get this some attention sometime soon?

@TimvdLippe
Copy link
Contributor Author

I would like to get @bicknellr's opinion first, before fixing the last bugs. Thanks for testing this PR out!

@stramel
Copy link

stramel commented Sep 12, 2017

This sounds useful! 👍 Thanks @TimvdLippe!

@TimvdLippe
Copy link
Contributor Author

This PR is very old and I am no longer pursuing this change. Therefore I am closing this PR.

@TimvdLippe TimvdLippe closed this Aug 10, 2018
@TimvdLippe TimvdLippe deleted the selected-property-value branch August 10, 2018 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants