-
Notifications
You must be signed in to change notification settings - Fork 32
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
trigger update on modification of sub-array in Observable{Array} #67
Comments
alternatively this would probably work x[] = map( x-> iseven(x) ? x : -42, x[] ) |
On |
presumably x = Observable(randn(100000))
x[][12] = 42
notify(x) |
It notifies all dependents that EDIT: if the updates were going to be minimal, you could use a |
I don't think reassigning the array is actually that wasteful (no more so than using notify). Julia doesn't have pass-by-value semantics, so reassigning the array doesn't actually allocate a new array. EDIT: Though if you're using something like WebIO which sends observable updates to the browser, it would send the entire array over the wire. In that case you'd probably want to create something like the above which whose observable updates are only the changed indices. |
Interesting.. thanks for the feedback :) so I'm using |
That's exactly right. Still, it's weird to need to apparently mutate just to send a notification. #58 flipped the way of doing it to the more logical order. But as you say, the performance impact is basically nil; this is a "conceptual cleanup" rather than a serious improvement.
That was basically my suggestion for |
For
With that we can do
Does that sound like an API enhancement for |
Meanwhile, we also forward @travigd , @timholy Do you think that it is reasonable to integrate this behaviour into Observables? We also defined a non-notifying notation in order to change the content of Observables without calling
The idea behind using the !-symbol was to combine both meanings of it; modification of the variable and NOT notifying. I personally found, that code using this syntax is much more reader-friendly, but I also understand that it hides the underlying mechanism. For our use case that was perfect, but from a general perspective it might look different. Moreover, this syntax does not cover nested structures. I'd be interested in hearing you opinion. |
I've implemented something like this for the package Stipple. Furthermore, I have come up with an indexing scheme that digs through nested objects and thus can trigger updates at any level. If this sounds interesting to you, I'd be happy to submit a PR. Our code is currently in the hh-push branch of Stipple.jl |
currently you have to manually trigger the change by re-assigning the whole array, seems wasteful?
The text was updated successfully, but these errors were encountered: