Skip to content

rokucommunity/bsc-plugin-auto-findnode

Repository files navigation

bsc-plugin-auto-findnode

A BrighterScript plugin that auto-injects m.top.findNode() calls in your component init() functions

build status security coverage status monthly downloads npm version license Slack

Installation

  1. Install the package via npm:
npm install bsc-plugin-auto-findnode
  1. Add the plugin to your bsconfig.json
{
    "plugins": [
        "bsc-plugin-auto-findnode"
    ]
}
  1. Run brighterscript like normal, and the plugin will work!
npx bsc

How it works

  1. find every xml file in the project
  2. find every element with an ID in that xml file
  3. find the init() function for each scope (or create one in a new file)
  4. inject m.<elementId> = m.top.findNode("<elementId>") into the init function

For example:

Before:

pkg:/components/ZombieKeyboard.xml

<component name="ZombieKeyboard">
    <children>
        <label id="helloZombieText" />
    </children>
    <script uri="ZombieKeyboard.brs" />
</component>

pkg:/components/ZombieKeyboard.brs

sub init()
    print "init for the keyboard!"
end sub

After:

pkg:/components/ZombieKeyboard.xml

<component name="ZombieKeyboard">
    <children>
        <label id="helloZombieText" />
    </children>
    <script uri="ZombieKeyboard.brs" />
</component>

pkg:/components/ZombieKeyboard.brs

sub init()
    m.helloZombieText = m.top.findNode("helloZombieText")
    print "init for the keyboard!"
end sub

Accepted security advisories

Dependencies flagged by npm audit that we have reviewed and chosen not to upgrade are tracked in audit-ci.jsonc. Each entry includes the advisory ID, the date it was added, and the reason it does not apply to this project.

About

A BrighterScript plugin that auto-injects `m.top.findNode()` calls in your component `init()` functions

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors