تعيين التدفقات ودمجها
حوّل التدفقات قبل وصولها إلى الشاشة
تعيين التدفقات ودمجها درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Shape Data Before the UI
Raw data rarely matches what the screen needs. You use flow operators to transform a stream into ready-to-render UI state.
Transform with map
The map operator runs a function on each emission and passes the result downstream, leaving the original stream untouched.
val names = users.map { it.name }Filter Out Noise
Use filter to drop emissions you do not care about, so only the items that pass your condition reach the UI.
val active = users.filter { it.isActive }Combine Two Streams
The combine operator merges multiple flows and re-runs whenever any of them emits, giving you the latest value from each.
combine(query, results) { q, r -> SearchUi(q, r) }Combine Builds UI State
A common pattern is to combine several source flows into one immutable UiState object that fully describes the screen.
combine(items, loading, error) { i, l, e ->
UiState(i, l, e)
}Wait for All with zip
While combine fires on any change, zip pairs emissions one-to-one and waits until both flows have produced a new value.
flowA.zip(flowB) { a, b -> a + b }Switch to a New Stream
With flatMapLatest a new value cancels the previous inner flow and switches to a fresh one, perfect for live search.
query.flatMapLatest { repo.search(it) }Operators Are Cold by Default
Transformations like map and filter are cold: they describe work but do nothing until something downstream collects.
Chain Operators Freely
You can chain operators into a pipeline. Each one reads the stream above it and feeds the one below, top to bottom.
users.filter { it.isActive }
.map { it.name }Handle Errors in the Chain
The catch operator intercepts exceptions upstream so you can emit a fallback instead of crashing the whole stream.
repo.load().catch { emit(emptyList()) }Keep Logic in the ViewModel
Do your combine and map work in the ViewModel, then expose one clean state flow. The Composable stays simple and dumb.
Quick Check
Pick the operator for the job.
Recap: Mapping & Combining
Great work! Operators like map, filter, and combine reshape and merge streams in the ViewModel so the UI gets exactly the state it needs. 🎯
الأسئلة الشائعة
هل درس «تعيين التدفقات ودمجها» مجاني؟
نعم — نص درس «تعيين التدفقات ودمجها» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
ماذا ستتعلم في «تعيين التدفقات ودمجها»؟
حوّل التدفقات قبل وصولها إلى الشاشة تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟
لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «تعيين التدفقات ودمجها»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟
نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- StateFlow مقابل SharedFlow
- تعيين التدفقات ودمجها
- stateIn وWhileSubscribed
- أحداث لمرة واحدة باستخدام Channels