-
Notifications
You must be signed in to change notification settings - Fork 55
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
Changes from all commits
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 |
---|---|---|
|
@@ -114,6 +114,15 @@ | |
value: null | ||
}, | ||
|
||
/** | ||
* The value of the property to set when an item is selected. The name | ||
* of the property is this.selectedAttribute. | ||
*/ | ||
selectedPropertyValue: { | ||
type: Object, | ||
value: null | ||
}, | ||
|
||
/** | ||
* Default fallback if the selection based on selected with `attrForSelected` | ||
* is not found. | ||
|
@@ -154,7 +163,8 @@ | |
observers: [ | ||
'_updateAttrForSelected(attrForSelected)', | ||
'_updateSelected(selected)', | ||
'_checkFallback(fallbackSelection)' | ||
'_checkFallback(fallbackSelection)', | ||
'_updatePropertyValue(selectedItem, selectedAttribute, selectedPropertyValue)' | ||
], | ||
|
||
created: function() { | ||
|
@@ -336,10 +346,19 @@ | |
if (this.selectedAttribute) { | ||
this.toggleAttribute(this.selectedAttribute, isSelected, item); | ||
} | ||
if (this.selectedPropertyValue) { | ||
item[this.selectedAttribute] = this.selectedPropertyValue; | ||
} | ||
this._selectionChange(); | ||
this.fire('iron-' + (isSelected ? 'select' : 'deselect'), {item: item}); | ||
}, | ||
|
||
_updatePropertyValue: function(selectedItem, selectedAttribute, propertyValue) { | ||
if (selectedAttribute && propertyValue) { | ||
selectedItem[selectedAttribute] = propertyValue; | ||
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. This crashes on first load as 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 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.. So the new value is set on the old page, which isn't desired. 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. 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. That would break subviews though wouldn't it? We would have 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. Not sure if I understand.. the view's selectedPropertyValue would be updated on _applySelection. 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. Yes but 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. Ah ya.. yup you're correct, it would break that :( |
||
} | ||
}, | ||
|
||
_selectionChange: function() { | ||
this._setSelectedItem(this._selection.get()); | ||
}, | ||
|
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.
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: