-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.coffee
More file actions
32 lines (23 loc) · 845 Bytes
/
server.coffee
File metadata and controls
32 lines (23 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extendPublish (name, func, options) ->
newFunc = (args...) ->
publish = @
scopeFieldName = "_sub_#{publish._subscriptionId}"
enabled = false
publish.enableScope = ->
enabled = true
originalAdded = publish.added
publish.added = (collectionName, id, fields) ->
# Add our scoping field.
if enabled
fields = _.clone fields
fields[scopeFieldName] = 1
originalAdded.call @, collectionName, id, fields
originalChanged = publish.changed
publish.changed = (collectionName, id, fields) ->
# We do not allow changes to our scoping field.
if enabled and scopeFieldName of fields
fields = _.clone fields
delete fields[scopeFieldName]
originalChanged.call @, collectionName, id, fields
func.apply publish, args
[name, newFunc, options]