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

Directives should support module publishing. #652

Closed
@mhevery

Description

@mhevery

When the directive is trigger its annotation should allow for modules which would be merged into the injector. In this way the directive could do more then just instantiate itself. It could also override instances, or create a whole collection of instances.

This should replace publishTypes annotation property.

We have a publishTypes https://docs.angulardart.org/#angular/angular.NgAnnotation@id_publishTypes annotation.

It is used like this

@NgDirective({
  publishTypes: [SomeInterface]
})
class SomeDirective implements SomeInterface {
}

The reason for this is that if we could have multiple directives which implement SomeInterface we would like for to inject it as SomeInterface. The issue is that when the module gets registered it will say something like this:

module.type(SomeDirective)

This means that asking for SomeInterface will return error. What the publishTypes property does is do an extra registration like so:

module.type(SomeDirective)
module.factory(SomeInterface, (i) => i.get(SomeDirective));

This enables one to ask for SomeInterface and get SomeDirective implementation.

But this is really just one specific use case. A more generic case is that a Directive should be able to create a custom module definition which should be loaded into the injector. Then the directive can performa a lot more.

Something like so:

@NgDirective({
  module: SomeDirective.module;
})
class SomeDirective implements SomeInterface {
  static _module = new Module()
        ..factory(SomeInterface, (i) => i.get(SomeDirective))
        ..type(SomeOtherType)
  static module() => _module;
}

This way not only can a directive implement different types, but it can also publish its own types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions