Discussing: Best practices: Test-driven development with Anvil

An atom from the atomic module doesn’t depend on the UI.
It’s based largely based on a subscriber model.

When using an atom - methods called in forms (that use the @render decorator) implicitly subscribe to specific atom attributes that they access.
When the atom's attribute is updated, any render methods that subscribed to that attribute are re-rendered.

But of course, if there is no UI then there are no subscribers. So in the case of testing in isolation, it should just work since atom's don’t really know anything about the render methods that subscribed to them.

e.g. in the count_atom example:

def test_count_atom():
    count_atom.value = 0
    assert count_atom.get_count() == 0
    count_atom.update_count(1)
    count_atom.update_count(1)
    assert count_atom.get_count() == 2

It’s definitely early days for the module.
But early adopters will help shape its direction :wink: .

(side note: we explored redux - but ended up with a more mobx inspired state manager)

4 Likes