tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/491-injector-seems-to-always-create-new-view-instanceRobotlegs: Discussion 2018-10-18T16:35:37Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/139603422012-02-24T16:20:39Z2012-02-24T16:20:39ZInjector seems to always create new view instance<div><p>OK, I've found why it's creating a new view instance each
time.</p>
<p>I changed the class mapping to<br>
injector.mapSingleton(KeysView);</p>
<p>This started to create only the single instance of the view. But
it seems as though I'm still getting different instances of the
mediator created, and therefore too many event handlers are being
fired.</p></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/139603422012-02-24T16:22:48Z2012-02-24T16:22:48ZInjector seems to always create new view instance<div><p>How are you adding your listeners in onRegister of the
mediator?</p>
<p>Are you using the eventMap? If not, the events won't get cleaned
up when the mediator is killed off (which should happen
automatically when the view leaves the stage).</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/139603422012-02-24T16:25:08Z2012-02-24T16:25:08ZInjector seems to always create new view instance<div><p>addViewListener(BeatMakerEvent.DISPLAY_MAIN_VIEW, dispatch,
BeatMakerEvent);</p>
<pre>
<code> addViewListener(ViewChangeEvent.REMOVE_VIEW, dispatch);
addViewListener(SoundKitEvent.SOUND_KIT_SELECTED, dispatch, SoundKitEvent);
addViewListener(BeatMakerEvent.PLAY_SAMPLE, onPlaySample, BeatMakerEvent);
addViewListener(ScreenEvent.TOGGLE_BLACKOUT_SCREEN, dispatch, ScreenEvent);
addViewListener(ScreenEvent.TOGGLE_FULL_SCREEN, dispatch, ScreenEvent);
addViewListener(BeatMakerEvent.CHANGE_TRACK_HIGH_AMOUNT, dispatch, BeatMakerEvent);
addViewListener(BeatMakerEvent.CHANGE_TRACK_MID_AMOUNT, dispatch, BeatMakerEvent);
addViewListener(BeatMakerEvent.CHANGE_TRACK_LOW_AMOUNT, dispatch, BeatMakerEvent);
addViewListener(BeatMakerEvent.CHANGE_TRACK_PAN_AMOUNT, dispatch, BeatMakerEvent);
addViewListener(BeatMakerEvent.SET_TRACK_FREQUENCY, dispatch, BeatMakerEvent);
addViewListener(BeatMakerEvent.SET_TRACK_LFO_AMOUNT, dispatch, BeatMakerEvent);
addViewListener(BeatMakerEvent.SET_TRACK_LFO_RATE, dispatch, BeatMakerEvent);
addViewListener(BeatMakerEvent.SET_TRACK_RESONANCE, dispatch, BeatMakerEvent);
addViewListener(BeatMakerEvent.IMPORT_KIT, onImportKit, BeatMakerEvent);
addViewListener(VolumeEvent.SET_VOLUME, dispatch, VolumeEvent);
addViewListener("typeSet", dispatch, Event);
relaxedEventMap.mapRelaxedListener("typeSet", onTypeSet, Event);
relaxedEventMap.mapRelaxedListener(BeatMakerEvent.MASTER_VOLUME_SET, onMasterVolumeSet, BeatMakerEvent);
addContextListener(BeatMakerEvent.MASTER_VOLUME_SET, onMasterVolumeSet, BeatMakerEvent);
addContextListener(SoundKitEvent.SOUND_KIT_SELECTED, onSoundKitSelected, SoundKitEvent);
addContextListener(BeatMakerEvent.SOUND_KIT_IMPORT_SUCCESSFUL, onSoundKitImported, BeatMakerEvent);</code>
</pre></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/139603422012-02-24T16:29:09Z2012-02-24T16:29:09ZInjector seems to always create new view instance<div><p>And are you unmapping those relaxedEventMap listeners in
onRemove() ?</p>
<p>See the section on clean up in the ReadMe here:</p>
<p><a href=
"https://github.com/Stray/robotlegs-utilities-RelaxedEventMap">https://github.com/Stray/robotlegs-utilities-RelaxedEventMap</a></p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/139603422012-02-24T16:40:10Z2012-02-24T16:40:10ZInjector seems to always create new view instance<div><p>OK, so now I'm still getting a new instance of the mediator. But
it appears that the old instances are being cleaned up properly. So
this is how it is suppsoed to be correct? But I do still have one
issue.</p>
<p>My handler for my "onTypeSet" event gets called once the first
time, but then gets called twice every time after that (though it
doesn't continue to grow in call counts like it used to).</p>
<p>I am adding it to the relaxed event map and the mediator's event
map, could that be why? But if so why does it only call it once the
first time?</p>
<p>Kyle</p></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/139603422012-02-24T16:40:59Z2012-02-24T16:40:59ZInjector seems to always create new view instance<div><p>Yep, that was why. If i remove the listener from the mediator's
event map and only use the relaxed one it always calls it once.</p>
<p>Kyle</p></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/139603422012-02-24T16:42:58Z2012-02-24T16:42:58ZInjector seems to always create new view instance<div><p>I'm guessing that the first time round, the event has actually
happened just before the mediator runs onRegister - so only the
relaxed one is getting run. After that, both get run. You don't
need to add that listener twice - the relaxed one will cover all
the future happenings as well as the past one.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/139603422012-02-24T16:48:38Z2012-02-24T16:48:38ZInjector seems to always create new view instance<div><p>Great, thanks so much! Love this forum, you are always on top of
everything!</p></div>kamcknig