scalajs-angulate icon indicating copy to clipboard operation
scalajs-angulate copied to clipboard

Controller attributes are accessible only after a clean

Open joaopmafra opened this issue 9 years ago • 4 comments

Hi all,

If I define a controller like this

class CounterCtrl extends Controller { }

and run the application with ~fastOptJS, all attributes added to controller will only be accessible from within the view after I clean the application and run it again. For example, if I start the application with ~fastOptJS and then add an attribute "foo" to the controller

class CounterCtrl extends Controller {
  var foo = "bar"
}

I need to stop the application, issue a clean, and start it again for the "foo" attribute be accessible within the view. The same thing doesn't happen with scope controllers.

Tested against angulate 0.2 and scalajs 0.6.2. I have a small project to demonstrate the issue: https://github.com/joaopmafra/scalajs-angulate-issues

Thanks in advance.

joaopmafra avatar May 11 '15 19:05 joaopmafra

~~ControllerMacros.createController() is not called during compile after a property was added to, or removed from a Controller. Maybe a cache problem -> check with Scala.js list~~ This is caused by the way the actual Controller code is generated: code generation happens where module.controllerOf[] is called; if the class where this call occurs is unchanged, the macro won't be called (and hence the controller code is not re-generated).

jokade avatar May 11 '15 20:05 jokade

Great! I tested with my codebase and it works the way you said. Thanks for investigating that.

Honestly, I would love to contribute to the project. But despite having 10 years of experience with java, I'm new to scala. I'm trying to learn the most important parts of the language for only then go to advanced features such macros. Thanks again.

joaopmafra avatar May 12 '15 20:05 joaopmafra

I've opened a thread on the scala-user list for this issue.

jokade avatar May 13 '15 04:05 jokade

This problem seems to be hard to solve with the current approach. We could use macro annotations on controller classes to generate the Angular.js code instead, which works quite well for angulate2. But that would mean to depend on macro paradise. Maybe we should provide annotations support in add-on library (or sbt plugin)?

jokade avatar May 24 '15 21:05 jokade