tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/10174-is-there-any-way-to-easy-destroy-configRobotlegs: Discussion 2014-04-28T08:12:17Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-05T15:26:03Z2014-03-05T15:31:16ZIs there any way to easy destroy config?<div><p>I have requirement to dynamic configure application, so i want
to add \ remove different configs. I can easy add new configs, but
i don't see any way to clear old ones. I wish to make mapping
manually, but all unmapping process i wanna automate if it
possible. So mb anyone can provide similar solution. (e.g. like
mediators has methods "addContextListener" \ "addViewListener",
wich remove whole mapped listeners on destroy)</p>
<p>As i understand i should use child injector, and call
Inject#teardown method to "destroy" it, but how i can unmap
mediators and commands?</p></div>ishaban.flashtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-06T10:36:31Z2014-03-06T10:36:31ZIs there any way to easy destroy config?<div><p>Hello,</p>
<blockquote>
<p>As i understand i should use child injector, and call
Inject#teardown method to "destroy" it, but how i can unmap
mediators and commands</p>
</blockquote>
<p>Why would you want to use teardown() ?</p>
<p>Injector's teardown() destroys the injector by cleaning up all
instances it manages.<br>
See:<br>
<a href=
"https://github.com/robotlegs/swiftsuspenders/blob/master/src/org/swiftsuspenders/Injector.as#L457">
https://github.com/robotlegs/swiftsuspenders/blob/master/src/org/sw...</a></p>
<p>When a context is destroyed, teardown() is called
automatically.</p>
<p>As you know, when a contextView is removed from stage, the
context gets destroyed automatically, thus you don't need to
manually unmap your classes. Everything that was mapped inside of
this context will get unmapped before the injector and the context
are destroyed.</p>
<p>If you don't want to remove the context view from stage, but you
want to destroy the context manually, you use
<strong>context.destroy()</strong>.</p>
<p>Now, I'm not sure I understand what you mean by dynamic
configuration.</p>
<p>A. Do you need to use different configs when you create a new
context,</p>
<p>B. or do you want to change the config inside the same context
at run time?</p>
<p>A. That's pretty easy. There, where you create the context, you
give it different configs depending on some conditions. When the
context is destroyed, the mappings in those configs are gone.</p>
<p>B. You could create a class that contains the desired
unmappings. You could access it inside a command, for example. The
command could also access the new configs containing the new
mappings.<br>
But, beware of what could happen to your mediators, if you remove
the mappings for your views while they are still on the stage. If
you need to unmediate them after unmaping them, you'll have to also
mediate them manually after adding the new configs.</p>
<p>So, the Injector can either remove all mappings of a certain
context when the context is destroyed (A), or only the ones you
specify directly through commandMap.unmap, mediatorMap.unmap or
injector.unmap (B).</p>
<p>In case I missed your point, could you explain what exactly you
want to achieve by "dynamic configuration"?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-06T13:58:52Z2014-03-06T13:58:52ZIs there any way to easy destroy config?<div><p>Hi, there is case "B", but i want to unmap all automatic, just
to call any method, like "destroy", and do not write
commandMap.unmap, mediatorMap.unmap.</p></div>ishaban.flashtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-07T10:29:42Z2014-03-07T10:29:42ZIs there any way to easy destroy config?<div><blockquote>
<p>but i want to unmap all automatic, just to call any method, like
"destroy", and do not write commandMap.unmap,
mediatorMap.unmap.</p>
</blockquote>
<p>In my mind, that would require implementing a special mapping
mechanism, where you could build a "group" of mappings, so that you
could refer to that group when you want to unmap all the classes
inside of it.<br>
Since the mappings are performed by different "mappers"
(commandMap, mediatorMap, Injector itself), each of them should
have an additional method for storing the mappings in a dictionary
of groups.</p>
<p>injector.map(SomeModel).asSingleton().toGroup("someGroup");</p>
<p>
mediatorMap.map(SomeView).toMediator(SomeMediator).toGroup("someGroup");<br>
mediatorMap.map(AnotherView).toMediator(AnotherMediator).toGroup("anotherGroup");</p>
<p>commandMap.map(SomeEvent.SOME_TYPE,
SomeEvent).toCommand(SomeCommand).toGroup("someGroup");</p>
<p>toGroup is of course a silly name:)</p>
<p>Then when you want to unmap them, calling</p>
<p>unmapFromGroup("someGroup");</p>
<p>would result in each "mapper" iterating through its own
mappings-dictionary in order to unmap the classes belonging to
"someGroup".</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-07T12:15:43Z2014-03-07T12:15:43ZIs there any way to easy destroy config?<div><p>Is it possible to implement this like separate extension, or add
new features directly in framework?</p></div>ishaban.flashtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-07T15:43:09Z2014-03-07T15:43:09ZIs there any way to easy destroy config?<div><p>You could try opening a feature request ticket on github:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/issues">https://github.com/robotlegs/robotlegs-framework/issues</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-12T15:32:16Z2014-03-12T15:32:16ZIs there any way to easy destroy config?<div><p>Hey Ishaban,</p>
<p>I saw your issue on GH. It sounds to me like you're trying to
replicate module-like behaviour, but without using modules?
However, I'd definitely recommend using modules with separate
contexts for something like this. Here's a demo for how to create
an application with modules in RL2: <a href=
"https://github.com/robotlegs/ModularRL">https://github.com/robotlegs/ModularRL</a></p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-12T16:02:06Z2014-03-12T16:02:06ZIs there any way to easy destroy config?<div><p>Hm, not exactly, i want to got one context and just extent
functionality for a some time, and after remove it as easy as it
possible. I don't want to create many contexts.</p></div>ishaban.flashtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-13T17:27:51Z2014-03-13T17:27:51ZIs there any way to easy destroy config?<div><p>Well yes, but that's what contexts are for. They manage groups
of mappings.<br>
With IContext#addChild and IContext#removeChild you can create a
hierarchy<br>
of contexts.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-14T08:51:02Z2014-03-14T08:51:24ZIs there any way to easy destroy config?<div><p>As for me, use context is too excess solution, because when i
create new context i should initialize it with all extensions, also
adds several problems with comunitation between contexts. I don't
need to load any logic at runtime, all logic already included in
application i just need change it. But all i need is to add few
mappings, e.g.:</p>
<pre>
<code>public class ConcreteProfile extends BaseProfile {
override protected function mapInjections() : void {
super.mapInjections();
injector.map(BaseModel).toValue(injector.instantiateUnmapped(ConcreteModel)).toGroup(groupName);
injector.map(BaseGameReels).toValue(injector.instantiateUnmapped(ConcreteGameReels)).toGroup(groupName);
injector.map(BaseGameInterface).toValue(injector.instantiateUnmapped(BaseGameInterface)).toGroup(groupName);
injector.map(BaseAnimation).toValue(injector.instantiateUnmapped(ConcreteAnimation)).toGroup(groupName);
injector.map(BaseGameWin).toValue(injector.instantiateUnmapped(ConcreteGameWin)).toGroup(groupName);
injector.map(BaseGameBonus).toValue(injector.instantiateUnmapped(ConcreteGameBonus)).toGroup(groupName);
injector.map(BaseGameEnvironment).toValue(injector.instantiateUnmapped(ConcreteGameEnvironment)).toGroup(groupName);
injector.map(BaseController).toValue(injector.instantiateUnmapped(ConcreteController)).toGroup(groupName);
injector.map(BasePopup, PopupFactory.PAYTABLE).toType(BasePaytableView).toGroup(groupName);
injector.map(BasePopup, PopupFactory.FREE_SPINS_RETRIGGERED).toType(RetriggerFreeSpinsWindow).toGroup(groupName);
injector.map(BasePopup, PopupFactory.FREE_SPINS_END).toType(EndFreeSpinsWindow).toGroup(groupName);
}
}</code>
</pre>
<p>and then:</p>
<pre>
<code>injector.unmapGroup(groupName);
mediatorMap.unmapGroup(groupName);</code>
</pre>
<p>I know that i can initialize child context with parent's
contextView, but afaik all extensions i should initialize every
time, and that scary me, because i care about perfomance.. If i
don't right please correct me.</p></div>ishaban.flashtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-14T12:38:27Z2014-03-14T12:38:27ZIs there any way to easy destroy config?<div><p>AFAIK you don’t need to install the bundles again when you
create a child context. Just add a config to it.<br>
(Sorry, don’t have the time to test it out)</p>
<p>Something like this:</p>
<pre>
<code>var childContext = new Context().configure(GroupConfig);
context.addChild(childContext);</code>
</pre></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-14T12:59:19Z2014-03-14T12:59:19ZIs there any way to easy destroy config?<div><p>Looks niiiice, thanks you, i will work around it. :)</p></div>ishaban.flashtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-14T15:52:09Z2014-03-14T15:52:09ZIs there any way to easy destroy config?<div><p>I think this works also, not sure :)</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-17T13:49:37Z2014-03-17T13:51:23ZIs there any way to easy destroy config?<div><p>So, i make test and those code doesn't work for me(( But next
code valid:</p>
<pre>
<code>public class Test extends Sprite {
private var _context : IContext;
public function Test() {
_context = new Context()
.install(MVCSBundle)
.configure(TestParentConfig)
.configure(new ContextView(this));
var childView : Sprite = new Sprite();
var childContext : IContext = new Context()
.install(MVCSBundle)
.configure(TestChildConfig)
.configure(new ContextView(childView));
_context.addChild(childContext);
addChild(childView);
}
}</code>
</pre>
<p>That means that i should initialize all extensions for child
context, what i doesn't need. Also, as i see, every context creates
own injector, but mediatorMap \ commandMap, creates in
extensions.<br>
Maybe i miss something or you have another advice?</p></div>ishaban.flashtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-17T14:16:24Z2014-03-17T14:16:24ZIs there any way to easy destroy config?<div><p>You can initialise just the extensions you need.<br>
Mediator Map, Signal command map ext .. that you use.</p>
<p>No need to use new context view, just pass the child config and
then call context.initialize();</p>
<p>and when you want to finish it, you call context.destroy();<br>
You can add context view also, but check inside MVCS bundle, not
all of that you need.</p>
<p>this is what you wanted, I suppose.</p></div>matejtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-17T14:33:46Z2014-03-17T14:33:46ZIs there any way to easy destroy config?<div><p>Can you provide small example? I install context with custom
MVCSBundle, in child context i want install only command \ mediator
maps, but all my tries has no luck(( Context doesn't
initialize.</p></div>ishaban.flashtag:robotlegs.tenderapp.com,2009-10-18:Comment/319370732014-03-18T10:32:27Z2014-03-18T10:32:27ZIs there any way to easy destroy config?<div><p>@ishaban</p>
<p>I know that the following example is not exactly what you want,
but at least it shows how you can use a custom bundle with just a
few extensions. Since the extensions needed for listening for the
added to stage event for views are missing, you need to mediate the
view manually and also to initialize the childContext manually (see
below), as Matej has already mentioned.</p>
<p>If you need a mediator map and a command map, these are the
required extensions for a child context to work:</p>
<pre>
<code>public class ChildMVCSBundle implements IBundle
{
public function extend(context:IContext):void
{
//context.logLevel = LogLevel.DEBUG;
context.install(
ContextViewExtension,
EventDispatcherExtension,
EventCommandMapExtension,
LocalEventMapExtension,
MediatorMapExtension
);
context.configure(ContextViewListenerConfig);
}
}</code>
</pre>
<p>In the parent Context, or there where you add a child
context:</p>
<pre>
<code>protected function onAddChildContext(event:Event=null):void
{
childContextView = new ChildOneView();
childContext = new Context();
childContext.afterInitializing(childAfterInitializing);
childContext.install(ChildMVCSBundle);
childContext.configure(ChildOneConfig);
childContext.configure(new ContextView(childContextView));
context.addChild(childContext);
//INITIALIZE YOUR CHILD CONTEXT
childContext.initialize();//!!!!!!!!!
(contextView.view as Object).addElement(childContextView);
}
private function childAfterInitializing():void
{
var childMediatorMap:IMediatorMap = childContext.injector.getInstance(IMediatorMap);
childMediatorMap.mediate(childContextView);
}</code>
</pre>
<p>Hope that helps a little:)</p>
<p>Ondina</p></div>Ondina D.F.