Unverified Commit b7a609ac authored by Duggan, John's avatar Duggan, John Committed by GitHub
Browse files

Merge pull request #25 from nova-model/24-test-allowing-multiple-connections-to-a-binding-in-trame

Allow multiple connections to a binding in trame
parents 50c97f7f 70788720
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
[tool.poetry]
name = "nova-mvvm"
version = "0.11.1"
version = "0.12.0"
description = "A Python Package for Model-View-ViewModel pattern"
authors = ["Yakubov, Sergey <yakubovs@ornl.gov>"]
readme = "README.md"
+14 −6
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
import asyncio
import inspect
import json
from typing import Any, Callable, Optional, Union, cast
from typing import Any, Callable, List, Optional, Union, cast

from pydantic import BaseModel, ValidationError
from trame_server.state import State
@@ -50,7 +50,7 @@ class TrameCommunicator(Communicator):
        self.viewmodel_linked_object = viewmodel_linked_object
        self._set_linked_object_attributes(linked_object_attributes, viewmodel_linked_object)
        self.viewmodel_callback_after_update = callback_after_update
        self.connection: Union[CallBackConnection, StateConnection]
        self.connections: List[Union[CallBackConnection, StateConnection]] = []

    def _set_linked_object_attributes(
        self, linked_object_attributes: LinkedObjectAttributesType, viewmodel_linked_object: LinkedObjectType
@@ -69,19 +69,27 @@ class TrameCommunicator(Communicator):

    @override
    def connect(self, connector: Any = None) -> ConnectCallbackType:
        new_connection: Union[CallBackConnection, StateConnection]
        if is_callable(connector):
            self.connection = CallBackConnection(self, connector)
            new_connection = CallBackConnection(self, connector)
        else:
            connector = str(connector) if connector else None
            if connector:
                check_binding(self.viewmodel_linked_object, connector)
                bindings_map[connector] = self
            self.connection = StateConnection(self, connector)
        return self.connection.get_callback()
            new_connection = StateConnection(self, connector)

        self.connections.append(new_connection)

        return new_connection.get_callback()

    @override
    def update_in_view(self, value: Any) -> None:
        self.connection.update_in_view(value)
        if not self.connections:
            raise ValueError("You must call connect on this binding before calling update_in_view.")

        for connection in self.connections:
            connection.update_in_view(value)


class CallBackConnection: