Take snapshot before publishing events

I hit a scenario whereby if an event was listened for that also updated the entity, the snapshot would become incorrect.

This seemed to be the lowest impact way of implementing the desired behaviour as the public API wasn't changed.

#### Bug description

Examples assume a snapshot threshold of 1.

The previous behaviour:

    +- Publish FooSet event sets foo=1
    |
    +-+- foo_set listener which results in something that sets foo=2
      |
      +- Save snapshot with foo=2
      |
    +-+- exit listener
    |
    +- Save snapshot with foo=1
    |
    +- Snapshot is now incorrect

By taking the snapshot before publishing the event:

    +- Publish FooSet event sets foo=1
    |
    +- Save snapshot with foo=1
    |
    +-+- foo_set listener which results in something that sets foo=2
      |
      +- Save snapshot with foo=2
      |
    +-+- exit listener
    |
    +- Snapshot is now correct