Angular: Repurpose `Inject`

Created on 13 Apr 2018  路  3Comments  路  Source: angulardart/angular

Since https://github.com/dart-lang/angular/commit/cfab80fa46e9388f5a7defe46951e8839619b842, we can now use an OpaqueToken directly as an annotation instead of having to wrap it in @Inject(). Here is the example from that commit:

const baseUrl = const OpaqueToken<String>('baseUrl');

class Comp1 {
  Comp1(@Inject(baseUrl) String url);
}

class Comp2 {
  Comp2(@baseUrl String url);
}

Is there any other use for Inject? If not, how about deprecating it?

Related: #1236

cc @kwalrath

compiler runtime 鈿ew feature

Most helpful comment

Good question. One thing we discussed was Injection-selection APIs.

Here is my idea, as I hate having 4-5 top-level annotations for this purpose:
(from https://github.com/dart-lang/angular/pull/1186)

abstract class Inject {
  // Used to be @SkipSelf()
  static const fromAncestors = const ...;

  // Used to be @Parent()
  static const fromParent = const ...;

  // Used to be @Self()
  static const fromSelf = const ...;

  // Used to be @Optional()
  static const nullIfMissing = const ...;

  const Inject._;
}

... and then keeping around Inject just as a namespace here.

All 3 comments

Good question. One thing we discussed was Injection-selection APIs.

Here is my idea, as I hate having 4-5 top-level annotations for this purpose:
(from https://github.com/dart-lang/angular/pull/1186)

abstract class Inject {
  // Used to be @SkipSelf()
  static const fromAncestors = const ...;

  // Used to be @Parent()
  static const fromParent = const ...;

  // Used to be @Self()
  static const fromSelf = const ...;

  // Used to be @Optional()
  static const nullIfMissing = const ...;

  const Inject._;
}

... and then keeping around Inject just as a namespace here.

BTW, I'm not sure about nullIfMissing, since I _prefer_ https://github.com/dart-lang/angular/issues/553.

FYI: This was accepted, but will not be done for 5.x. Targeting >=5.1, remove old APIs in 6.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

supermuka picture supermuka  路  5Comments

4cm4k1 picture 4cm4k1  路  5Comments

jrote1 picture jrote1  路  6Comments

matanlurey picture matanlurey  路  3Comments

Tomucha picture Tomucha  路  5Comments