question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In order to compose pages one can parse html or one can manually create instances of JustPy classes and connect them together with the add method or with the a=comp_ref construct (the docs prefer the latter). eg:

        c3 = jp.QItem(clickable=True, v_ripple=True, a=c2, click=button_click)
        c3.user_name = u['name']

        c4 = jp.QItemSection(avatar=True, a=c3)
        c5 = jp.QAvatar(size='100px',
                        font_size='52px',
                        color=color_from_state(u['state']),
                        text_color='white',
                        icon=icon_from_state(u['state']),
                        a=c4)
        c3.avatar = c5

        c6 = jp.QItemSection(a=c3)
        c7 = jp.QItemLabel(a=c6, classes=['text-h3'], text=u['name'])
        c8 = jp.QItemLabel(caption=True, a=c6, text=u['state'])
        c3.state_label = c8

        c9 = jp.QSeparator(spaced=True, inset=True, a=c2)

When using this manual construction method one gives up the visual nesting that is clear in HTML code. This makes it harder to see the page’s structure (IMHO). Maybe an alternative construction method could be useful:

        c3 = jp.QItem([ 
                jp.QItemSection(avatar=True),
                jp.QAvatar(size='100px',
                        font_size='52px',
                        color=color_from_state(u['state']),
                        text_color='white',
                        icon=icon_from_state(u['state'])),
                jp.QItemSection( [
                        jp.QItemLabel(classes=['text-h3'], text=u['name'])
                        jp.QItemLabel(caption=True, a=c6, text=u['state'])),
                ],
                jp.QSeparator(spaced=True, inset=True, a=c2)
          ],
          clickable=True, v_ripple=True, a=c2, click=button_click)
       )

or with a kwarg ‘children=[]’. I agree that this could get messy as well (just look at JS code), but it does make the structure clearer. What do you think?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
elimintzcommented, Apr 23, 2020

Got it. I added the children kwarg, it will be in the next version.

0reactions
knoxvilledatabasecommented, Apr 23, 2020

Although I’ve now gotten used to writing JustPy code without nesting, before switching to JustPy we wrote a ReactJS solution similar (yet not nearly as powerful) using code nesting:

Div(     Span(         text='Hello World',         classnames='test',         style='margin-top:50px',     ),     classnames='test_div',     style='margin-bottom:10px', )

This nesting concept originally came from https://github.com/django-crispy-forms/django-crispy-forms

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nesting (computing) - Wikipedia
In computing science and informatics, nesting is where information is organized in layers, or where objects contain other similar objects.
Read more >
Computer Programming/Coding Style/Minimize nesting
Deeply nested code is a common feature of structured programming. While it has some advantages, discussed in that section, it is frequently considered...
Read more >
What is nesting in programming? - Quora
It means that you use one structured programming construct within another one. These constructs may include things like “if”, “for”, “while”, and others....
Read more >
Untangling Nested Code - DEV Community ‍ ‍
Nested code blocks often return a value. When these are boolean values, there's an opportunity to condense the code block and return the ......
Read more >
Nesting - Programming constructs - OCR - BBC Bitesize - BBC
Nesting. occurs when one programming construct is included within another. Nesting allows for powerful, yet simple programming. It reduces the amount of code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found