2

私は Aurelia で遊んでいましたが、かなり良さそうです。一部のプロジェクトでは Durandal を使用していますが、これは私のニーズに完全に合っています。

EC6 からの新しいクラス定義を使用するのは素晴らしいことです。しかし今、requireJs で従来の AMD モジュールを使用する必要があるものを準備しています。たとえば、次のようなものです。

define("testModule",
[],
function() {
    "use strict";
    console.log('testModule loaded');

    var testModule = function() {
        var that = this;

        this.variable = 10;

        that.getVariable = function(){
            alert('function executed ' + that.variable);
        };
    }

    return testModule;
});

Aurelia のドキュメントに従って、testModule のようなものを ViewModel として使用できることがわかりました。実際、viewModel は Durandal アプリケーションで使用されていました。

しかし、いくつかの試行の後、これを機能させることができませんでした。

誰かがそれを行うために従った考えやアプローチはありますか? そして最も重要なことは、それは可能ですか?だと思いますが、互換性があることを確認するだけです。

ありがとう。

4

2 に答える 2

1

以下は、Aurelia で動作するAMD モジュールの例です。

define(["require", "exports"], function (require, exports) {
  var Welcome = (function () {
    function Welcome() {
      this.heading = "Welcome to the Aurelia Navigation App (VS/TS)!";
      this.firstName = "John";
      this.lastName = "Doe";
    }
    Object.defineProperty(Welcome.prototype, "fullName", {
      get: function () {
        return this.firstName + " " + this.lastName;
      },
      enumerable: true,
      configurable: true
    });
    Welcome.prototype.welcome = function () {
      alert("Welcome, " + this.fullName + "!");
    };
    return Welcome;
  })();
  exports.Welcome = Welcome;
});

実際にはTypeScriptソースファイルによって生成されました

export class Welcome {
  public heading: string;
  public firstName: string;
  public lastName: string;

  constructor() {
    this.heading = "Welcome to the Aurelia Navigation App (VS/TS)!";
    this.firstName = "John";
    this.lastName = "Doe";
  }

  get fullName() {
    return this.firstName + " " + this.lastName;
  }

  welcome() {
    alert("Welcome, " + this.fullName + "!");
  }
}

GitHub リポジトリのサンプルの指示に従って、サンプルを操作できます。

于 2015-02-08T10:43:47.643 に答える