slash.reactive

class slash.reactive.Computed(fn)

Bases: Generic[T]

Reactive value computed from other reactive values.

Parameters:

fn (Callable[[], T]) – Function that computes the value from other reactive values.

get()

Return the current value.

Return type:

T

to_elem(tag='span')

Create an element whose content is the computed value.

The content of the returned element gets updated with the computed value.

Parameters:

tag (str) – Tag of the element.

Returns:

Element with given tag whose content equals the computed value.

Return type:

Elem

class slash.reactive.Effect(fn)

Bases: object

Reactive effect that runs automatically when the reactive values that it depends are updated.

Parameters:

fn (Callable[[], Any]) – Function that executes the effect from reactive values.

class slash.reactive.Signal(value)

Bases: Generic[T]

Reactive value that notifies observers when updated.

Parameters:

value (T) – Initial value.

get()

Return the current value.

Return type:

T

set(value)

Set the value and notify all observers if it has changed.

Parameters:

value (T) – New value to set.

Return type:

None

to_elem(tag='span')

Create an element whose content is the value of the signal.

The content of the returned element gets updated with the value of the signal.

Parameters:

tag (str) – Tag of the element.

Returns:

Element with given tag whose content equals the value of the signal.

Return type:

Elem

trigger()

Trigger all observers without changing the value.

Return type:

None