Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow NoneType and Iterable returns within components #538

Closed
Archmonger opened this issue Nov 21, 2021 · 1 comment · Fixed by #672
Closed

Allow NoneType and Iterable returns within components #538

Archmonger opened this issue Nov 21, 2021 · 1 comment · Fixed by #672
Labels
priority-2-moderate Should be resolved on a reasonable timeline. type-feature About new capabilities
Milestone

Comments

@Archmonger
Copy link
Contributor

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.

@Archmonger Archmonger added the flag-triage Not prioritized. label Nov 21, 2021
@rmorshea
Copy link
Collaborator

rmorshea commented Nov 22, 2021

This one's definitely on my radar. Though there's some reasons returning lists and tuples directly isn't a great idea. React allows for something called fragments (<>...</>). In IDOM we could do something similar with html._(...).

@rmorshea rmorshea added type-feature About new capabilities and removed flag-triage Not prioritized. labels Nov 22, 2021
@rmorshea rmorshea modified the milestones: 3.0, 2.0 Jan 11, 2022
@rmorshea rmorshea added the priority-2-moderate Should be resolved on a reasonable timeline. label Jan 13, 2022
@rmorshea rmorshea mentioned this issue Feb 17, 2022
@Archmonger Archmonger modified the milestones: 2.0, 1.0 Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-2-moderate Should be resolved on a reasonable timeline. type-feature About new capabilities
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants