Skip to content

Commit 2fc205c

Browse files
committed
Docs: Update Contributor model JSDoc for Turbo Mode compatibility (#9066)
1 parent 0cae8b9 commit 2fc205c

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

apps/devrank/model/Contributor.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,25 @@ class Contributor extends Model {
4949
{
5050
name : 'total_commits',
5151
type : 'Integer',
52+
/**
53+
* Calculates the total commits from the yearly breakdown.
54+
*
55+
* **Turbo Mode / Soft Hydration Compatibility:**
56+
* In "Turbo Mode" (autoInitRecords: false), the Store sorts raw JSON objects, not Record instances.
57+
* The `Neo.data.Store#doSort` "Soft Hydration" logic resolves this field (`total_commits`)
58+
* by calling this `calculate` function on the raw object.
59+
*
60+
* - **Record Context:** `data` is a Record. `data.commits_array` exists (via getter/mapping).
61+
* - **Raw Context:** `data` is a POJO. `data.commits_array` is undefined. `data.cy` exists.
62+
*
63+
* To support both contexts without forcing full record instantiation (performance killer),
64+
* we must check for both the canonical name AND the raw data key.
65+
*
66+
* @param {Object|Neo.data.Record} data
67+
* @returns {Number}
68+
*/
5269
calculate: data => {
53-
return data.commits_array?.reduce((a, b) => a + b, 0) || 0;
70+
return (data.commits_array || data.cy)?.reduce((a, b) => a + b, 0) || 0;
5471
}
5572
}
5673
]

0 commit comments

Comments
 (0)