how can i communicate between views

68 views
Skip to first unread message

else...@gmail.com

unread,
Jun 10, 2018, 2:17:47 PM6/10/18
to StrangeIoC
hello ,

this might be  a dumb question to ask but anyway i want to access a view from another view , i was wondering if someone can help me get that right  ,
i'm getting 

InjectionException: Attempt to Instantiate a null binding
target property: initiationView
target: Button(Clone) (TicTacToe.ButtonClickView)
type: TicTacToe.InitiationView
name: 

i want to access InitiationView  in ButtonClickView 



  public class ButtonClickView : View
    {

         [Inject]
         public InitiationView initiationView { get; set; } // the view i want to inject 

        [Inject]
        public IEventDispatcher dispatcher { get; set; }

        Button myButton;
    
         protected override void OnEnable()
        {
            myButton = GetComponent<Button>();
            myButton.onClick.AddListener(Clicked);
        }
        protected override void OnDisable()
        {
            myButton.onClick.RemoveListener(Clicked);

        }

        void Clicked()
        {
            dispatcher.Dispatch("Clicked");
        }

        public void Button_Clicked()
        {
            UnityEngine.Debug.Log("Clicked");
            initiationView.gameObject.GetComponent<Image>().sprite = initiationView.O;
        }
    }
public class GameContext : MVCSContext
{
public GameContext(MonoBehaviour view) : base(view)
{
}

public GameContext(MonoBehaviour view, ContextStartupFlags flags) : base(view, flags)
{
}

protected override void mapBindings()
{

            injectionBinder.Bind<ITicTacToeData>().To<TicTacToeData>().ToSingleton();
 
            mediationBinder.Bind<InitiationView>().To<InitiationMediator>();
            mediationBinder.Bind<ButtonClickView>().To<ButtonMediator>();
        }

        protected override void addCoreComponents()
        {
            base.addCoreComponents();
            injectionBinder.Unbind<ICommandBinder>();
            injectionBinder.Bind<ICommandBinder>().To<EventCommandBinder>().ToSingleton();
        }
    }





wcorwin

unread,
Jun 10, 2018, 6:26:48 PM6/10/18
to StrangeIoC
I think you may be overthinking this a bit. Provide a reference from one to the other. Not everything needs to be strange. The traditional method of allowing views to speak to one another is using injected signals from their mediators. Typically I do 90% of my communication between views using regular code and the 10% are special cases or very different parts of the app (creating a popup or tooltip, for example).

else...@gmail.com

unread,
Jun 10, 2018, 8:37:13 PM6/10/18
to StrangeIoC
i tried to provide a reference but it returns null ref exception, i don't know why,

here is how i'm doing it, 
ps i'm new to Strange , trying to learn it about a week ago,

  public class ButtonClickView : View
    {
        public InitiationView initiationView;
        [Inject]
        public IEventDispatcher dispatcher { get; set; }
        public GameObject canvas;

        Button myButton;
    
         protected override void OnEnable()
        {
            myButton = GetComponent<Button>();
            myButton.onClick.AddListener(Clicked);

           var canvas= this.transform.parent.gameObject;

        }
        protected override void OnDisable()
        {
            myButton.onClick.RemoveListener(Clicked);

        }

        void Clicked()
        {
            // Debug.Log("" + this.transform.parent.name); this return correctly the name of the canvas where InitiationView is attached

            initiationView = canvas.GetComponent<InitiationView>();
            dispatcher.Dispatch("Clicked");
        }
       
        public void Button_Clicked()
        {
            UnityEngine.Debug.Log("Clicked");
             initiationView.gameObject.GetComponent<Image>().sprite = initiationView.O;
        }
    }

else forty

unread,
Jun 10, 2018, 9:06:26 PM6/10/18
to StrangeIoC
Never mind i got that right , was doing something stupid :D

--
You received this message because you are subscribed to the Google Groups "StrangeIoC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to strangeioc+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages