Eliminating GWT ActivityMapper boilerplate

前端 未结 6 1116
盖世英雄少女心
盖世英雄少女心 2021-02-05 16:26

I am using the GWT Activities and Places framework to structure my application and it is turning out nicely. One thing that annoys me though is that the ActivityMapper

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 17:21

    Actually I am using custom boilerplate code for this task:

    public class PuksaActivityMapper implements ActivityMapper {
    private HashMap mappings;
    
    @Inject
    private SearchResultActivityContainer searchResultContainer;
    @Inject
    private HelloActivityContainer helloContainer;
    
    @Override
    public Activity getActivity(Place place) {
        ActivityContainer container = getMappings().get(place.getClass().getName());
    
        return container.getActivity(place);
    }
    
    public HashMap getMappings() {
        if (mappings == null) {
            mappings = new HashMap();
    
            mappings.put(ShowResultsPlace.class.getName(), searchResultContainer);
            mappings.put(HelloPlace.class.getName(), helloContainer);
        }
        return mappings;
    }
    

    }

    Where ActivityContainer is a simple factory type (from this point classic ioc methods can be used).

    Of course now it is only changing 'if block' with a map lookup/population, but combined with Gin multibinding (witch currently does not exist) could do it's job.

    Also Gin enhancement - generic GinModule for GWT Activity/Places looks promising.

提交回复
热议问题