with optional action before emit data
add some tests