Latihan 1 dari materi CQRS (Command Query Responsibility Segregation) di Design Patterns — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.
Bangun model CQRS sederhana untuk user.
createUserCQRS() return object dengan:
execute(command) — terima command seperti { type: "RegisterUser", id, name } atau { type: "UpdateName", id, name }. Validasi ringan (id tidak boleh kosong, name tidak boleh kosong). Jika invalid throw error. Jika valid → simpan ke write store dan update read projection.query(query) — terima query seperti { type: "GetUser", id } (return user dari read store) atau { type: "GetAllNames" } (return array nama, sorted ascending).writeCount() — jumlah command yang sukses ter-apply.Read projection adalah map { id: { id, name } } — update langsung setiap command sukses.