Skip to content

Commit

Permalink
Fire EntityChange events immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Jan 11, 2020
1 parent 179142f commit d211400
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,14 @@ object EntityHook {
}

fun Transaction.registerChange(entityClass: EntityClass<*, Entity<*>>, entityId: EntityID<*>, changeType: EntityChangeType) {
EntityChange(entityClass, entityId, changeType, id).let {
if (entityEvents.lastOrNull() != it) {
entityEvents.add(it)
}
}
}
val event = EntityChange(entityClass, entityId, changeType, id)

fun Transaction.alertSubscribers() {
entityEvents.forEach { e ->
if (entityEvents.lastOrNull() != event) {
entityEvents.add(event)
entitySubscribers.forEach {
it(e)
it(event)
}
}
entityEvents.clear()
}

fun Transaction.registeredChanges() = entityEvents.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class EntityLifecycleInterceptor : GlobalStatementInterceptor {

override fun beforeCommit(transaction: Transaction) {
val created = transaction.flushCache()
transaction.alertSubscribers()
val createdByHooks = transaction.flushCache()
EntityCache.invalidateGlobalCaches(created + createdByHooks)
}
Expand Down

0 comments on commit d211400

Please sign in to comment.