Skip to content
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

Controller macro code generation ignores traits #81

Open
dejvid opened this issue Aug 21, 2015 · 0 comments
Open

Controller macro code generation ignores traits #81

dejvid opened this issue Aug 21, 2015 · 0 comments

Comments

@dejvid
Copy link

dejvid commented Aug 21, 2015

Hi I've noticed that macro for controller code generation does not generate defs and vars defined in trait. Below are two samples. After clicking button in example 1 nothing happens, but in example 2 TODO: refresh maps is printed in console. Would be possible to extend controller code generation to traits defs and vars, this would be really helpful or are there some annotations to accomplish that.

Example code 1:

trait  CommonView {
  var currentView = "map"
  def refreshMaps() = println("TODO: refresh maps")
}

class UserDetailsCtrl ($location: Location, $scope: Scope) extends Controller with CommonView {
  currentView = "map"
}

HTML:

<div ng-controller="UserDetailsCtrl as ctl">
  {{ctl.currentView}}
 <button ng-click="ctl.refreshMaps()">Refresh</button>
</div>

Example 1 debug macro code generation output:

[info] {
[info]   import scala.scalajs.js;
[info]   import js.Dynamic.{global, literal};
[info]   module.self.controller("UserDetailsCtrl", js.Array[Any]("$location", "$scope", ((((scope: js.Dynamic, x$macro$12: biz.enef.angulate.core.Location, x$macro$13: biz.enef.angulate.Scope) => {
[info]     val ctrl = new client.angular.UserDetailsCtrl(x$macro$12, x$macro$13);
[info]     global.console.debug("Created Controller ".+("UserDetailsCtrl"), ctrl.asInstanceOf[js.Dynamic], "with scope:", scope);
[info]     scope
[info]   })): js.ThisFunction)))
[info] }
[info]       
[info]     module.controllerOf[UserDetailsCtrl]("UserDetailsCtrl")
[info] 

Example code 2:

trait  CommonView {
  var currentView = "map"
}

class UserDetailsCtrl ($location: Location, $scope: Scope) extends Controller with CommonView {
  currentView = "map"
 def refreshMaps() = println("TODO: refresh maps")
}

HTML:

<div ng-controller="UserDetailsCtrl as ctl">
  {{ctl.currentView}}
 <button ng-click="ctl.refreshMaps()">Refresh</button>
</div>

Example 2 debug macro code generation output:

[info] {
[info]   import scala.scalajs.js;
[info]   import js.Dynamic.{global, literal};
[info]   module.self.controller("UserDetailsCtrl", js.Array[Any]("$location", "$scope", ((((scope: js.Dynamic, x$macro$16: biz.enef.angulate.core.Location, x$macro$17: biz.enef.angulate.Scope) => {
[info]     val ctrl = new client.angular.UserDetailsCtrl(x$macro$16, x$macro$17);
[info]     {
[info]       global.Object.defineProperty(scope, "refreshMaps", literal(value = (() => ctrl.refreshMaps())));
[info]       global.console.debug("Created Controller ".+("UserDetailsCtrl"), ctrl.asInstanceOf[js.Dynamic], "with scope:", scope)
[info]     };
[info]     scope
[info]   })): js.ThisFunction)))
[info] }
[info]       
[info]     module.controllerOf[UserDetailsCtrl]("UserDetailsCtrl")


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

No branches or pull requests

1 participant