@Override public void onStop() { loop.dispose(); M mostRecentModel = loop.getMostRecentModel(); actions.goToStateCreated(renderer, mostRecentModel); }
@Override public void onStop() { loop.dispose(); M mostRecentModel = loop.getMostRecentModel(); actions.goToStateCreated(renderer, mostRecentModel); }
@Test(expected = IllegalStateException.class) public void dispatchingEventsAfterDisposalThrowsException() throws Exception { mobiusLoop.dispose(); mobiusLoop.dispatchEvent(new TestEvent("2")); }
@Test public void shouldThrowForEffectHandlerEventsAfterDispose() throws Exception { final FakeEffectHandler effectHandler = new FakeEffectHandler(); setupWithEffects(effectHandler, immediateRunner); effectHandler.emitEvent(new EventWithSafeEffect("good one")); mobiusLoop.dispose(); assertThatThrownBy(() -> effectHandler.emitEvent(new EventWithSafeEffect("bad one"))) .isInstanceOf(IllegalStateException.class); observer.assertStates("init", "init->good one"); }
@Test public void shouldThrowForEventSourceEventsAfterDispose() throws Exception { FakeEventSource<TestEvent> eventSource = new FakeEventSource<>(); mobiusLoop = MobiusLoop.create( mobiusStore, effectHandler, eventSource, immediateRunner, immediateRunner); observer = new RecordingModelObserver<>(); // to clear out the init from the previous setup mobiusLoop.observe(observer); eventSource.emit(new EventWithSafeEffect("one")); mobiusLoop.dispose(); assertThatThrownBy(() -> eventSource.emit(new EventWithSafeEffect("two"))) .isInstanceOf(IllegalStateException.class); observer.assertStates("init", "init->one"); }
@Test public void shouldSupportCreatingMultipleLoops() throws Exception { MobiusLoop.Factory<String, Integer, Boolean> factory = Mobius.loop(UPDATE, HANDLER); // one loop = factory.startFrom("first"); loop.dispatchEvent(97); await().atMost(Duration.ONE_SECOND).until(() -> loop.getMostRecentModel(), is("first97")); loop.dispose(); // then another one loop = factory.startFrom("second"); loop.dispatchEvent(97); await().atMost(Duration.ONE_SECOND).until(() -> loop.getMostRecentModel(), is("second97")); }