-
Notifications
You must be signed in to change notification settings - Fork 248
[WIP] refactor: Drop the Controller directive #1040
Conversation
var ballClassName = 'ball'; | ||
|
||
BounceController(this.scope) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Scope could not be injected in the root "controller". It would cause a circular dependency (Scope.context = controller).
I should work on a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by implementing ScopeAware
@mhevery I have added some inline comment / questions. It would be great if you have some time to review and comment back. Thanks. |
In the last commit, the This is to avoid potential side effects. Two side effects have been detected thanks to this:
|
@mhevery about the ng_form issue, the only solution is see for now is to convert it from a Decorator to a Component so that each form/control has its own context and can access parents/child. Can you think of any other solution ? |
I have rebased this PR on the latest master. @jbdeboer or @markovuksanovic you are probably more familiar with the zones, could you please take a look at the last commit ? (It seems that the exception is not rethrown and then The PR description has been updated with the remaining items. |
closes dart-archive#919 closes dart-archive#917 1) The @controller annotation is no more It is possible to define the context of the root scope with: applicationFactory() ..rootContextType(RootContext) ..run(); The RootContext needs to be annotated with @Injectable(): @Injectable() class RootContext { // ... } 2) You can not inject a scope in a component or in theroot context any more As the Scope context is set to the Component instance, the scope could not be injected any more. Components should implements the "ScopeAware" interface and declare a "scope" setter in order to get hold of the scope. before: @component(...) class MyComponent { Watch watch; Scope scope; MyComponent(Dependency myDep, Scope scope) { watch = scope.rootScope.watch("expression", (v, p) => ...); } } after: @component(...) class MyComponent implements ScopeAware { Watch watch; MyComponent(Dependency myDep) { // It is an error to add a Scope / RootScope argument to the // ctor and will result in a DI circular dependency error // The scope is never accessible in the class constructor } void set scope(Scope scope) { // This setter gets called to initialize the scope watch = scope.rootScope.watch("expression", (v, p) => ...); } } or @component(...) class MyComponent implements ScopeAware { Scope scope; MyComponent(Dependency myDep) { // It is an error to add a Scope / RootScope argument to the // ctor and will result in a DI circular dependency error // The scope is never accessible in the class constructor } }
Closes dart-archive#915 1) Now "a.b" return a.b and "a['b']" return a['b'] Before this change a.b would have match either a.b or a['b']. The reason is that the context was a Map (before dart-archive#914) and we don't want to write ctrl['foo'] but ctrl.foo. It was also not possible to access Map properties, ie map.length would have returned map['length']. 2) Accessing probes The probes are no more accessible directly in the rootScope context but in a $probes map on the rootScope context. Before: <p probe="prb"></p> var probe = rootScope.context['prb']; After: <p probe="prb"></p> var probe = rootScope.context.$probes['prb'];
For information: This PR has been rebased on master in vicb/angular.dart@angular:master...vicb:0714-controller. Notes:
|
When is "feat: Removing implicit map dereference in expressions" going to be released? Just stumbled over it while debugging {{ctrl.map.keys}} not working as expected ^^ Thanks, |
@mhevery is working on landing the new bind syntax + removal of |
closes #919
closes #917
closes #915
Replaces #959
See the commit comments for a detailed explanation of the changes and BC breaks
TODO:
ScopeLocals
to an instance of the controller)