diff --git a/content/docs/nav.yml b/content/docs/nav.yml index 52b29e693..49f7c2ef2 100644 --- a/content/docs/nav.yml +++ b/content/docs/nav.yml @@ -64,7 +64,7 @@ - id: react-without-jsx title: React بدون JSX - id: reconciliation - title: Reconciliation + title: المطابقة (Reconciliation) - id: refs-and-the-dom title: Refs and the DOM - id: render-props diff --git a/content/docs/reconciliation.md b/content/docs/reconciliation.md index 1624bfbde..6689a0f63 100644 --- a/content/docs/reconciliation.md +++ b/content/docs/reconciliation.md @@ -1,35 +1,35 @@ --- id: reconciliation -title: Reconciliation +title: المطابقة (Reconciliation) permalink: docs/reconciliation.html --- -React provides a declarative API so that you don't have to worry about exactly what changes on every update. This makes writing applications a lot easier, but it might not be obvious how this is implemented within React. This article explains the choices we made in React's "diffing" algorithm so that component updates are predictable while being fast enough for high-performance apps. +تُزوّدنا React بواجهة برمجة تطبيقات (API) صريحة بحيث لا نقلق بشأن التغييرات التي تطرأ في كل تحديث. يجعل هذا من كتابة التطبيقات أمرًا أسهل بكثير، ولكن قد لا يكون من الواضح كثيرًا كيفيّة تطبيق هذا في React. تشرح هذه الصفحة الخيارات التي وضعناها في خوارزمية المقارنة (diffing) بحيث تكون تحديثات المُكوّنات متوقعة وفي نفس الوقت سريعة كفاية لأجل التطبيقات عالية الأداء. -## Motivation {#motivation} +## تحفيز {#motivation} -When you use React, at a single point in time you can think of the `render()` function as creating a tree of React elements. On the next state or props update, that `render()` function will return a different tree of React elements. React then needs to figure out how to efficiently update the UI to match the most recent tree. +عندما تستخدم React في نقطة زمنية محددة بإمكانك التفكير في التابع `render()` وكأنّه يُنشِئ شجرة من عناصر React، وعند التحديث التالي للخاصيات `props` أو الحالة `state` سيُعيد التابع `render()‎` شجرة مختلفة من عناصر React. تحتاج بعدها React لأن تعرف كيف ستُحدِّث واجهة المستخدم بكفاءة لُتطابِق آخر تحديث للشجرة. -There are some generic solutions to this algorithmic problem of generating the minimum number of operations to transform one tree into another. However, the [state of the art algorithms](https://grfia.dlsi.ua.es/ml/algorithms/references/editsurvey_bille.pdf) have a complexity in the order of O(n3) where n is the number of elements in the tree. +هنالك بعض الحلول العامة لهذه المشكلة الحسابية لتوليد أقل عدد من العمليات المطلوبة للتحويل من شجرة إلى أخرى. على أية حال تمتلك [الخوارزميات النموذجيّة](https://grfia.dlsi.ua.es/ml/algorithms/references/editsurvey_bille.pdf) تعقيدًا من الترتيب O(n3) حيث n هو عدد العناصر الموجودة في الشجرة. -If we used this in React, displaying 1000 elements would require in the order of one billion comparisons. This is far too expensive. Instead, React implements a heuristic O(n) algorithm based on two assumptions: +إن استخدمنا هذا في React فسيتطلّب عرض 1000 عنصر من الأس (1^) بليون مقارنة، وهذا مُكلِف جدًّا. تُنفِّذ React بدلًا من ذلك خوارزمية إرشاديّة O(n)‎ بناءً على افتراضين هما: -1. Two elements of different types will produce different trees. -2. The developer can hint at which child elements may be stable across different renders with a `key` prop. +1. سيُنتِج العنصران من نوعين مختلفين أشجار مختلفة. +2. يُمكِن للمُطوّر أن يُلمِّح للعناصر الأبناء التي قد تكون مستقرة خلال تصييرات مختلفة عن طريق خاصيّة مفتاح (`key`) للإشارة إليها. -In practice, these assumptions are valid for almost all practical use cases. +عمليًّا تكون هذه الافتراضات صحيحة تقريبًا لكل حالات الاستخدام العمليّة. -## The Diffing Algorithm {#the-diffing-algorithm} +## خوارزميّة المقارنة (Diffing Algorithm) {#the-diffing-algorithm} -When diffing two trees, React first compares the two root elements. The behavior is different depending on the types of the root elements. +عند مقارنة شجرتين تُقارِن React في البداية بين العنصرين الجذريين لهما. يختلف هذا السلوك اعتمادًا على أنواع العناصر الجذريّة. -### Elements Of Different Types {#elements-of-different-types} +### العناصر من أنواع مختلفة {#elements-of-different-types} -Whenever the root elements have different types, React will tear down the old tree and build the new tree from scratch. Going from `` to ``, or from `
` to ``, or from `