You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 15:06:20 +00:00
feat(events,session): add React-friendly subscribe APIs and snapshot getters
Adds backwards-compatible primitives needed to consume the renderer from React 19 hooks (useSyncExternalStore, use(), TanStack Query) without re-architecting the event bus. - EventDispatcher.subscribe(type, cb): () => void — unsubscriber-returning wrapper matching the useSyncExternalStore subscribe signature. - CommunicationManager.subscribeMessage(eventCtor, handler): () => void — packet-stream equivalent. - SessionDataManager.getUserDataSnapshot() and RoomSessionManager.getActiveRoomSessionSnapshot() — referentially-stable read-only views invalidated through new SESSION_DATA_UPDATED and ROOM_SESSION_UPDATED events. All additive; existing addEventListener/removeEventListener / IRoomSession APIs are unchanged. Bumps renderer to 2.1.0.
This commit is contained in:
@@ -101,4 +101,23 @@ export class EventDispatcher implements IEventDispatcher
|
||||
{
|
||||
this._listeners.clear();
|
||||
}
|
||||
|
||||
public subscribe<T extends INitroEvent>(type: string | string[], callback: (event: T) => void): () => void
|
||||
{
|
||||
if(!type || !callback) return () => {};
|
||||
|
||||
if(Array.isArray(type))
|
||||
{
|
||||
for(const t of type) this.addEventListener<T>(t, callback);
|
||||
|
||||
return () =>
|
||||
{
|
||||
for(const t of type) this.removeEventListener(t, callback);
|
||||
};
|
||||
}
|
||||
|
||||
this.addEventListener<T>(type, callback);
|
||||
|
||||
return () => this.removeEventListener(type, callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,6 @@ export class NitroEventType
|
||||
public static readonly AVATAR_EFFECT_DOWNLOADED = 'AVATAR_EFFECT_DOWNLOADED';
|
||||
public static readonly AVATAR_EFFECT_LOADED = 'AVATAR_EFFECT_LOADED';
|
||||
public static readonly FURNITURE_DATA_LOADED = 'FURNITURE_DATA_LOADED';
|
||||
public static readonly SESSION_DATA_UPDATED = 'SESSION_DATA_UPDATED';
|
||||
public static readonly ROOM_SESSION_UPDATED = 'ROOM_SESSION_UPDATED';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user