A BrighterScript plugin that auto-injects m.top.findNode() calls in your component init() functions
- Install the package via npm:
npm install bsc-plugin-auto-findnode- Add the plugin to your
bsconfig.json
- Run brighterscript like normal, and the plugin will work!
npx bsc- find every xml file in the project
- find every element with an ID in that xml file
- find the
init()function for each scope (or create one in a new file) - 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 subAfter:
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
{ "plugins": [ "bsc-plugin-auto-findnode" ] }