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

Suggestion: shorter name for setexcludinghandlers! #77

Open
BioTurboNick opened this issue Oct 28, 2021 · 10 comments
Open

Suggestion: shorter name for setexcludinghandlers! #77

BioTurboNick opened this issue Oct 28, 2021 · 10 comments

Comments

@BioTurboNick
Copy link

setexcludinghandlers! is a bit long. Something like the following might be better:

setsilent!
setquiet!
setmuted!

And just a note here that if/when this is chosen, the examples in the GtkObservables.jl docs need to be updated. Currently uses .value, which doesn't work because that's not the current field name.

@hhaensel
Copy link

hhaensel commented Jul 2, 2022

Hi @BioTurboNick , @SimonDanisch , @timholy

I want to come back on my [!] solution that I proposed already in #67.
We use it in Stipple.jl for our own subtype Reactive and find it very useful.

o = Observable(1)

# standard assignment
o[] = 10

# silent assignment by an exclamation mark between the brackets
o[!] = 100

Furthermore we pass arguments that are not ! on to the value of the observable and call notify in case of assignment.

o = [10, 20, 30]
o[2]
# 20

on(o) do x
    println("Hello $x")
end

o[2] = 200
# Hello [10, 200, 30]

The same with getproperty

mutable struct HH
    a::Integer
    b::Integer
end

o = Reactive(HH(1,2))

on(o) do x
    println("Hello $x")
end

o.a = 10
# Hello HH(10, 2)

Happy to hear what you think.

Note: Reactive has nothing to do with the package Reactive. It is an observable type Reactive <: AbstractObservable

@SimonDanisch
Copy link
Member

This should really be a separate issue...
But, I also have a similar type in ShaderAbstractions:
https://github.com/SimonDanisch/ShaderAbstractions.jl/blob/master/src/types.jl#L12-L65=
Looking back on it, it doesn't seem that elegant, but maybe we can clean it up and add it to Observables.jl

@hhaensel
Copy link

hhaensel commented Jul 4, 2022

We can make it a different issue with a better name.
Your idea is quite the same as mine.
If we 'd define these operations for AbstractObservables no macro would be needed

@hhaensel
Copy link

hhaensel commented Jul 4, 2022

Shall I open a draft PR and paste an adaptation of my code?

@hhaensel
Copy link

hhaensel commented Jul 4, 2022

I'dinclude push!, pushfirst!, empty! accordingly

@SimonDanisch
Copy link
Member

Yeah, that'd be an idea.
For my type it's important that one can register for certain updates so that one can do:

on(array, :setindex) do (idx, new_value)
...
end

@hhaensel
Copy link

hhaensel commented Jul 4, 2022

Yeah, that's what we did. We declared Reactive <: AbstractObservable.
I'll submit a PR then :-)

@BioTurboNick
Copy link
Author

Just to throw this out there - _ might better indicate suppression than !

@hhaensel
Copy link

hhaensel commented Jul 4, 2022

That's not possible, you have to use an operator character.
My idea was that ! indicates "not" notifying.

@treygreer
Copy link

treygreer commented Aug 2, 2022

(Never mind... I was running a garbled set of package versions because of a rogue Project.toml that wound up in my Windows home directory somehow. ) Feel free to delete this comment, or ask me to. Not sure what the process is here.

Er, I wound up here trying to track down a bug in Interact. It seems that WebIO throws an error looking for Observables.setexcludinghandlers!():

line 346 in scope.jl, webIO v0.8.17: Observables.setexcludinghandlers(ob, val, x -> !(x isa SyncCallback))

Complete newb here. Any suggestions?

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

4 participants