2

コーヒースクリプトを使用して厳密モードで流星パッケージを構築しようとしています。主な問題は、 coffeescript meteor パッケージで説明されている共有の使用です。次のエラーが表示されるため、リンクの説明を誤解したようです。

 ReferenceError: __coffeescriptShare is not defined

パッケージはjavascriptでうまく機能しました。'use strict' の前にNotificationCommonの定義を置きました。

目標は

  • NotificationCommon、スコープ パッケージ
  • NotificationClientおよびNotificationServer : スコープ ファイル
  • 届出: 輸出

これは私のバージョンですcoffeescript

notification_common.coffee :

'use strict'

class share.NotificationCommon
  constructor: ->
    @collection = new (Meteor.Collection)('notification')

    @SUCCESS = 'success'
    @ERROR = 'error'
    @INFO = 'info'
    @WARNING = 'warning'

notification_client.coffee :

'use strict'

class NotificationClient extends share.NotificationCommon
  constructor = ->
    self = @

    Meteor.subscribe 'user_notif'
    toastr.options = positionClass: 'toast-bottom-full-width'

    @collection.find({}).observe 'added': (notif) ->
      self.notify notif
      return

  notify = (notif) ->
    toastr[notif.type] notif.message, notif.title, notif.options
    @collection.update { _id: notif._id }, $set: notified: true
    return

Notification = new NotificationClient

notification_server.coffee :

'use strict'

class NotificationServer extends share.NotificationCommon
  constructor = ->
    self = @

    @collection.allow update: (userId, doc, fields, modifier) ->
          return doc.userId is userId

    Meteor.publish 'user_notif', ->
      if @userId
        return self.collection.find( userId: @userId, notified: false)
      return

  notify = (user_id, notif) ->
    self = @
    checkType = Match.Where((x) ->
      check x, String
      check x, Match.OneOf('success', 'error', 'info', 'warning')
      true
      )
    check notif,
      type: checkType
      message: String
      title: Match.Optional(String)
      options: Match.Optional(Match.Any)
      context: Match.Optional(Match.Any)
    if user_id isnt null
      if not Meteor.users.findOne(_id: user_id)
        throw new (Meteor.Error)('User id not found.')
      notif.userId = user_id
    notif.notified = false
    self.collection.insert notif
    return

Notification = new NotificationServer

およびpackage.js :

Package.describe({
  name: 'my:notification',
  version: '0.0.1',
  summary: 'User and system wide notification',
  git: '',
  documentation: 'README.md'
});

Package.onUse(function(api) {
  api.versionsFrom('1.1.0.2');

  api.use(['coffeescript','jquery']);
  api.use('chrismbeckett:toastr');

  api.export('Notification');

  api.addFiles('notification_common.coffee');
  api.addFiles('notification_server.coffee','server');
  api.addFiles('notification_client.coffee','client');

});

Package.onTest(function(api) {
  api.use(['tinytest','coffeescript']);
  api.use('my:notification');
  api.addFiles('notification-tests.js');
});

どんな助けでも大歓迎です。

4

1 に答える 1

1

解決策は、パッケージ fds:coffeescript-sharepackage.jsに追加することです:

  api.use('fds:coffeescript-share');

説明については、リンクを参照してください。

パッケージcoffeescriptの説明で問題 ( strict の使用に関連) を説明し、上記のパッケージの存在について通知していただけると助かります。

編集

@jorjordandan さん、コメントありがとうございます。現時点では、組み合わせるための完全な解決策はないと結論付けることができます。

  • 流星パッケージ
  • コーヒースクリプト
  • 厳格モード

編集2

私は問題をより深く分析しましたが、coffeescriptパッケージ内に解決策が見つからないと思います。

この問題は、パッケージのビルド コードで meteor チームが解決する必要があります。次のように解決策を想像できました。新しい命令が Meteor パッケージ API に追加さました。scopePackageで宣言された変数は/* Package-scope variables */(連結された js 内) の下にリストされます。ただし、それらはエクスポートされません (/* Exports */連結された js の下のコード)。

于 2015-08-01T13:04:34.953 に答える