Hi!
I’m using a Map to store some metadata. The elements get updated on user interaction. My template displays some of this metadata. However updating the data won’t be reflected in the template.
I’ve found it better to just change my pattern to immutable collections in my components. This is much cleaner and the binding just works. Try creating a new map object in the update() method.
If the map is bound (input) to your element, then the update method in SampleCustomElement should call a method (output) in the parent component to set the item. The parent component would own all updates to map and a new map is created whenever needed.
Over the past year, I’ve realized that this pattern of inputs and outputs makes for clean code and reliable binding.
Turns out what I did to work around it was to iterate over the map and select the item that matches the right key.
<div repeat.for="key, value of map" if.bind="key === 'foo'></div>
I think we all agree this isn’t good. However, I did this way back in the alpha days of Aurelia and never had the problem again. I think it would be great to add this to the binding engine, but it’s just a super low priority for most developers at the moment.
The problem is that it handles these changes the same way it handles array mutations. If you push to an array, the first n items don’t have their bindings refreshed. Only iterable bindings (repeat.for) do. This is why the above strategy works.
<div repeat.for="key, value of map" if.bind="key === 'foo'></div>