Skip to content

Allow NoneType and Iterable returns within components #538

Closed
@Archmonger

Description

@Archmonger

Current Situation

NoneType

There are instances where the user may genuinely want to pretend like a component doesn't exist (ex. Django IDOM conditional rendering based on authentication). Currently, exceptions are generated if a component returns NoneType.

2021-11-21T13:15:57-0800 | ERROR | Failed to render homepage(1408449473488, websocket=<django_idom.websocket_consumer.IdomAsyncWebsocketConsumer object at 0x00000147EB0C4B80>)
Traceback (most recent call last):
  File "C:\Users\Username\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 201, in _render_component
    self._render_model(old_state, new_state, raw_model)
  File "C:\Users\Username\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 236, in _render_model
    new_state.model.current = {"tagName": raw_model["tagName"]}
TypeError: 'NoneType' object is not subscriptable

Iterables

In many situations, not allowing for iterable return type increases the the DOM depth can be unnecessarily. For example, in my circumstances, my components are almost always returning nothing but several other components. I need to add an unnecessary div wrapper to get the component rendering working. From Django IDOM's side, this makes for the top-level component div, and then a second wrapper div directly below it.
image

2021-11-21T13:18:52-0800 | ERROR | Failed to render homepage(1628060950176, websocket=<django_idom.websocket_consumer.IdomAsyncWebsocketConsumer object at 0x0000017B0FF1B6A0>)
Traceback (most recent call last):
  File "C:\Users\Username\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 201, in _render_component
    self._render_model(old_state, new_state, raw_model)
  File "C:\Users\Username\Repositories\Conreq\.venv\lib\site-packages\idom\core\layout.py", line 236, in _render_model
    new_state.model.current = {"tagName": raw_model["tagName"]}
TypeError: list indices must be integers or slices, not str

Proposed Changes

Allow for NoneType and Iterable return types in components.

Implementation Details

Modify idom.core.layout to detect these situations and handle them differently than the standard VDOM return type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-2-moderateShould be resolved on a reasonable timeline.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions