如何让你的GWT应用程序可插入? [英] How to make your GWT application plug-able?

查看:100
本文介绍了如何让你的GWT应用程序可插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写(与我的团队)一个GWT应用程序,该应用程序解析并表示一些特定领域的语言 - 例如,用文本,视频和UI控件播放媒体演示文稿。因此,该应用程序有一组组件:用于保存模型的组件,用于控制例程(控制器)的组件,当然,我们还有用于View的类。

现在我们遇到了一个问题 - 从所有方面来看,它都是可插入的:


  • 应该是一个核心插件,它可以制作所有常见的东西。这个coer块必须是一个JavaScript文件(每个置换一个)


  • 应该能够扩展核心类,编写自定义类 - 将其编译为单独的JS文件(每个排列一个)




每个插件都必须注册)本身的核心平台,所以它可以使用。



问题:


  1. 如何分别编译自定义内容

  2. 如何加载插件?

对于第二一个问题,我发现 http://code.google.com/p/gwt-exporter/ ,将GWT类导出到外部世界,以便他们可以从纯JS中调用。



另外我有一个想法来为新插件创建新模块,所以它将被编译为单独的文件第一个问题)。



您有构建这样的体系结构的经验吗,在这种情况下您有一些最佳实践吗?

自从GWT 1.5以来,我已经尝试过这个相同的问题,每次我想出一个更优雅的解决方案时,他们都会更改链接器并将其分解。我提出的独立于链接器设计的唯一方法就是完成你正在讨论的内容,并为永久插件创建一个新模块。然后使用GWT导出器创建一个抽象类,该类必须扩展插件,该插件必须具有一个抽象方法,该方法将插件的根元素传递给核心并填充它。此方法的问题是所有插件模块必须在页面的初始加载时添加到DOM,因为从2.0开始,iFrame链接器依赖页面加载事件,因此动态添加的模块不会完全加载。因此,您将希望将导出的群体方法包装在runAsync中,以便在使用它们之前不会下载模块。



编辑:



下面是我正在谈论的一个粗略示例。请注意,我在几年内没有做过任何GWT,现在可能有更好的方法。

  public final class PluginManager 
{
public static final PluginManager INSTANCE = new PluginManager();

private private PluginManager()
{
}

private static native void loadPlugin(AbstractPlugin plugin)
/ * - {
如果(!$ wnd.Plugins){
$ wnd.Plugins = {};
}
var name = plugin。@ com.example.PluginManager.AbstractPlugin :: getName()();
$ wnd.Plugins [name] = $ entry(plugin。@ com.example.PluginManager.AbstractPlugin :: load(Ljava / lang / String;));
} - * /;

private static native void unloadPlugin(AbstractPlugin plugin)
/ * - {
if($ wnd.Plugins){
var name = plugin。@ com.example .PluginManager.AbstractPlugin ::的getName()();
删除$ wnd.Plugins [name];
}
} - * /;

private static native JsArrayString getPlugins()
/ * - {
if($ wnd.Plugins){
return Object.keys($ wnd.Plugins);
}
return undefined;
} - * /;

public static abstract class AbstractPlugin实现EntryPoint
{
@Override
public final void onModuleLoad()
{
PluginManager.INSTANCE.loadPlugin ( 这个 );
}

protected final void unload()
{
PluginManager.INSTANCE.unloadPlugin(this);
}

protected abstract String getName();

protected void load(String rootPanelId);
}
}


I am writing (with my team) an GWT application, which parses and represent some domain specific language - for example, plays media presentation with text, video and UI controls. So the application has a set of components: ones - for holding model, ones - for control routines (controllers), and of course we have classes for View.

Now we have a problem - make it all plug-able, in the sense of:

  • should be one core plugin, which make all common stuff. This coer block must be an JavaScript file (one for every permutation)

  • should be ability to extend core classes, write custom ones - and compile it to separate JS file (one for every permutation)

Every plugin must registers (export it's classes etc) itself to the core platform, so it could be used.

Problems:

  1. How to compile the custom stuff separately ?
  2. How to load plugins ?

For the second one problem i've found http://code.google.com/p/gwt-exporter/, that exports GWT classes to outer world, so they could be invoked from pure JS.

Also I have an idea to create new module for new plugin, so it will be compiled to separate file (first problem).

Have you an experience of building such architecture, have you some best practices in this case ?

解决方案

I have experimented with this same question since GWT 1.5 and every time I come up with a more elegant solution they change the linker and break it. The only way that I have come up with that would work independent of linker design is to do exactly what you are talking about and create a new module for ever plug-in. Then use GWT exporter to create an abstract class that plugins must extend that would have an abstract method that would take the root element of the plugin passed to it by the core and populate it. The issue with this method is all plug-in modules must be added to the DOM on the initial load of the page because since 2.0 the iFrame linker relies on a page load event so dynamically added modules wont fully load. So because of this you will want to have the exported population method wrapped in runAsync so that you aren't downloading modules till you use them.

Edit:

Here is a rough example of what I am talking about. Please be aware that I haven't done any GWT in a couple years and there may be a better way of doing this by now.

public final class PluginManager
{
    public static final PluginManager INSTANCE = new PluginManager();

    private PluginManager()
    {
    }

    private static native void loadPlugin( AbstractPlugin plugin )
    /*-{
        if (!$wnd.Plugins) {
            $wnd.Plugins = {};
        }
        var name = plugin.@com.example.PluginManager.AbstractPlugin::getName()();
        $wnd.Plugins[name] = $entry(plugin.@com.example.PluginManager.AbstractPlugin::load(Ljava/lang/String;));
    }-*/;

    private static native void unloadPlugin( AbstractPlugin plugin )
    /*-{
        if ($wnd.Plugins) {
            var name = plugin.@com.example.PluginManager.AbstractPlugin::getName()();
            delete $wnd.Plugins[name];
        }
    }-*/;

    private static native JsArrayString getPlugins()
    /*-{
        if ($wnd.Plugins) {
            return Object.keys($wnd.Plugins);
        }
        return undefined;
    }-*/;

    public static abstract class AbstractPlugin implements EntryPoint
    {
        @Override
        public final void onModuleLoad()
        {
            PluginManager.INSTANCE.loadPlugin( this );
        }

        protected final void unload()
        {
            PluginManager.INSTANCE.unloadPlugin( this );
        }

        protected abstract String getName();

        protected abstract void load( String rootPanelId );
    }
}

这篇关于如何让你的GWT应用程序可插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆