Complete source code for the Chat App built with Nahir UI and K2
We're working on this example and the full source code will be available soon. Here's a preview of what's to come:
# Chat App Example using Nahir UI import NahirUI import WebSocket # Chat App component component ChatApp { state = { currentUser: null, messages: [], channels: [], currentChannel: "general", newMessage: "", connected: false } # Initialize WebSocket connection function init() { # Connect to WebSocket server this.socket = WebSocket.connect("wss://api.k2lang.org/chat") # Set up event handlers this.socket.onOpen(function() { state.connected = true updateState() }) this.socket.onMessage(function(data) { const message = JSON.parse(data) if (message.type == "message") { receiveMessage(message) } else if (message.type == "channel_list") { state.channels = message.channels updateState() } }) # Request channel list this.socket.send(JSON.stringify({ type: "get_channels" })) } # More code will be available soon... }
Check back soon for the complete source code of the Chat App example!
Explore Nahir UI DocsGet started with Nahir UI and build ultra-fast user interfaces for your K2 applications.