开发者

Is there a penalty to using GWT history instead of EventBus

开发者 https://www.devze.com 2023-02-22 07:53 出处:网络
I\'m planning my GWT app.As Ray Ryan said at Google IO 09: \"Get your history right, and get it right early\".

I'm planning my GWT app. As Ray Ryan said at Google IO 09:

"Get your history right, and get it right early".

I've considered the role of history in my application, and on first impressions it seems I can handle all of my control flows via History tokens. The control flows all just involve the specification of a single index value (eg 123): so I can represent this as a "i_123" history token: multiple components in the UI would fire in new history tokens - to trigger the UI to update. My record display Presenter would just listen out for history events that begin with "i_", then extract the index from matching tokens, and update.

Is there a penalty to this strategy? If I needed to pass complex messages around the app I appreciate I would wrap these into events, but it just doesn't seem neces开发者_运维问答sary.

Any other opinions on this strategy?


It's a good idea to use the history for everything you want the user to be able to navigate back and forth with the browser's back- and forward-buttons. Moving between individual records seems like a good example - you might like to let them explore three records, and then move backwards through them.

This won't be sufficient for some events, though. Say some data changes, and you want all of your various displays to update themselves - even though you are still looking at i_123. At that point, you might want to send something like a RefreshEvent (that you'd create) through your eventbus.

Luckily, you can use the exact same eventbus that you're listening to for history events to listen for events you decide to add later! So, when you're starting out, I do recommend* listening for history events as a means of intra-program communication, and then adding more events as you need them. Just make sure you don't start using history for things that aren't related to navigation.

*PS: GWT's Activity and Place classes are built to provide a layer of flexibility between your history and your code, and have some great benefits like centralized URL mapping/parsing (so you don't have to go around changing every single presenter when you want to change the url scheme) and automatic "do you really want to leave?" confirmations. If you have time before you really get started, I recommend using Activity and Place from the beginning instead of listening to history events directly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号