2

我正在尝试使用咖啡脚本以严格模式构建流星包。主要问题是咖啡脚本流星包中描述的共享的使用。似乎我误解了链接中的解释,因为我收到以下错误:

 ReferenceError: __coffeescriptShare is not defined

打包后在 javascript 中运行良好。我只是将NotificationCommon的定义放在'use strict'之前。

目标是

  • NotificationCommon , 范围包
  • NotificationClientNotificationServer:范围文件
  • 通知:出口

这是我的咖啡脚本版本:

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

解决方案是在package.js中添加包 fds:coffeescript-share

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

请参阅链接以获取说明。

如果对咖啡脚本包的解释能够描述问题(与use strict相关)并告知上述包的存在,将会很有帮助。

编辑

谢谢@jorjordandan的评论。我可以得出结论,目前没有完整的组合解决方案

  • 流星包
  • 咖啡脚本
  • 严格模式

编辑 2

我已经对问题进行了更深入的分析,并且我认为在coffeescript包中找不到解决方案。

该问题应该由meteor团队在包构建代码中解决。我可以想象一个解决方案如下。Meteor 包 API 中添加了一条新指令:除了export之外,还有一条名为scopePackage的指令。使用scopePackage声明的变量将列在/* Package-scope variables */(在连接的 js 中)下。但它们不会被导出(/* Exports */连接js中的代码)。

于 2015-08-01T13:04:34.953 回答