On Tuesday, May 15, 2012 1:58:48 PM UTC+2, Shaun Tarves wrote:
Sorry for not being clearer - self-contained wasn't the correct description. Modular is more what I meant; widgets in the sense that they could be used in multiple views, but still have the ability to interact with the rest of the app (fire events mostly). If they're widgets as used in uiBinder templates, how to I control the construction of them to include an event bus. Should I make the event bus static, declare a UiConstructor, or use injection?
Don't make the bus static!
You can use @UiFactory, @UiConstructor if you wish, or @UiField(provided=true).
In some very specific cases (because we had a lot of those widgets –a SuggestBox that needed a RequestFactory in our case– and a lot of views, and didn't want to add too much boilerplate in each view), we added a static field into the widget and used GIN's requestStaticInjection (ideally, you'd rather inject a Provider<> and call its get() from your constructor, to mimic dependency-injection).
This is only a workaround for the fact UiBinder isn't really GIN-friendly; it should IMO be explicitly documented in your code as being a workaround, and not a rule to follow ! (rather an exception to the rule).
I'm mostly looking for a design pattern that others have found helpful with actual implementation (where/how to declare/construct) of MVP widgets.