Is there any way to easy destroy config?
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)
As i understand i should use child injector, and call Inject#teardown method to "destroy" it, but how i can unmap mediators and commands?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Ondina D.F. on 06 Mar, 2014 10:36 AM
Hello,
Why would you want to use teardown() ?
Injector's teardown() destroys the injector by cleaning up all instances it manages.
See:
https://github.com/robotlegs/swiftsuspenders/blob/master/src/org/sw...
When a context is destroyed, teardown() is called automatically.
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.
If you don't want to remove the context view from stage, but you want to destroy the context manually, you use context.destroy().
Now, I'm not sure I understand what you mean by dynamic configuration.
A. Do you need to use different configs when you create a new context,
B. or do you want to change the config inside the same context at run time?
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.
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.
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.
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).
In case I missed your point, could you explain what exactly you want to achieve by "dynamic configuration"?
Ondina
2 Posted by ishaban.flash on 06 Mar, 2014 01:58 PM
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.
Support Staff 3 Posted by Ondina D.F. on 07 Mar, 2014 10:29 AM
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.
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.
injector.map(SomeModel).asSingleton().toGroup("someGroup");
mediatorMap.map(SomeView).toMediator(SomeMediator).toGroup("someGroup");
mediatorMap.map(AnotherView).toMediator(AnotherMediator).toGroup("anotherGroup");
commandMap.map(SomeEvent.SOME_TYPE, SomeEvent).toCommand(SomeCommand).toGroup("someGroup");
toGroup is of course a silly name:)
Then when you want to unmap them, calling
unmapFromGroup("someGroup");
would result in each "mapper" iterating through its own mappings-dictionary in order to unmap the classes belonging to "someGroup".
4 Posted by ishaban.flash on 07 Mar, 2014 12:15 PM
Is it possible to implement this like separate extension, or add new features directly in framework?
Support Staff 5 Posted by Ondina D.F. on 07 Mar, 2014 03:43 PM
You could try opening a feature request ticket on github:
https://github.com/robotlegs/robotlegs-framework/issues
Support Staff 6 Posted by creynders on 12 Mar, 2014 03:32 PM
Hey Ishaban,
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: https://github.com/robotlegs/ModularRL
7 Posted by ishaban.flash on 12 Mar, 2014 04:02 PM
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.
Support Staff 8 Posted by creynders on 13 Mar, 2014 05:27 PM
Well yes, but that's what contexts are for. They manage groups of mappings.
With IContext#addChild and IContext#removeChild you can create a hierarchy
of contexts.
9 Posted by ishaban.flash on 14 Mar, 2014 08:51 AM
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.:
and then:
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.
Support Staff 10 Posted by creynders on 14 Mar, 2014 12:38 PM
AFAIK you don’t need to install the bundles again when you create a child context. Just add a config to it.
(Sorry, don’t have the time to test it out)
Something like this:
11 Posted by ishaban.flash on 14 Mar, 2014 12:59 PM
Looks niiiice, thanks you, i will work around it. :)
12 Posted by matej on 14 Mar, 2014 03:52 PM
I think this works also, not sure :)
13 Posted by ishaban.flash on 17 Mar, 2014 01:49 PM
So, i make test and those code doesn't work for me(( But next code valid:
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.
Maybe i miss something or you have another advice?
14 Posted by matej on 17 Mar, 2014 02:16 PM
You can initialise just the extensions you need.
Mediator Map, Signal command map ext .. that you use.
No need to use new context view, just pass the child config and then call context.initialize();
and when you want to finish it, you call context.destroy();
You can add context view also, but check inside MVCS bundle, not all of that you need.
this is what you wanted, I suppose.
15 Posted by ishaban.flash on 17 Mar, 2014 02:33 PM
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.
Support Staff 16 Posted by Ondina D.F. on 18 Mar, 2014 10:32 AM
@ishaban
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.
If you need a mediator map and a command map, these are the required extensions for a child context to work:
In the parent Context, or there where you add a child context:
Hope that helps a little:)
Ondina
Ondina D.F. closed this discussion on 28 Apr, 2014 08:12 AM.