Skip to content
This repository has been archived by the owner on Nov 11, 2022. It is now read-only.

Possible to add support of EventBus#addHandlerToSource(...)? #5

Open
July-G opened this issue Jun 1, 2013 · 4 comments
Open

Possible to add support of EventBus#addHandlerToSource(...)? #5

July-G opened this issue Jun 1, 2013 · 4 comments

Comments

@July-G
Copy link

July-G commented Jun 1, 2013

Hi:
Possible to add a interface method in EventBinder like below:

public HandlerRegistration bindEventHandlers(T target, Object source, EventBus eventBus);

So we can take use of EventBus#addHandlerToSource(...)?

@ekuefler
Copy link
Contributor

ekuefler commented Jun 3, 2013

@gokdogan, what do you think of this? I'm not sure how people usually use addHandlerToSource - if it's normal for all handlers in the class to be registered on the same source, this seems like it would be a fairly straightforward extension of the API. We could also do something @UiHandler-like where @eventhandler is parameterized with field names as strings or similar, though I don't think that would fit quite as nicely in this case.

@gkdn
Copy link
Member

gkdn commented Jun 4, 2013

Use of addHandlerToSource is very uncommon in Google so it is hard to generalize but based on my sample set and expectations it is unlikely that source-per-class will be useful to many people.
Parameterizing EventHandler will give the option to use String, Enum or Class as source but that also covers very limited scenarios.
Let's wait and accumulate other use cases here.

@ekuefler
Copy link
Contributor

ekuefler commented Jun 9, 2013

Sounds good to me. July, would you mind describing exactly how you use addHandlerToSource in your application?

@July-G
Copy link
Author

July-G commented Jun 9, 2013

I hope to use like below, so I can write one event instead of many(BookSaveEvent, UserSaveEvent...):

public class ProxySavedEvent<P extends EntityProxy> extends GenericEvent
{
    private P proxy;

    public ProxySavedEvent( P proxy )
    {
        this.proxy = proxy;
    }

    public P getProxy()
    {
        return proxy;
    }
}

public class MyEditProxyActivity<P extends EntityProxy> extends Activity
{
  private void save(P proxy)
  {
        //...
        myReq.save(proxy).fire(new Receiver<P>()
        {
            @Override
            public void onSuccess( P response )
            {
                //...
                factory.getEventBus().fireEventFromSource( new ProxySavedEvent<P>( response ),
                    proxy.stableId().getProxyClass() );
        }
    }
  }
}

public class MyBookActivity extends Activity
{
    public void start( AcceptsOneWidget display, EventBus eventBus )
    {
      entityProxyChangeHandler = eventBinder.bindEventHandlers( this, BookEntity.class, eventBus );
      //...
    }
    @EventHandler
    void onProxyChanged( ProxySavedEvent<BookEntity> event )
    {
        update( event.getProxy() );
    }
}

public class MyUserActivity extends Activity
{
    public void start( AcceptsOneWidget display, EventBus eventBus )
    {
      entityProxyChangeHandler = eventBinder.bindEventHandlers( this, UserEntity.class, eventBus );
      //...
    }
    @EventHandler
    void onProxyChanged( ProxySavedEvent<UserEntity> event )
    {
        update( event.getProxy() );
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants