我正在尝试使用咖啡脚本以严格模式构建流星包。主要问题是咖啡脚本流星包中描述的共享的使用。似乎我误解了链接中的解释,因为我收到以下错误:
ReferenceError: __coffeescriptShare is not defined
打包后在 javascript 中运行良好。我只是将NotificationCommon的定义放在'use strict'之前。
目标是
- NotificationCommon , 范围包
- NotificationClient和NotificationServer:范围文件
- 通知:出口
这是我的咖啡脚本版本:
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');
});
任何帮助都感激不尽。