如何注册精益小部件播放器

How to register a lean widget player

Apostrophes 精益前端很好,我得到了巨大的性能提升,但我在理解如何注册我自己的一些小部件播放器时遇到了一些问题,如解释的 here

例如这个lib/modules/contact-form-widgets/public/js/always.js 这是我根据你的文档制作的联系表。

apos.define('contact-form-widgets', {

  extend: 'apostrophe-widgets',

  construct: function(self, options) {

    self.play = function($widget, data, options) {

      var $form = $widget.find('[data-contact-form]');
      var schema = self.options.submitSchema;
      var piece = _.cloneDeep(self.options.piece);

      return apos.schemas.populate($form, self.schema, self.piece, function(err) {
        if (err) {
          alert('A problem occurred setting up the contact form.');
          return;
        }
        enableSubmit();
      });

      function enableSubmit() {
        $form.on('submit', function() {
          submit();
          return false;
        });
      }

      function submit() {
        return async.series([
          convert,
          submitToServer
        ], function(err) {
          if (err) {
            alert('Email settings missing, message not send!');
          } else {
            // Replace the form with its formerly hidden thank you message
            $form.replaceWith($form.find('[data-thank-you]'));
          }
        });
        function convert(callback) {
          return apos.schemas.convert($form, schema, piece, callback);
        }
        function submitToServer(callback) {
          return self.api('submit', piece, function(data) {
            if (data.status === 'ok') {
              // All is well
              return callback(null);
            }
            // API-level error
            return callback('error');
          }, function(err) {
            // Transport-level error
            return callback(err);
          });
        }
      }
    };
  }
});

所以我在 apostrophe-video 的代码中看到我需要一个文件:lib/modules/contact-form-widgets/public/js/lean.js 像这样:

apos.utils.widgetPlayers['apostrophe-video'] = function(el, data, options) {
  // Utilize the provided `data` (properties of the widget)
  // and `options` (options passed to the singleton or area for
  // this widget) to enhance `el`, a DOM element representing the widget
};

但我不明白如何根据您的文档修改我的 always.js 文件并寻求 一些有助于进一步理解此功能的信息,因此我可以为我的小部件创建精益播放器。

正如您发现的那样,这个特定的小部件播放器并不容易进入精益环境。在多年的 Apostrophe 开发中,我认为我从未见过一个小部件播放器使用如此多的模块方法和数据。我原以为某些原始播放器不会工作,但也许可以(async 来自哪里?)。

正如您在评论中提到的,您可以使用撇号形式。那可能是最好的选择。或者,您需要将播放器函数中的所有引用替换为 selfapos(浏览器中 lean: true 除外)。这主要意味着在服务器上完成大部分数据工作。其中大部分可以移至自定义路由处理程序中。