anvilistas / anvil-labs

MIT License
9 stars 3 forks source link

Support catching the atom in a subscribe hook #34

Closed s-cork closed 2 years ago

s-cork commented 2 years ago

We could do something where the action is the thing that gets passed to the with ActionContext rather than self.f (on line 71 in the new world - line 54 in the old world)

that might be nicer But since we already passed the function I didn't change that

feel free to tag a commit onto this one to make that happen and or make it work - this pr is untested

meatballs commented 2 years ago

I'm out of time for today so haven't got an MWE, but when I quickly tried this, I get an attribute error for any method decorated with action - it no longer exists on the atom.

s-cork commented 2 years ago

Now tested - turns out you can add attributes to functions but not methods. functions have their own __dict__ but methods don't - who knew.

>>> class A:
...    def foo(): pass
...
>>> a = A()
>>> a.foo.__dict__ is A.foo.__dict__
True
>>> A.foo.bar = 1
>>> a.foo.eggs = 2
AttributeError
meatballs commented 2 years ago

Every day is a school day!