angular icon indicating copy to clipboard operation
angular copied to clipboard

Add application-level startup settings

Open matanlurey opened this issue 6 years ago • 2 comments

I'd like to propose having something like the following class available:

import 'package:meta/meta.dart';

@sealed
class AppOverrides {
  final bool enableTestability;

  const AppOverrides({
    this.enableTestability = true,
  });
}

... as a start. The runApp and runAppAsync functions would support it:

ComponentRef<T> runApp<T>(
  ComponentFactory<T> componentFactory, {
  InjectorFactory createInjector,
  AppOverrides overrides,
}) {
  // ...
}

So, for example, you could do the following:

void main() {
  runApp(
    app.AppComponentNgFactory,
    createInjector: hackerNewsApp,
    overrides: AppOverrides(
      enableTestability = false,
    ),
  );
}

... in order to disable Testability, and functionality in NgZone present only for it. This would drop the minimum amount of code-size, as well as remove a very small performance overhead currently for any registered timers within NgZone.

The class and field would also exist so we could add more "advanced" options/overrides in the future, including potentially using it to set a custom Sanitizer, completely disable NgZone, and more.

matanlurey avatar Oct 09 '18 20:10 matanlurey

One idea: Start with everything optimized instead of opting-out of deopts.

matanlurey avatar Oct 09 '18 21:10 matanlurey

I like this idea overall, but I'm not sure its compatible with the original purpose of #887 . The signature for runApp/runAppAsync is not suitable for an application that does not have a root component.

LorenVS avatar Feb 26 '19 21:02 LorenVS