Skip to content

Transformers create constructor stubs #496

@mhevery

Description

@mhevery

Create a setupReflection method which registers constructor stubs.

Given this source:

@Component(...)
class MyComponent {
  MyComponent(MyClass dep);
}

@Injectable()
class MyClass {
  MyClass(@Url String name);
}

main() {
  bootstrap(MyComponent);
}

generate:

import 'package:path/to/above/file' as file1;
import 'package:reflection/reflection.dart' show reflector;

setupReflection() {
  reflector.registerType(
    file1.MyComponent, 
    factory: (file1.MyClass dep) => new file1.MyComponent(dep),
    paramaters: const [cost [file1.MyClass]]
  );
  reflector.registerType(
    file1.MyClass, 
    factory: (String name) => new file1.MyClass(name),
    paramaters: const [cost [Url, String]]
  );
}

Only the types which are annotated with: Component, Decorator, Template, and Inject need to have the corresponding stubs generated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions