Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events 使用Dojo在特定小部件方法中发布主题_Events_Templates_Dojo - Fatal编程技术网

Events 使用Dojo在特定小部件方法中发布主题

Events 使用Dojo在特定小部件方法中发布主题,events,templates,dojo,Events,Templates,Dojo,我希望能够在模板对象发生问题时发布特定主题。 现在,我只是简单地创建了一个额外的小部件: [...] return declare('hotplate.hotDojoAuth.LoginForm', [_WidgetBase, _TemplatedHooksMixin, _TemplatedMixin, _WidgetsInTemplateMixin ], { _TemplatedHooksMixin仅发射: define([ 'dojo/_base/declare', 'dojo/_

我希望能够在模板对象发生问题时发布特定主题。 现在,我只是简单地创建了一个额外的小部件:

[...]
return declare('hotplate.hotDojoAuth.LoginForm', [_WidgetBase, _TemplatedHooksMixin, _TemplatedMixin, _WidgetsInTemplateMixin ], {
_TemplatedHooksMixin仅发射:

define([
  'dojo/_base/declare',
  'dojo/_base/lang',
  'dojo/topic',

  ], function(
    declare
  , lang
  , topic

  ){
    return  declare(null, {

      templatedHooks: true,

      constructor: function(){
        this.templatedHooks = true;
        topic.publish('hotplate/hotHooks/constructor', this);
      },

      buildRendering: function(){
        topic.publish('hotplate/hotHooks/buildRendering/before', this);
        this.inherited(arguments);
        topic.publish('hotplate/hotHooks/buildRendering/after', this);
      },

      destroyRendering: function(){
        topic.publish('hotplate/hotHooks/destroyRendering/before', this);
        this.inherited(arguments);
        topic.publish('hotplate/hotHooks/destroyRendering/after', this);
      },

      postCreate: function(){
        topic.publish('hotplate/hotHooks/postCreate/before', this);
        this.inherited(arguments);
        topic.publish('hotplate/hotHooks/postCreate/after', this);
      },

      startup: function(){
        topic.publish('hotplate/hotHooks/startup/before', this);
        this.inherited(arguments);
        topic.publish('hotplate/hotHooks/startup/after', this);
      },

      destroy: function(){
        topic.publish('hotplate/hotHooks/destroy/before', this);
        this.inherited(arguments);
        topic.publish('hotplate/hotHooks/destroy/after', this);
      }

    });
  }
);
问题:

1) 代码是重复的,主要是因为它使用了“this”、“arguments”、“inherited”,它们都尖叫着“不要回避我!”(尤其是this.inherited)。关于使用简单参数生成一个函数有什么提示吗

2) 这是一种半理智的做法吗?其思想是允许其他与我的库无关的小部件更改模板小部件的内容

3) 如果这是一条好的路径(评论?),你认为我称之为路径的方式是否合理

谢谢大家!


Merc.

我认为您应该考虑使用
dojo/aspect


我要试一试。然而,我特别担心的是,this.inherited(参数)在我的函数中,以及
aspect.before(this,methodName,function(deferred){
中的“this”将是methodName(函数),而不是对象本身。
constructor: function(){
    this.templatedHooks = true;

    var methodsToDecorate = ["buildRendering", "destroyRendering", ...];
    array.forEach(methodsToDecorate, function(methodName) {
        aspect.before(this, methodName, function(deferred){
            topic.publish('hotplate/hotHooks/' + methodName + '/before', this);
        });
        aspect.after(this, methodName, function(deferred){
            topic.publish('hotplate/hotHooks/' + methodName + '/after', this);
        });
    });

    topic.publish('hotplate/hotHooks/constructor', this);
},