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

Observing Map doesn't work, possible regression #642

Closed
davismj opened this issue Oct 28, 2017 · 7 comments
Closed

Observing Map doesn't work, possible regression #642

davismj opened this issue Oct 28, 2017 · 7 comments

Comments

@davismj
Copy link
Member

davismj commented Oct 28, 2017

I'm submitting a bug report

  • Library Version:
    1.5.0

Current behavior:
No observation of map.get

Expected/desired behavior:
Observe map.get

@davismj davismj changed the title MapObserver broken? Observing Map doesn't work, possible regression Oct 28, 2017
@bigopon
Copy link
Member

bigopon commented Oct 28, 2017

The first case has never been supported. Same for second case as they are both bound to function call result. So if the map never changed, It won't call the binding to update those text node.

I think it's intentional, since we don't support observer function call result function call result. Aurelia cannot differentiate between a map get and a normal function call.

@davismj
Copy link
Member Author

davismj commented Oct 28, 2017

I had some code that was using this and I seem to remember it working before.

Since map.get, for example, is not just a normal function, but a function whose result is explicitly tied to a map mutation, such as map.set, I'm thinking it would be possible, maybe reasonable, to observe these mutations.

@bigopon
Copy link
Member

bigopon commented Oct 29, 2017

I dont know the full history so you could be right, then support for it was dropped. Maybe @jdanyow left those out for performance optimization ?

@jdanyow
Copy link
Contributor

jdanyow commented Oct 29, 2017

Never was supported. Mr Davis here has a history of requesting method call observation. 😉

@jdanyow
Copy link
Contributor

jdanyow commented Oct 29, 2017

#147

@davismj
Copy link
Member Author

davismj commented Oct 29, 2017

Haha okay, maybe I found a workaround for it like iterating over the map elements and then testing to see if it was equal to the one I actually wanted.

However, I don't think this is an unreasonable thing to observe. These aren't arbitrary methods, and in fact Map.get is quite similar to Array[index] as we know Map.get will be updated by Map.set just like we know Array[index] will be updated by Array methods including splice.

I think this Array use case--in an issue also opened by yours truly--was eventually added: #64

@davismj davismj closed this as completed Nov 6, 2017
@davismj
Copy link
Member Author

davismj commented Nov 9, 2017

@jdanyow @bigopon I'm looking at the map-observation code here: https://github.com/aurelia/binding/blob/master/src/map-observation.js#L42

So basically, this works on a repeat but not on a .get() call. In the case of Map, however, I think more often than not you will want to get specific values rather than iterating over the entire Map.

Wouldn't there be a way to extend the get function to add it as a subscriber to the map's subscriber collection?

This was brought up on Discourse here: https://discourse.aurelia.io/t/updating-a-map-doesnt-trigger-binding-updates/264/3

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

No branches or pull requests

3 participants