ictvmt / mvp4g

Automatically exported from code.google.com/p/mvp4g
0 stars 0 forks source link

First instance of Multiple Presenter not created if "handlers" attribute used #119

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Define two events for the multiple presenter (MP) below,

@Event(handlers = MP.class)
void createOne();

@Event(generate = MP.class)
void createMany();

@Presenter(view = MV.class, multiple = true)
public class MP ...

2. If the createOne event is fired at the beginning, the first MP instance is 
not created. 

3. The createMany event works as usual.

4. Re-define the createOne event below,

@Event(generate = MP.class)
void createOne();

5. Re-run the test, the createOne event works as expected, so the first MP 
instance is created.

What is the expected output? What do you see instead?

Step 2 should create the first MP instance.

What version of the product are you using? On what operating system?

1.4.0

Please provide any additional information below.

Workaround:

As described on Step 4.

Original issue reported on code.google.com by fans.gro...@googlemail.com on 23 Jul 2012 at 1:53

GoogleCodeExporter commented 8 years ago
This is the expected behavior as described 
[http://code.google.com/p/mvp4g/wiki/PresenterViewService#Event_Generation 
here]. The 'handlers' attribute isn't supposed to generate any handler, you 
need to use the 'generate' attribute.

Original comment by plcoir...@gmail.com on 23 Jul 2012 at 11:19

GoogleCodeExporter commented 8 years ago
First, i've misunderstood how the singleton presenter is instantiated on Mvp4g. 

- It's not instantiated when the event is fired but the application starts. 

- The "handler" attribute has nothing to do with instantiation.

- The "multiple=true" attribute effectively disables the automatic 
instantiation on startup. 

- The "generate" attribute is used to create new instance for the multiple 
presenter whenever the event is fired. 

So the issue can be rejected in this regard.

However, there's another aspect concerning this issue.

- Supposing that the createOne event would be fired before the createMany 
event. The question is how to make sure that only one instance is created when 
the createOne event is fired?

- It might be done by calling #addHandler before firing the createOne event 
below,

if(!instantiated){
eventBus.addHandler(MP.class);
instantiated=true;
}

@Event(handler = MP.class)
void createOne();

@Event(generate = MP.class)
void createMany();

@Presenter(multiple = true ...)
public class MP ...

Can we achieve it simply via annotation?

Original comment by fans.gro...@googlemail.com on 24 Jul 2012 at 7:38

GoogleCodeExporter commented 8 years ago
If you want a single instance, then you shouldn't use multiple instance. If you 
concern about instantiating presenters at start, you should use Lazy Presenter 
to build your presenter/view only the first time it has to handle an event.

Original comment by plcoir...@gmail.com on 25 Jul 2012 at 2:43

GoogleCodeExporter commented 8 years ago
Thanks! Let's close this issue and discuss the derived use case on the forum. 
i'll try to either formulate it more convincing or refactor the solution more 
feasible.

Original comment by fans.gro...@googlemail.com on 25 Jul 2012 at 6:59

GoogleCodeExporter commented 8 years ago

Original comment by plcoir...@gmail.com on 6 Sep 2013 at 4:36