Read both files
The project generated in lesson 01 already uses named Logic. A formula names a method with func; that method returns the calculated value. A Logic module exports class Logic. The Python Page remains the place where inputs and their bindings are declared.
Read the Named logic gallery example with its Python and Logic tabs. Follow one parameter into the method and the return value back to the formula’s result path. A reusable function does not need a second binding language.
Initialize at the appropriate stage
Data declarations are installed before the first DOM build. _init is for initialization before rendering; _onBuilt follows the first successful build; _onStart runs when the page is ready. Use the stage that matches the work.
A method that needs a rendered element cannot assume that element exists during _init. Removing a declaration also releases its owned subscriptions and timers. Save code changes in the authored files and reload through the normal host lifecycle.
Your turn
Try it yourself
- In your generated hello project, locate the func name in Python and the corresponding method in pages/index.js.
- Change only a literal part of the greeting returned by that method. Save, restart and reload.
- Open Lifecycle and compare the reported order with your prediction.
Check your understanding
Does using a named method move the calculation onto the Python server?
Show the answer and expected result
No. Named Logic still runs in the browser. It separates browser code from the declarations, supports reuse and works with the generated strict CSP profile. A server calculation is an endpoint, introduced later.