Could you please advise if it is possible to emit event from $deleted handler?
I am trying to continuously run following projection and first emit runs like a charm, but the second one do not work at all, in the same time both state fields deleted and emitedAbandonedEvent are set to true.
fromCategory(‘association’)
.foreachStream()
.when({
‘$init’: function() {
return { }
},
‘AssociationOfDeviceToUserCreated’: function(state, ev) {
state.userId = ev.body.userId;
state.deviceId = ev.body.deviceId;
state.deleted = false;
emit(‘user-’ + ev.body.userId, ‘DeviceAssociated’, {‘deviceId’ : ev.body.deviceId, ‘timestamp’: ev.body.timestamp}, {‘userId’: ev.body.userId})
},
‘$deleted’: function(state, ev) {
state.deleted = true;
emit('user-' + state.userId, 'DeviceAbandoned', {'deviceId' : state.deviceId }, {'userId': state.userId});
state.emitedAbandonedEvent = true;
}
})
``
Mikhail