rokucommunity / rokucommunity/brighterscript

Set m.[xmlElementId] for every component

Open
#164 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

BrighterScript enhancement
Dominant language
TypeScript
Stars
208
Forks
68
Avg merge
8h 39m
Merged PRs (30d)
39

Description

BrighterScript should add a feature to expose every xml element by its ID onto m. For example:

<Rectangle id = "Rectangle1"/>

should somehow generate

sub init()
    m.Rectangle1 = m.top.findNode("Rectangle1")
end sub

This should also work for node inheritance.

Currently, the plan is:

  1. generate a function called something like bs_assignNamedNodesToM() for every component.
  2. If a component extends a parent, update the function to handle whether the parent is calling the function or IT is calling the function. This can be done because we know the Roku calls init from top-to-bottom in component inheritance, so Grandparent would be call 1, parent would be call 2, and child would be call 3. This also prevents exceptions for when child xml nodes don't exists, preventing unnecessary lookups in parent functions.
  3. Inject this call into the init() function of every component. If the component doesn't have an init function, create one for it and inject it into the component's XML.

Here are a few examples (Names simplified for this example).

GrandparentComponent.brs

sub bs_assignNamedNodesToM()
    m.GrandparentGroup= m.top.findNode("GrandparentGroup")
end sub

ParentComponent.brs

sub bs_assignNamedNodesToM()
    'Grandparent
    if m.bs_assignNameNodesToM_index = invalid then
        m.GrandparentGroup= m.top.findNode("GrandparentGroup")
        m.bs_assignNameNodesToM_index = 1

    'parent
    else
            m.ParentGroup= m.top.findNode("ParentGroup")
     end if
end sub

ChildComponent.brs

sub bs_assignNamedNodesToM()
    'Grandparent
    if m.bs_assignNameNodesToM_index = invalid then
        m.GrandparentGroup= m.top.findNode("GrandparentGroup")
        m.bs_assignNameNodesToM_index = 1
    else   

        'Parent
        if m.bs_assignNameNodesToM_index = 1 then
            m.ParentGroup= m.top.findNode("ParentGroup")

        'Child
        else
            m.ChildGroup= m.top.findNode("ChildGroup")
        end if
        'increment the node index so the next init call in the component chain will call the right stuff
        m.bs_assignNameNodesToM_index++
    end if
end sub

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the component init-generation path described in the issue and trace how XML components, inheritance, and generated BrightScript are handled. Implement the named-node assignment behavior across grandparent, parent, and child components, including components without init functions, and verify that each XML id is exposed on m without unnecessary lookups or exceptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.