DoclerLabs / hexMachina

Releases, issues, documentation, website of hexMachina, framework written in Haxe
http://hexmachina.org
MIT License
44 stars 8 forks source link

injectInto. Issue with optionals #308

Open CrazyFlasher opened 5 years ago

CrazyFlasher commented 5 years ago
class MockCommand_6 extends AbstractCommand
{
    @Inject("bool")
    @Optional
    private var bool:Bool = true;

    @Inject("iint")
    @Optional
    private var iint:Int = 1;

    override public function execute():Void
    {
        if (!bool || iint != 1)
        {
            throw Error.Custom("MockCommand_6: invalid values: " +  bool + " " + iint);
        }
    }
}

If I inject into MockCommand_6 without having mappings for "bool" and "iint", injector makes the to be null (for js). But in my opinion they should keep their default values

st3veV commented 5 years ago

I think erasing the values makes more sense because you want the injector to update everything in the command and since injector doesn't have values it will inject no value. You could of course deal with this by injecting things through setters where you can do the null check (or any check) yourself

back2dos commented 5 years ago

Whoops, wrong button ^^ Anyway, a similar option to what Steve suggests would be to fallback to a default value in a getter, as that will deal with other null cases as well.