Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

[WIP] refactor: Drop the Controller directive #1040

Closed
wants to merge 3 commits into from

Conversation

vicb
Copy link
Contributor

@vicb vicb commented May 13, 2014

closes #919
closes #917
closes #915
Replaces #959

See the commit comments for a detailed explanation of the changes and BC breaks

TODO:

  • investigate dart2js failures
  • Decide how to form children should be accessed (it is no more possible to add arbitrary keys to the context because we have switched from a ScopeLocals to an instance of the controller)
  • Once the previous point is solved, update the second commit comment with the change
  • fix one remaining issue with runZoned

var ballClassName = 'ball';

BounceController(this.scope) {
Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by implementing ScopeAware

@vicb
Copy link
Contributor Author

vicb commented May 13, 2014

@mhevery I have added some inline comment / questions. It would be great if you have some time to review and comment back. Thanks.

@vicb vicb added cla: yes and removed cla: no labels May 13, 2014
@vicb
Copy link
Contributor Author

vicb commented May 19, 2014

In the last commit, the TestContext does not override the operators [], []=.

This is to avoid potential side effects.

Two side effects have been detected thanks to this:

  • probes - they are now accessible through rootScope.context.$probes, see the commit comment for details,
  • form - ng_form get published to the scope, this is yet to be fixed

@vicb
Copy link
Contributor Author

vicb commented May 19, 2014

@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 ?

@mvuksano mvuksano assigned vicb and unassigned vicb May 26, 2014
@vicb
Copy link
Contributor Author

vicb commented May 28, 2014

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 .toThrow does not catch it). Thanks

The PR description has been updated with the remaining items.

vicb added 3 commits May 28, 2014 13:04
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'];
@vicb
Copy link
Contributor Author

vicb commented Jul 14, 2014

For information: This PR has been rebased on master in vicb/angular.dart@angular:master...vicb:0714-controller.

Notes:

  • There might still be some minor issues to fix (mostly related to form control access),
  • This PR will be rebased on top of 1178 once issues are fixed

@BlackHC
Copy link
Contributor

BlackHC commented Jul 25, 2014

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,
Andreas

@vicb
Copy link
Contributor Author

vicb commented Jul 25, 2014

@mhevery is working on landing the new bind syntax + removal of @Controller + no implicit dereference in master. He might have a better idea of the timing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
4 participants