@@ -8,15 +8,13 @@ import getDedicatedChannel from '../../utils/getDedicatedChannel';
8
8
import Config from '../../config' ;
9
9
import OptimisticInvocation from '../OptimisticInvocation' ;
10
10
11
- const dispatchEvents = function ( optimistic , collectionName , channels , events ) {
11
+ const dispatchEvents = function ( config , collectionName , channels , events ) {
12
+ const { optimistic } = config ;
12
13
if ( optimistic ) {
13
14
OptimisticInvocation . withValue ( true , ( ) => {
14
15
events . forEach ( event => {
15
16
const docId = event [ RedisPipe . DOC ] . _id ;
16
- const dedicatedChannel = getDedicatedChannel (
17
- collectionName ,
18
- docId
19
- ) ;
17
+ const dedicatedChannel = getDedicatedChannel ( collectionName , docId , config ) ;
20
18
RedisSubscriptionManager . process ( dedicatedChannel , event ) ;
21
19
22
20
channels . forEach ( channelName => {
@@ -37,20 +35,22 @@ const dispatchEvents = function(optimistic, collectionName, channels, events) {
37
35
channels . forEach ( channelName => {
38
36
client . publish ( channelName , message ) ;
39
37
} ) ;
38
+
40
39
const docId = event [ RedisPipe . DOC ] . _id ;
41
- const dedicatedChannel = getDedicatedChannel ( collectionName , docId ) ;
40
+ const dedicatedChannel = getDedicatedChannel ( collectionName , docId , config ) ;
42
41
client . publish ( dedicatedChannel , message ) ;
43
42
} ) ;
44
43
} ) ;
45
44
} ;
46
45
47
46
const dispatchUpdate = function (
48
- optimistic ,
47
+ config ,
49
48
collectionName ,
50
49
channels ,
51
50
docs ,
52
51
fields
53
52
) {
53
+ const { optimistic } = config ;
54
54
const uid = optimistic ? RedisSubscriptionManager . uid : null ;
55
55
56
56
const events = docs . map ( doc => ( {
@@ -60,10 +60,11 @@ const dispatchUpdate = function(
60
60
[ RedisPipe . UID ] : uid ,
61
61
} ) ) ;
62
62
63
- dispatchEvents ( optimistic , collectionName , channels , events ) ;
63
+ dispatchEvents ( config , collectionName , channels , events ) ;
64
64
} ;
65
65
66
- const dispatchRemove = function ( optimistic , collectionName , channels , docs ) {
66
+ const dispatchRemove = function ( config , collectionName , channels , docs ) {
67
+ const { optimistic } = config ;
67
68
const uid = optimistic ? RedisSubscriptionManager . uid : null ;
68
69
69
70
const events = docs . map ( doc => ( {
@@ -72,10 +73,11 @@ const dispatchRemove = function(optimistic, collectionName, channels, docs) {
72
73
[ RedisPipe . UID ] : uid ,
73
74
} ) ) ;
74
75
75
- dispatchEvents ( optimistic , collectionName , channels , events ) ;
76
+ dispatchEvents ( config , collectionName , channels , events ) ;
76
77
} ;
77
78
78
- const dispatchInsert = function ( optimistic , collectionName , channels , doc ) {
79
+ const dispatchInsert = function ( config , collectionName , channels , doc ) {
80
+ const { optimistic } = config ;
79
81
const uid = optimistic ? RedisSubscriptionManager . uid : null ;
80
82
81
83
const event = {
@@ -84,7 +86,7 @@ const dispatchInsert = function(optimistic, collectionName, channels, doc) {
84
86
[ RedisPipe . UID ] : uid ,
85
87
} ;
86
88
87
- dispatchEvents ( optimistic , collectionName , channels , [ event ] ) ;
89
+ dispatchEvents ( config , collectionName , channels , [ event ] ) ;
88
90
} ;
89
91
90
92
export { dispatchInsert , dispatchUpdate , dispatchRemove } ;
0 commit comments