Last active
September 23, 2019 22:01
-
-
Save jasonboukheir/b812aa3cbf431e9f52acef1e883b819a to your computer and use it in GitHub Desktop.
mediator destruction bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using strange.extensions.context.impl; | |
using strange.extensions.mediation.impl; | |
using UnityEngine; | |
// TestMediator.cs | |
public class TestMediator : Mediator | |
{ | |
public override void OnRemove() | |
{ | |
base.OnRemove(); | |
Debug.Log($"TestMediator.OnRemove on {gameObject.name} is being called."); | |
} | |
} | |
// TestView.cs | |
public class TestView : View | |
{ | |
public TestContextView contextView; // for ease of use | |
private void Update() | |
{ | |
if (Input.GetKeyDown(KeyCode.D)) | |
{ | |
Debug.Log($"Destroying TestView on {gameObject.name}.", this); | |
Destroy(this); | |
} | |
if (Input.GetKeyDown(KeyCode.B)) | |
{ | |
Debug.Log($"Calling bubbleToContext(this, BubbleType.Remove, false) on '{gameObject.name}'.TestView", this); | |
bubbleToContext(this, BubbleType.Remove, false); | |
} | |
if (Input.GetKeyDown(KeyCode.R)) | |
{ | |
Debug.Log($"Calling contextView.context.RemoveView(this) on '{gameObject.name}'.TestView", this); | |
contextView.context.RemoveView(this); | |
} | |
} | |
} | |
// TestContextView.cs | |
public class TestContextView : ContextView | |
{ | |
void Awake() | |
{ | |
context = new TestContext(this, true); | |
context.Start(); | |
} | |
} | |
// TestContext.cs | |
public class TestContext : MVCSContext | |
{ | |
public TestContext() : base() { } | |
public TestContext(MonoBehaviour view, bool autoStartup) : base(view, autoStartup) { } | |
protected override void mapBindings() | |
{ | |
mediationBinder.Bind<TestView>() | |
.To<TestMediator>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment