CSS organization
Open live editorDiscover → Predict → Understand
What evidence shows that css organization keeps state and application behavior understandable?
Organize declarations by responsibility so a component change does not unexpectedly alter every page. This classifier is a design aid, not a CSS engine.
- Explain the operation and its responsibility.
- Predict actual values before execution.
- Identify local calculation, actual DOM and external execution boundaries.
Conceptual application flow
- User intent
- Action / handler
- Business logic
- State
- Render / persistence
Five source examples
Working contract
Organize declarations by responsibility so a component change does not unexpectedly alter every page. This classifier is a design aid, not a CSS engine.
async function main(input) {
return input.map(x=>({selector:x,scope:x.startsWith(".component-")?"component":"global review"}));
}Input
[ ".component-card", "body" ]
Fixed expected result
[
{
"selector": ".component-card",
"scope": "component"
},
{
"selector": "body",
"scope": "global review"
}
]Observe input preservation
The wrapper records the original input and compares it after the operation. Some lessons intentionally demonstrate mutation in a local copy.
async function calculate(input){
return input.map(x=>({selector:x,scope:x.startsWith(".component-")?"component":"global review"}));
}
async function main(input){const before=structuredClone(input);const result=await calculate(input);return {result,inputUnchanged:JSON.stringify(input)===JSON.stringify(before)};}Input
[ ".component-card", "body" ]
Fixed expected result
{
"result": [
{
"selector": ".component-card",
"scope": "component"
},
{
"selector": "body",
"scope": "global review"
}
],
"inputUnchanged": true
}Investigate the discarded result
An early return bypasses the intended operation. Repair the first incorrect boundary rather than changing the expected result.
async function calculate(input){
return input.map(x=>({selector:x,scope:x.startsWith(".component-")?"component":"global review"}));
}
async function main(input){return null; // Deliberate early return discards calculation
return await calculate(input);}Input
[ ".component-card", "body" ]
Fixed expected result
[
{
"selector": ".component-card",
"scope": "component"
},
{
"selector": "body",
"scope": "global review"
}
]Repeat the deterministic calculation
Invoke the same declared pure/model operation twice and compare both results. This is not an external idempotency guarantee.
async function calculate(input){
return input.map(x=>({selector:x,scope:x.startsWith(".component-")?"component":"global review"}));
}
async function main(input){return [await calculate(structuredClone(input)),await calculate(structuredClone(input))];}Input
[ ".component-card", "body" ]
Fixed expected result
[
[
{
"selector": ".component-card",
"scope": "component"
},
{
"selector": "body",
"scope": "global review"
}
],
[
{
"selector": ".component-card",
"scope": "component"
},
{
"selector": "body",
"scope": "global review"
}
]
]Frozen regression contract
Execute the operation and compare with a fixed fixture result. Changing the calculation must not silently rewrite the expectation.
async function calculate(input){
return input.map(x=>({selector:x,scope:x.startsWith(".component-")?"component":"global review"}));
}
async function main(input){const actual=await calculate(input);const expected=[{"selector":".component-card","scope":"component"},{"selector":"body","scope":"global review"}];if(JSON.stringify(actual)!==JSON.stringify(expected))throw Error("Regression contract mismatch");return {pass:true,actual};}Input
[ ".component-card", "body" ]
Fixed expected result
{
"pass": true,
"actual": [
{
"selector": ".component-card",
"scope": "component"
},
{
"selector": "body",
"scope": "global review"
}
]
}Important operations
[
{
"line": 1,
"source": "async function main(input) {",
"explanation": "Declare the named operation or local value and follow its scope in the source."
},
{
"line": 2,
"source": "return input.map(x=>({selector:x,scope:x.startsWith(\".component-\")?\"component\":\"global review\"}));",
"explanation": "Create a new array from declared inputs; inspect which nested references are retained."
},
{
"line": 3,
"source": "}",
"explanation": "Declare the named operation or local value and follow its scope in the source."
}
]Guided mission
- Discover the problem and inspect source/input.
- Write a prediction. Run the actual source and inspect the returned value.
- Change one requirement and state the new expected result independently.
- Load the repair exercise, reproduce the failure and use hints.
- Restore the authored fixture and Check, then explain and extend.
Three hints
- Locate the input, transition and returned result before editing.
- Compare the first differing field and trace which expression produced it.
- Remove the deliberate early return and restore the named responsibility; compare with Finished Code only after trying.
Complete solution
async function main(input) {
return input.map(x=>({selector:x,scope:x.startsWith(".component-")?"component":"global review"}));
}Common mistake: Changing the expected result to match a defect instead of repairing the behavior.
Invalid JSON is rejected before execution. Syntax and thrown errors are shown. Model kernels for DOM, HTTP and Node teach contracts; use the actual browser and exported server projects for those execution boundaries.
Reflect and extend
Which returned value or actual DOM observation supports your explanation? Which side effect was outside this check?
Create a second normal, boundary and invalid case. Write exact expected values before execution and explain what the provided fixture does not prove.
AI prompt goals
- Explain the current source, input, actual output and architecture boundary.
- Help refactor one responsibility while preserving independently expected behavior.
- Investigate the current error and propose normal, boundary and invalid tests.