Sobes.tech

Frontend

/* * Backend'dan ma'lumot so'rashni taqlid qiladigan funktsiya. * Backend RPS chekloviga ega va muvaffaqiyatsiz bo'ladi, * agar parallel so'rovlar soni MAX_PARALLEL_REQUESTS dan oshsa. */ function requestData(id: number): Promise<string> { parallelRequests++; if (parallelRequests > MAX_PARALLEL_REQUESTS) { throw new Error("Juda ko'p parallel so'rovlar"); } return new Promise((res) => { setTimeout(() => { parallelRequests--; return res(`${id * 2}`); }, Math.floor(Math.random() * 2000)) }); } function prepareData( ids: number[], maxParallelRequests: number, ): Promise<string[]> { /* * TODO: barcha ma'lumotlarni so'rashni amalga oshiring, * maksimal maxParallelRequests * parallel ulanishlardan foydalanib. */ }

137

React uchun maxsus useSubState hookini amalga oshiring, u to'liq holatni, setState funksiyasini va kalit nomini (obyekt maydonini) qabul qiladi va bu maydonning qiymati va uni o'zgartirish uchun funksiyadan iborat tupni qaytaradi — useState ga o'xshash, lekin katta holat ob'ektining ma'lum bir maydoni uchun.

120

function cloneDeep(something: Cloneable): Cloneable { /* * TODO: chuqur nusxa ko'chirishni JSON.parse/stringifysiz amalga oshiring */ return JSON.parse(JSON.stringify(something)); } function assertDeep(a: Cloneable, b: Cloneable) { if (JSON.stringify(a) !== JSON.stringify(b)) { console.error("Not OK"); } console.log("OK"); } const obj: Cloneable = { a: 1, b: true, c: "salom", d: { there: "are", some: ["properties"] }, e: {}, f: [(), (), { key: { value: [1, 2, "3", "four"] } }], g: [] }; assertDeep(obj, cloneDeep(obj));

108