Skip to content

feat: pre UI code #1422

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

feat: pre UI code #1422

wants to merge 3 commits into from

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Apr 2, 2025

Inside the generated controllers it looks like this:

  // Generated code that must be executed before all UI and/or
  // controller code. One example is all model and collection
  // declarations from markup.

  // Generated UI code

and after that it will add the code of the controller. Currently there is no way (unless someone knows one) to put controller code before creating all the UI code which e.g. calls createController and creates sub controllers already.
Only Backbone collections are before the UI code.

Alloy already provides a pre field for "pre code" stuff but it is not used.

This PR will add a way to use a method called __pre() to fill that property. So all you code inside function __pre(){} will be added before the // Generated UI code section.

Example:

  • create an Alloy project
  • create e.g. a TabGroup where you require the Tab from a different controller
  • add a console.log("controller") in that controller
  • add function __pre(){console.log("index");} into index.js

"index" should be logged before "controller"

Note
We can change the name of the method to something else like __alloy_preCode or so. Just to make it more unlikely to cause conflicts with existing function names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant