hexMachina icon indicating copy to clipboard operation
hexMachina copied to clipboard

injectInto. Issue with optionals

Open CrazyFlasher opened this issue 6 years ago • 2 comments

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

CrazyFlasher avatar Oct 21 '19 09:10 CrazyFlasher

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

st3veV avatar Oct 21 '19 10:10 st3veV

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.

back2dos avatar Oct 21 '19 10:10 back2dos