Creating Boolean valued singleton

Chris's Avatar

Chris

14 Feb, 2013 10:48 PM

In my context file, I have:-

var serviceRequestPending:Boolean = false;

injector.mapValue(Boolean, serviceRequestPending, "serviceRequestPending");

Then I inject it using:-

[Inject(name="serviceRequestPending")] public var serviceRequestPending:Boolean;

but when I try to set it to true, it's always false.

Am I misreading the way this is supposed to work? (in RL1)

  1. Support Staff 1 Posted by Ondina D.F. on 15 Feb, 2013 12:32 PM

    Ondina D.F.'s Avatar

    Hi Chris,

    mapValue(whenAskedFor:Class, useValue:Object, named:String=""):*

    When you do this:
    var serviceRequestPending:Boolean = false;
    injector.mapValue(Boolean, serviceRequestPending, "serviceRequestPending");

    the provided useValue will be used for every injection; the injector won’t perform injection into this value.
    In other words, when you ask for an instance of type Boolean, named ‘serviceRequestPending’, you’ll always get the instance with the value you provided (false).
    WIMIWIG :What I map is what I get ;)

    If class A sets serviceRequestPending to true, the value of serviceRequestPending in class B will still be false, unless you remap serviceRequestPending before injecting it into class B, but that wouldn’t make much sense.

    Till wanted to introduce „live“ injections for Swiftsuspenders 2, but, as far as I know, that didn’t happen.

    I understand that you’re expecting serviceRequestPending to behave like a static variable of a Singleton class. If you change its value in one class, you expect to get this value in other classes as well, right?
    Class A:
    GlobalStaticClass.serviceRequestPending=true;
    Class B:
    trace(GlobalStaticClass.serviceRequestPending)// should be true
    GlobalStaticClass.serviceRequestPending=false;
    Class C:
    trace(GlobalStaticClass.serviceRequestPending)// should be false

    I think that a Model, mapped as a singleton (the good kind, with a small "s"), having a property serviceRequestPending would serve you better. Just saying:)

    Ondina

  2. Chris closed this discussion on 18 Feb, 2013 11:34 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac