Skip to content
This repository was archived by the owner on Sep 23, 2019. It is now read-only.
This repository was archived by the owner on Sep 23, 2019. It is now read-only.

Add support for constructor-level Query annotation #5

@nweedon

Description

@nweedon

References:
https://angular.io/docs/js/latest/api/annotations/QueryFactory-interface.html
https://angular.io/docs/js/latest/api/annotations/QueryAnnotation-class.html
https://angular.io/docs/js/latest/api/annotations/DirectiveAnnotation-class.html

Haxe 3.2 doesn't support parameter metadata, so this data should be added to the constructor instead. However, this means that the metadata can only be retrieved at build-time, as RTTI cannot retrieve metadata on constructors (to my knowledge).

Using this example:

@Directive({ ... })
@:expose
class MyDirective
{
    @Query(["testcompile.Dependency"])
    public function new(?dependency : QueryList<Dependency>)
    {
        // ...
    }
}

The data can be retrieved similarly to below. The metadata should be retrieved

var constr : Field = Lambda.find(fields, function(f : Field)
{
    return f.name == "new";
});

if (constr != null)
{
    trace(constr.meta);  // Constructor metadata (@Query)
}

Angular 2 parameters can then be updated with the types provided in the metadata:

MyDirective.parameters = [
  [new ng.Query(testcompile.Dependency)]
]

Specification:
Query Annotation sits on a components' constructor and takes the form of:
@Query([ QueryField, ... ])

Where QueryField is defined as:
EitherType<String, QueryConstructorData>

Where QueryConstructorData is defined as:
{ selector : String, extra : Dynamic }

Alternatively, the annotation could sit on the class declaration, but this moves the annotation further away from the constructor and potentially makes the annotation more difficult to understand, however, this would mean that the annotation can be used in non-compiled builds (builds which don't use the build compiler metadata).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions