# अवस्था और डेटा प्रवाह

> CrossFly का अवस्था-दर्शन — कोई रिएक्टिव binding नहीं, कोई DI नहीं, अनिवार्य + स्पष्ट अमान्यीकरण।

Source: https://crossfly.dev/hi/docs/concepts/state-and-data-flow — CrossFly documentation. Full docs as one file: https://crossfly.dev/llms-full.txt

# अवस्था और डेटा प्रवाह

यहीं CrossFly Flutter, Compose, SwiftUI या React से आने वालों को सबसे ज़्यादा चौंकाता है। दो जानबूझकर की गई
अनुपस्थितियाँ:

- **कोई स्वचालित रिएक्टिव binding नहीं है।** न `setState`, न observables, न `@State`, न recomposition। मॉडल
  बदलना UI को स्वयं अपडेट **नहीं** करता।
- **कोई dependency injection कंटेनर नहीं है।** न Dagger/Guice/Spring। आप अपनी निर्भरताएँ हाथ से बनाते और
  पास करते हैं (आमतौर पर स्क्रीन के कंस्ट्रक्टर के ज़रिए)।

## मॉडल: अनिवार्य + स्पष्ट अमान्यीकरण
आप **मॉडल को पढ़ते/लिखते हैं**, **कंपोनेंट को सीधे अपडेट करते हैं** और फ्रेमवर्क **पुनः पेंट करता है**:
```java
model.nome = "Ana";
label.setText(model.nome);   // अधिकांश setters पहले से ही layout अमान्य कर repaint() को कॉल करते हैं
```
अधिकांश कंपोनेंट setters पहले से ही आपके लिए `repaint()` चालू करते हैं / layout को अमान्य करते हैं। याद रखने
योग्य एकमात्र नियम:

> **ऐसी अवस्था बदली जिसे फ्रेमवर्क नहीं जानता** (आपका कोई काउंटर, कोई गणना, `onPaint` में बनाया गया कोई फ़ील्ड)?
> **आप** `repaint()` को बुलाते हैं। (देखें [paint thread](/docs/concepts/the-paint-thread)।)

### क्लासिक प्रति-उदाहरण
```java
this.progresso = 0.7f;   // मैंने एक फ़ील्ड बदला जिसे केवल मेरा onPaint पढ़ता है…
// …और स्क्रीन नहीं बदलती। कमी है:
Component.repaint();      // ✔ अब अगला frame नए मान को दर्शाता है
```
"मैंने अवस्था बदली और स्क्रीन अपडेट नहीं हुई" लगभग हमेशा एक छूटा हुआ `repaint()` होता है।

## यह चुनाव क्यों
- **पूर्वानुमेयता:** प्रवाह रैखिक और दृश्यमान है — डेटा → setter → repaint → frame। डिबग करने के लिए न कोई
  जादुई recomposition है, न कोई छिपा रिएक्टिव चक्र।
- **शून्य जादू, कम लागत:** न कोई रिएक्टिव निर्भरता ग्राफ़, न कॉन्फ़िगर करने के लिए कोई DI फ्रेमवर्क।
- इसकी कीमत स्पष्टता है: **अवस्था प्रबंधित करना एप्लिकेशन की ज़िम्मेदारी है**, फ्रेमवर्क की नहीं।

## संचार के तंत्र जो फ्रेमवर्क प्रदान करता है
- **Callbacks / actions** — `onAction(...)`, कंस्ट्रक्टर से पास किए गए callbacks (देखें
  [मान लौटाना](/docs/ui/navigation/returning-results))।
- **अभिभावक/बच्चा पदानुक्रम** — कंपोनेंट के वृक्ष में नेविगेट करना।
- **`property(k, v)`** — प्रति कंपोनेंट "डेटा की थैली" (देखें [सब कुछ एक Component है](/docs/concepts/everything-is-a-component))।
- **वैश्विक अवस्था** — जब समझ में आए, तब साझा static फ़ील्ड/सेवाएँ।

## अनुशंसित पैटर्न
चूँकि फ्रेमवर्क केवल ब्लॉक देता है, संगठन का पैटर्न (प्रति स्क्रीन एक **ViewModel/controller** +
डेटा के लिए **repository**) एप्लिकेशन की परंपरा है — जो
[best-practices](/docs/best-practices) में प्रलेखित है। फ्रेमवर्क आर्किटेक्चर थोपता नहीं; वह
कंपोनेंट और setter→`repaint()` जोड़ी प्रदान करता है।

<div class="cf-diagram">
<svg role="img" id="my-svg" width="940" height="78" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="flowchart" style="max-width: 940.203px; background-color: transparent;" viewBox="0 0.014089584350585938 940.203125 77.98590850830078" role="graphics-document document" aria-roledescription="flowchart-v2"><style>#my-svg{font-family:Manrope,system-ui,sans-serif;font-size:14px;fill:var(--text);}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#my-svg .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#my-svg .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#my-svg .error-icon{fill:var(--bg-elev);}#my-svg .error-text{fill:var(--text-dim);stroke:var(--text-dim);}#my-svg .edge-thickness-normal{stroke-width:1px;}#my-svg .edge-thickness-thick{stroke-width:3.5px;}#my-svg .edge-pattern-solid{stroke-dasharray:0;}#my-svg .edge-thickness-invisible{stroke-width:0;fill:none;}#my-svg .edge-pattern-dashed{stroke-dasharray:3;}#my-svg .edge-pattern-dotted{stroke-dasharray:2;}#my-svg .marker{fill:var(--text-dim);stroke:var(--text-dim);}#my-svg .marker.cross{stroke:var(--text-dim);}#my-svg svg{font-family:Manrope,system-ui,sans-serif;font-size:14px;}#my-svg p{margin:0;}#my-svg .label{font-family:Manrope,system-ui,sans-serif;color:var(--text);}#my-svg .cluster-label text{fill:var(--text-dim);}#my-svg .cluster-label span{color:var(--text-dim);}#my-svg .cluster-label span p{background-color:transparent;}#my-svg .label text,#my-svg span{fill:var(--text);color:var(--text);}#my-svg .node rect,#my-svg .node circle,#my-svg .node ellipse,#my-svg .node polygon,#my-svg .node path{fill:var(--bg-soft);stroke:var(--border-strong);stroke-width:1px;}#my-svg .rough-node .label text,#my-svg .node .label text,#my-svg .image-shape .label,#my-svg .icon-shape .label{text-anchor:middle;}#my-svg .node .katex path{fill:var(--text-dim);stroke:var(--text-dim);stroke-width:1px;}#my-svg .rough-node .label,#my-svg .node .label,#my-svg .image-shape .label,#my-svg .icon-shape .label{text-align:center;}#my-svg .node.clickable{cursor:pointer;}#my-svg .root .anchor path{fill:var(--text-dim)!important;stroke-width:0;stroke:var(--text-dim);}#my-svg .arrowheadPath{fill:rgba(255, 255, 255, 0);}#my-svg .edgePath .path{stroke:var(--text-dim);stroke-width:1px;}#my-svg .flowchart-link{stroke:var(--text-dim);fill:none;}#my-svg .edgeLabel{background-color:var(--bg-elev);text-align:center;}#my-svg .edgeLabel p{background-color:var(--bg-elev);}#my-svg .edgeLabel rect{opacity:0.5;background-color:var(--bg-elev);fill:var(--bg-elev);}#my-svg .labelBkg{background-color:rgba(255, 255, 255, 0.5);}#my-svg .cluster rect{fill:var(--bg-elev);stroke:hsl(0, 0%, 90%);stroke-width:1px;}#my-svg .cluster text{fill:var(--text-dim);}#my-svg .cluster span{color:var(--text-dim);}#my-svg div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:Manrope,system-ui,sans-serif;font-size:12px;background:var(--bg-elev);border:1px solid hsl(0, 0%, 90%);border-radius:2px;pointer-events:none;z-index:100;}#my-svg .flowchartTitleText{text-anchor:middle;font-size:18px;fill:var(--text);}#my-svg rect.text{fill:none;stroke-width:0;}#my-svg .icon-shape,#my-svg .image-shape{background-color:var(--bg-elev);text-align:center;}#my-svg .icon-shape p,#my-svg .image-shape p{background-color:var(--bg-elev);padding:2px;}#my-svg .icon-shape .label rect,#my-svg .image-shape .label rect{opacity:0.5;background-color:var(--bg-elev);fill:var(--bg-elev);}#my-svg .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#my-svg .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#my-svg .node .neo-node{stroke:var(--border-strong);}#my-svg [data-look="neo"].node rect,#my-svg [data-look="neo"].cluster rect,#my-svg [data-look="neo"].node polygon{stroke:url(#my-svg-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg [data-look="neo"].swimlane.cluster rect{filter:none;}#my-svg [data-look="neo"].node path{stroke:url(#my-svg-gradient);stroke-width:1px;}#my-svg [data-look="neo"].node .outer-path{filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg [data-look="neo"].node .neo-line path{stroke:var(--border-strong);filter:none;}#my-svg [data-look="neo"].node circle{stroke:url(#my-svg-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg [data-look="neo"].node circle .state-start{fill:var(--text-dim);}#my-svg [data-look="neo"].icon-shape .icon{fill:url(#my-svg-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg [data-look="neo"].icon-shape .icon-neo path{stroke:url(#my-svg-gradient);filter:drop-shadow( 1px 2px 2px rgba(185,185,185,1));}#my-svg :root{--mermaid-font-family:Manrope,system-ui,sans-serif;}</style><g><marker id="my-svg_flowchart-v2-pointEnd" class="marker flowchart-v2" viewBox="0 0 10 10" refX="5" refY="5" markerUnits="userSpaceOnUse" markerWidth="8" markerHeight="8" orient="auto"><path d="M 0 0 L 10 5 L 0 10 z" class="arrowMarkerPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-pointStart" class="marker flowchart-v2" viewBox="0 0 10 10" refX="4.5" refY="5" markerUnits="userSpaceOnUse" markerWidth="8" markerHeight="8" orient="auto"><path d="M 0 5 L 10 10 L 10 0 z" class="arrowMarkerPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-pointEnd-margin" class="marker flowchart-v2" viewBox="0 0 11.5 14" refX="11.5" refY="7" markerUnits="userSpaceOnUse" markerWidth="10.5" markerHeight="14" orient="auto"><path d="M 0 0 L 11.5 7 L 0 14 z" class="arrowMarkerPath" style="stroke-width: 0; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-pointStart-margin" class="marker flowchart-v2" viewBox="0 0 11.5 14" refX="1" refY="7" markerUnits="userSpaceOnUse" markerWidth="11.5" markerHeight="14" orient="auto"><polygon points="0,7 11.5,14 11.5,0" class="arrowMarkerPath" style="stroke-width: 0; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-circleEnd" class="marker flowchart-v2" viewBox="0 0 10 10" refX="11" refY="5" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" orient="auto"><circle cx="5" cy="5" r="5" class="arrowMarkerPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-circleStart" class="marker flowchart-v2" viewBox="0 0 10 10" refX="-1" refY="5" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" orient="auto"><circle cx="5" cy="5" r="5" class="arrowMarkerPath" style="stroke-width: 1; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-circleEnd-margin" class="marker flowchart-v2" viewBox="0 0 10 10" refY="5" refX="12.25" markerUnits="userSpaceOnUse" markerWidth="14" markerHeight="14" orient="auto"><circle cx="5" cy="5" r="5" class="arrowMarkerPath" style="stroke-width: 0; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-circleStart-margin" class="marker flowchart-v2" viewBox="0 0 10 10" refX="-2" refY="5" markerUnits="userSpaceOnUse" markerWidth="14" markerHeight="14" orient="auto"><circle cx="5" cy="5" r="5" class="arrowMarkerPath" style="stroke-width: 0; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-crossEnd" class="marker cross flowchart-v2" viewBox="0 0 11 11" refX="12" refY="5.2" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" orient="auto"><path d="M 1,1 l 9,9 M 10,1 l -9,9" class="arrowMarkerPath" style="stroke-width: 2; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-crossStart" class="marker cross flowchart-v2" viewBox="0 0 11 11" refX="-1" refY="5.2" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" orient="auto"><path d="M 1,1 l 9,9 M 10,1 l -9,9" class="arrowMarkerPath" style="stroke-width: 2; stroke-dasharray: 1, 0;"/></marker><marker id="my-svg_flowchart-v2-crossEnd-margin" class="marker cross flowchart-v2" viewBox="0 0 15 15" refX="17.7" refY="7.5" markerUnits="userSpaceOnUse" markerWidth="12" markerHeight="12" orient="auto"><path d="M 1,1 L 14,14 M 1,14 L 14,1" class="arrowMarkerPath" style="stroke-width: 2.5;"/></marker><marker id="my-svg_flowchart-v2-crossStart-margin" class="marker cross flowchart-v2" viewBox="0 0 15 15" refX="-3.5" refY="7.5" markerUnits="userSpaceOnUse" markerWidth="12" markerHeight="12" orient="auto"><path d="M 1,1 L 14,14 M 1,14 L 14,1" class="arrowMarkerPath" style="stroke-width: 2.5; stroke-dasharray: 1, 0;"/></marker><g class="root"><g class="clusters"/><g class="edgePaths"><path d="M158.891,39L166.432,39C173.974,39,189.057,39,203.474,39C217.891,39,231.641,39,238.516,39L245.391,39" id="my-svg-L_Model_VM_0" class="edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link" style=";" data-edge="true" data-et="edge" data-id="L_Model_VM_0" data-points="W3sieCI6MTU4Ljg5MDYyNSwieSI6Mzl9LHsieCI6MjA0LjE0MDYyNSwieSI6Mzl9LHsieCI6MjQ5LjM5MDYyNSwieSI6Mzl9XQ==" data-look="classic" marker-end="url(#my-svg_flowchart-v2-pointEnd)"/><path d="M428.969,28.276L442.609,26.646C456.25,25.017,483.531,21.759,510.152,21.933C536.773,22.108,562.734,25.715,575.714,27.519L588.694,29.323" id="my-svg-L_VM_Comp_0" class="edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link" style=";" data-edge="true" data-et="edge" data-id="L_VM_Comp_0" data-points="W3sieCI6NDI4Ljk2ODc1LCJ5IjoyOC4yNzU1MDE4NDM1MDY3Nn0seyJ4Ijo1MTAuODEyNSwieSI6MTguNX0seyJ4Ijo1OTIuNjU2MjUsInkiOjI5Ljg3MzA4NjkwMzU2NDA1fV0=" data-look="classic" marker-end="url(#my-svg_flowchart-v2-pointEnd)"/><path d="M724.016,39L731.938,39C739.859,39,755.703,39,770.88,39C786.057,39,800.568,39,807.823,39L815.078,39" id="my-svg-L_Comp_Frame_0" class="edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link" style=";" data-edge="true" data-et="edge" data-id="L_Comp_Frame_0" data-points="W3sieCI6NzI0LjAxNTYyNSwieSI6Mzl9LHsieCI6NzcxLjU0Njg3NSwieSI6Mzl9LHsieCI6ODE5LjA3ODEyNSwieSI6Mzl9XQ==" data-look="classic" marker-end="url(#my-svg_flowchart-v2-pointEnd)"/><path d="M592.656,48.127L579.016,50.022C565.375,51.918,538.094,55.709,511.474,56.054C484.855,56.4,458.898,53.299,445.919,51.749L432.941,50.199" id="my-svg-L_Comp_VM_0" class="edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link" style=";" data-edge="true" data-et="edge" data-id="L_Comp_VM_0" data-points="W3sieCI6NTkyLjY1NjI1LCJ5Ijo0OC4xMjY5MTMwOTY0MzU5NX0seyJ4Ijo1MTAuODEyNSwieSI6NTkuNX0seyJ4Ijo0MjguOTY4NzUsInkiOjQ5LjcyNDQ5ODE1NjQ5MzI0fV0=" data-look="classic" marker-end="url(#my-svg_flowchart-v2-pointEnd)"/></g><g class="edgeLabels"><g class="edgeLabel" transform="translate(204.140625, 39)"><g class="label" data-id="L_Model_VM_0" transform="translate(-20.25, -10.5)"><foreignObject width="40.5" height="21"><div xmlns="http://www.w3.org/1999/xhtml" class="labelBkg" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="edgeLabel"><p>पढ़ता है</p></span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(510.91388, 18.51409)"><g class="label" data-id="L_VM_Comp_0" transform="translate(-56.84375, -10.5)"><foreignObject width="113.6875" height="21"><div xmlns="http://www.w3.org/1999/xhtml" class="labelBkg" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="edgeLabel"><p>setText / setItems</p></span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(771.546875, 39)"><g class="label" data-id="L_Comp_Frame_0" transform="translate(-22.53125, -10.5)"><foreignObject width="45.0625" height="21"><div xmlns="http://www.w3.org/1999/xhtml" class="labelBkg" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="edgeLabel"><p>repaint</p></span></div></foreignObject></g></g><g class="edgeLabel" transform="translate(510.8125, 59.5)"><g class="label" data-id="L_Comp_VM_0" transform="translate(-28.609375, -10.5)"><foreignObject width="57.21875" height="21"><div xmlns="http://www.w3.org/1999/xhtml" class="labelBkg" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="edgeLabel"><p>onAction</p></span></div></foreignObject></g></g></g><g class="nodes"><g class="node default" id="my-svg-flowchart-Model-0" data-look="classic" transform="translate(83.4453125, 39)"><rect class="basic label-container" style="" x="-75.4453125" y="-24.5" width="150.890625" height="49"/><g class="label" style="" transform="translate(-47.4453125, -10.5)"><rect/><foreignObject width="94.890625" height="21"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="nodeLabel"><p>मॉडल / रिपॉज़िटरी</p></span></div></foreignObject></g></g><g class="node default" id="my-svg-flowchart-VM-1" data-look="classic" transform="translate(339.1796875, 39)"><rect class="basic label-container" style="" x="-89.7890625" y="-24.5" width="179.578125" height="49"/><g class="label" style="" transform="translate(-61.7890625, -10.5)"><rect/><foreignObject width="123.578125" height="21"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="nodeLabel"><p>ViewModel (आपका)</p></span></div></foreignObject></g></g><g class="node default" id="my-svg-flowchart-Comp-3" data-look="classic" transform="translate(658.3359375, 39)"><rect class="basic label-container" style="" x="-65.6796875" y="-24.5" width="131.359375" height="49"/><g class="label" style="" transform="translate(-37.6796875, -10.5)"><rect/><foreignObject width="75.359375" height="21"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="nodeLabel"><p>Component</p></span></div></foreignObject></g></g><g class="node default" id="my-svg-flowchart-Frame-5" data-look="classic" transform="translate(875.640625, 39)"><rect class="basic label-container" style="" x="-56.5625" y="-24.5" width="113.125" height="49"/><g class="label" style="" transform="translate(-28.5625, -10.5)"><rect/><foreignObject width="57.125" height="21"><div xmlns="http://www.w3.org/1999/xhtml" style="display: table-cell; white-space: nowrap; line-height: 1.5; max-width: 200px; text-align: center;"><span class="nodeLabel"><p>अगला फ्रेम</p></span></div></foreignObject></g></g></g></g></g><defs><filter id="my-svg-drop-shadow" height="130%" width="130%"><feDropShadow dx="4" dy="4" stdDeviation="0" flood-opacity="0.06" flood-color="var(--text-dim)"/></filter></defs><defs><filter id="my-svg-drop-shadow-small" height="150%" width="150%"><feDropShadow dx="2" dy="2" stdDeviation="0" flood-opacity="0.06" flood-color="var(--text-dim)"/></filter></defs><linearGradient id="my-svg-gradient" gradientUnits="objectBoundingBox" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="var(--border-strong)" stop-opacity="1"/><stop offset="100%" stop-color="hsl(0, 0%, 90%)" stop-opacity="1"/></linearGradient></svg>
</div>

## यह भी देखें
- संबंधित: [paint thread](/docs/concepts/the-paint-thread) · [app आर्किटेक्चर (best-practices)](/docs/best-practices)
