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

injectInto. Issue with optionals #308

Open
CrazyFlasher opened this issue Oct 21, 2019 · 2 comments
Open

injectInto. Issue with optionals #308

CrazyFlasher opened this issue Oct 21, 2019 · 2 comments

Comments

@CrazyFlasher
Copy link

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
Copy link
Collaborator

st3veV commented Oct 21, 2019

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
Copy link

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 back2dos reopened this Oct 21, 2019
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

3 participants