rang icon indicating copy to clipboard operation
rang copied to clipboard

Is it better to automate @register() ?

Open bcamp1973 opened this issue 11 years ago • 4 comments

Excellent library! Thank you for sharing :)

Question: Would it make sense to automate the @register() method? Unless I misunderstand, it seems that in most applications, nearly all controllers will likely call the @register() method the same way?

myApp = angular.module('myApp',[])

class @ExampleCtrl extends @RangCtrl
    @register myApp # <- always the same for a given application

Wouldn't it make sense if myApp was defined globally...maybe like so...

angular
    .module('myApp.constants',[])
    .constant(
        "APP":
            "NAME": "myApp"
            "VERSION": "1234"
            ...
    )

and @RangCtrl's constructor did something like this...

constructor: (args...) ->
    name ?= @name || @toString().match(/function\s*(.*?)\(/)?[1]
    $window[APP.NAME].controller name, @ # <- automatic registration
    ...

I guess this would require that rang is set up as a factory or ``provider` so that it can accept dependency injection? Not sure how that would work?

bcamp1973 avatar Apr 07 '14 16:04 bcamp1973

Thanks for commenting you're the first ! It's a good idea. I want to implement convention over configuration feature, with possibility to override it. What about

@Rang.config 
  app_name: 'myPersonalized'
  template_url: 'personaliezed/template/path'

ranska avatar Apr 10 '14 14:04 ranska

Good idea, i like that approach!

bcamp1973 avatar Apr 10 '14 15:04 bcamp1973

Hihi ! I have push some new code and update readme. Tell me what do think about.

ranska avatar May 03 '14 18:05 ranska

So after few days. Because directive force me to write register at the end of file. I have starting to rethink the overall register concept. I a have write https://github.com/ranska/aether for it. AEther is batch coffeescript class meta programming and batch call methods lib. Yup !

So now AEther will inject @register and call it just after app definition. THis is so cool i have spend lot off time to try meta progamming coffee and learn a lot.

ranska avatar May 11 '14 08:05 ranska