Projection - emit event from $deleted handler

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

I didn´t know about a $deleted wildcard. Is there a documentation about it?

Hi Darien,
Projections have little to no documentation yet, although it doesn’t stop some from reading the source code.

Mikhail,

You unfortunately cannot emit events via the $deleted handler, that said you can write an appropriate event instead of deleting the stream?

Hi Pieter and thanks! My idea was to achieve consistency that device may be associated only with one user by creating association stream and deleting it when user decides to drop association. Unfortunately, this is really a bad approach and my decision, is to use CommonDomain and aggregates to implement consistency checks within aggregate logic. ES will be used to store events and compute projections, but all business logic on data manipulation will be in CommonDomain aggregates.

Projections are being released in 4.0 (with documentation).

That would be awesome! Thanks for all the hard work!

Any ETA on 4.0?