angelos.lib.reactive

Module for reactive programming, using the observer pattern.

class angelos.lib.reactive.Event(sender: NotifierMixin, action: int = 0, data: dict = None)

Bases: object

Event used to notify the observer.

Parameters
  • sender (NotifierMixin) – The notifier instance.

  • action (int) – Action taken by the notifier.

  • data (dict) – Data related to the action.

sender

The sender instance.

Type

NotifierMixin

action

Recent action to notify.

Type

int

data

Data related to the action.

Type

dict

property action

Action.

Returns

Recent action to notify.

Return type

int

property data

Data

Returns

Related data.

Return type

dict

property sender

Sender property.

Returns

The sender instance.

Return type

NotifierMixin

class angelos.lib.reactive.NotifierMixin

Bases: object

Mixin to implement the notifier pattern.

__subscribers

All subscribers that observe.

Type

Set[ObserverMixin]

notify_all(action: int, data: Optional[dict] = None) → _asyncio.Task

Invoke this method to notify all observers about an action.

This method

Parameters
  • action (int) – Integer representation of the action.

  • data (dict) – Data associated with the action.

Returns

Returns a task that gather all the notify() coroutines.

Return type

asyncio.Task

subscribe(observer: angelos.lib.reactive.ObserverMixin, internal: bool = False) → None

Adds a subscriber to the notifier to be notified.

Parameters
  • observer (ObserverMixin) – The subscriber class.

  • internal (bool) – Internal use only.

unsubscribe(observer: angelos.lib.reactive.ObserverMixin, internal: bool = False) → None

Removes subscriber from the notifier

Parameters
  • observer (ObserverMixin) – Observer to be removed.

  • internal (bool) – Internal use only.

class angelos.lib.reactive.ObserverMixin

Bases: object

Mixin used to implement the observer patterh.

The observer will be notified fron notifiers to whom it subscribes.

__subscriptions

All notifiers subscribed to.

Type

Set[NotifierMixin]

add_subscription(notifier: angelos.lib.reactive.NotifierMixin, internal: bool = False) → None

Add a subscription to the observer.

Parameters
  • notifier (NotifierMixin) – Description of parameter notifier.

  • internal (bool) – Internal use only.

end_subscription(notifier: angelos.lib.reactive.NotifierMixin, internal: bool = False) → None

End subscription from notifier.

Parameters
  • notifier (NotifierMixin) – Notifier to end subscription.

  • internal (bool) – Internal use only`.

notify(event: angelos.lib.reactive.Event) → None

Invoked by the notifier.

This method should be implemented on the observer class.

Parameters

event (Event) – The nofitication itself.

class angelos.lib.reactive.ReactiveAttribute(attribute: unicode, value: Any = None)

Bases: angelos.lib.reactive.NotifierMixin

A class holding a value that can be subscribed to.