Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View Injection Hidden Feature #180

Open
prankard opened this issue Sep 20, 2015 · 0 comments
Open

View Injection Hidden Feature #180

prankard opened this issue Sep 20, 2015 · 0 comments

Comments

@prankard
Copy link

Currently there is a hidden feature due to this line in MediatorFactory.as:

mapTypeForFilterBinding(mapping.matcher, type, item);
mediator = createMediator(item, mapping);
unmapTypeForFilterBinding(mapping.matcher, type, item)

Which I found whilst trying to modify the code for another feature.

So the ViewComponent get's mapped for the mediator. But it's actaully exposed to the entire injector for a bit longer than expected. So you can inject the view component whilst in the 'preInitialize', 'initialize' and 'postInitialize' phase.

For example you can do the following which should cause errors when injecting.

class ExampleConfig
{
    [Inject]
    public mediatorMap:IMediatorMap;

    [Inject]
    public commandMap:IEventCommandMap;

    [Inject]
    public injector:IInjector;

    public function config():void
    {
        mediatorMap.map(ExampleView).toMediator(ExampleMediator);
        commandMap.map(ExampleEvent.TRIGGER_COMMAND).toCommand(ExampleCommand);
        injector.map(IExampleService).toType(ExampleService);
    }
}
class ExampleMediator
{
    public function initialize():void
    {
        dispatchEvent(new ExampleEvent(ExampleEvent.TRIGGER_COMMAND));
    }
}
class ExampleCommand
{
    [Inject]
    public service:IExampleService;

    [Inject]
    public viewComponent:ExampleView;

    public function execute():void
    {
        trace(viewComponent + " is not null");
    }
}
class ExampleService implements IExampleService
{
    [Inject]
    public viewComponent:ExampleView;

    [PostConstruct]
    public function init():void
    {
        trace(viewComponent + " is not null");
    }
}

Let me know if this is a hidden feature that isn't documented, or a bug and I'll fix :godmode:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant