使用加载程序时扩展 Ractive 组件

Extending Ractive component when using a loader

我一直在尝试使用 component spec 中描述的组件加载器。我不确定如何通过组件文件做这样的事情:

var bookmarkableBaseClass = Ractive.extend({
    oninit : function(){
        this.on(commonBookmarkEvents);
    },
    data : {
        badgeDefinitions: globalCommonBadgeDefinitions
    }
});

Ractive.components.singlecard = bookmarkableBaseClass.extend({
    template: "#smallcarditem"
});

Ractive.components.singleline = bookmarkableBaseClass.extend({
    template: "#cardlineitem"
});

换句话说 - 有一个组件可以扩展另一个具有公共属性的基础组件 - 即公共数据和公共代理事件处理程序。目前组件规范只允许我包含其他组件,但不能像上面那样继承。

虽然 has been discussed 目前不支持它。我认为最好的选择是这样的:

<div class='singlecard'>
  <!-- template goes here -->
</div>

<script>
  var bookmarkableBaseClass = require('./bookmarkableBaseClass');

  component.exports = {
    base: bookmarkableBaseClass,

    someSubclassMethod: function () { /*...*/ }
  };
</script>

任何现有的组件加载器都可以很容易地修改以促进这一点——你在使用哪个?