예제 #1
0
async def test_render_raw_vdom_dict_with_single_element_object_as_children():
    history = RenderHistory()

    @history.track("main")
    @idom.element
    async def Main(self):
        return {"tagName": "div", "children": Child()}

    @history.track("child")
    @idom.element
    async def Child(self):
        return {"tagName": "div", "children": {"tagName": "h1"}}

    async with idom.Layout(Main()) as layout:
        render = await layout.render()

    assert render == LayoutUpdate(
        src=history.main_1.id,
        new={
            history.child_1.id: {
                "tagName": "div",
                "children": [{"type": "obj", "data": {"tagName": "h1"}}],
            },
            history.main_1.id: {
                "tagName": "div",
                "children": [{"type": "ref", "data": history.child_1.id}],
            },
        },
        old=[],
        error=None,
    )
예제 #2
0
파일: idom.py 프로젝트: brl0/panel
    def _get_model(self, doc, root=None, parent=None, comm=None):
        from idom.core.layout import LayoutUpdate
        from idom.config import IDOM_CLIENT_IMPORT_SOURCE_URL

        # let the client determine import source location
        IDOM_CLIENT_IMPORT_SOURCE_URL.set("./")

        if comm:
            url = '/panel_dist/idom/build'
        else:
            url = '/' + LOCAL_DIST + 'idom/build'

        if self._idom_loop is None:
            self._setup()

        update = LayoutUpdate.create_from({}, self._idom_model)
        props = self._init_params()
        model = self._bokeh_model(event=[update.path, update.changes],
                                  importSourceUrl=url,
                                  **props)
        if root is None:
            root = model
        self._link_props(model, ['msg'], doc, root, comm)

        if root is None:
            root = model
        self._models[root.ref['id']] = (model, parent)
        return model
예제 #3
0
async def test_layout_render_error_has_partial_update():
    history = RenderHistory()

    @history.track("main")
    @idom.element
    async def Main(self):
        return idom.html.div([OkChild(), BadChild()])

    @history.track("ok_child")
    @idom.element
    async def OkChild(self):
        return idom.html.div(["hello"])

    @idom.element
    async def BadChild(self):
        raise ValueError("Something went wrong :(")

    async with idom.Layout(Main()) as layout:

        update = await layout.render()
        assert isinstance(update.error, ValueError)

        assert update == LayoutUpdate(
            src=history.main_1.id,
            new={
                history.ok_child_1.id: {
                    "tagName": "div",
                    "children": [{"type": "str", "data": "hello"}],
                }
            },
            old=[],
            error=update.error,
        )
예제 #4
0
def test_layout_update_create_from_apply_to():
    update = LayoutUpdate.create_from({
        "a": 1,
        "b": [1]
    }, {
        "a": 2,
        "b": [1, 2]
    })
    assert update.apply_to({"a": 1, "b": [1]}) == {"a": 2, "b": [1, 2]}
예제 #5
0
 def _idom_on_msg(self, message, buffers):
     m_type = message.get("type")
     if m_type == "client-ready":
         v_id = message["viewID"]
         self._idom_views.add(v_id)
         update = LayoutUpdate("", None, self._idom_model)
         diff = VdomJsonPatch.create_from(update)
         self.send({"viewID": v_id, "data": diff})
     elif m_type == "dom-event":
         asyncio.run_coroutine_threadsafe(
             self._idom_layout.deliver(LayoutEvent(**message["data"])),
             loop=self._idom_loop,
         )
     elif m_type == "client-removed":
         v_id = message["viewID"]
         if v_id in self._idom_views:
             self._idom_views.remove(message["viewID"])
예제 #6
0
파일: idom.py 프로젝트: rmorshea/panel
    def _get_model(self, doc, root=None, parent=None, comm=None):
        from idom.core.layout import LayoutUpdate
        if comm:
            url = '/panel_dist/idom/build/web_modules'
        else:
            url = '/'+LOCAL_DIST+'idom/build/web_modules'

        if self._idom_loop is None:
            self._setup()

        update = LayoutUpdate.create_from({}, self._idom_model)
        props = self._init_params()
        model = self._bokeh_model(
            event=[update.path, update.changes], importSourceUrl=url, **props
        )
        if root is None:
            root = model
        self._link_props(model, ['msg'], doc, root, comm)

        if root is None:
            root = model
        self._models[root.ref['id']] = (model, parent)
        return model
예제 #7
0
def test_vdom_json_patch_create_from_apply_to():
    update = LayoutUpdate("", {"a": 1, "b": [1]}, {"a": 2, "b": [1, 2]})
    patch = VdomJsonPatch.create_from(update)
    result = patch.apply_to({"a": 1, "b": [1]})
    assert result == {"a": 2, "b": [1, 2]}