ethul / purescript-angular

AngularJS 1.2 bindings for PureScript (currently in the experimental stage)
MIT License
23 stars 3 forks source link

Handle arbitrary locals to be injected as dependencies #2

Closed ethul closed 10 years ago

ethul commented 10 years ago

The way angular dependencies are handled currently is by accessing the injector on the document element, and then getting the dependency through the that injector instance.

This does not work for accessing locals that could normally be injected into a controller, for example. The work-around is to manually pass the known locals to the controller function. For example, in a directive controller function, $scope, $element, $attrs, $transclude, are all explicitly passed in. However, this does not allow user-defined locals.

I think the way dependencies are handled could use further development. One idea is to match more closely how dependencies are specified in angular. For example we could defined the controller as:

foreign import controller
  "..."
  :: forall e r i h a b c d
  .  String
  -> Module
  -> { | i }
  -> ({ | h } -> ConstructorFnEff e r a b c d)
  -> Eff (ngwmod :: WriteModule | e) Module

And use it like

fooController m =
  controller "FooController" m { http: httpDependency
                               , this: thisDependency
                               , scope: scopeDependency } \inj -> writeScopeState { foo: "test" } inj.scope

However, since we defined { | i} and { | h} using different type parameters, the access of the keys for inj are not constrained by what dependencies are passed in for { | i}. It would be ideal to somehow enforce a key constraint.

ethul commented 10 years ago

Closing until a more elegant solution is found. The manual specification of angular components will hopefully be okay in the meantime.