diff --git a/nicegui/outbox.py b/nicegui/outbox.py index 77c0a0356..d87380c29 100644 --- a/nicegui/outbox.py +++ b/nicegui/outbox.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import itertools from collections import deque from typing import TYPE_CHECKING, Any, Deque, Dict, Optional, Tuple @@ -76,8 +77,8 @@ async def loop(self) -> None: coros.append(self._emit('update', data, self.client.id)) self.updates.clear() - for target_id, message_type, data in self.messages: - coros.append(self._emit(message_type, data, target_id)) + for target_id, messages in itertools.groupby(self.messages, key=lambda x: x[0]): + coros.append(self._emit('messages', [(type_, data) for _, type_, data in messages], target_id)) self.messages.clear() for coro in coros: diff --git a/nicegui/static/nicegui.js b/nicegui/static/nicegui.js index 40960e37f..90ae2c393 100644 --- a/nicegui/static/nicegui.js +++ b/nicegui/static/nicegui.js @@ -325,6 +325,9 @@ function createApp(elements, options) { disconnect: () => { document.getElementById("popup").style.opacity = 1; }, + messages: (msg) => { + msg.forEach(([type, data]) => messageHandlers[type](data)); + }, update: async (msg) => { for (const [id, element] of Object.entries(msg)) { if (element === null) {