Clock Class — react Architecture
Architecture documentation for the Clock class in Clock.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 85a7bb5e_f42b_35c7_ce24_22564222542f["Clock"] 3a7e99dd_a5c5_f3c7_9c40_65dc549077bf["Clock.js"] 85a7bb5e_f42b_35c7_ce24_22564222542f -->|defined in| 3a7e99dd_a5c5_f3c7_9c40_65dc549077bf fce62b73_eba4_c50e_66ea_b6d1be6fdd8f["componentDidMount()"] 85a7bb5e_f42b_35c7_ce24_22564222542f -->|method| fce62b73_eba4_c50e_66ea_b6d1be6fdd8f ed32ecbe_ba45_fa03_530e_5cb5acf9ecac["componentDidUpdate()"] 85a7bb5e_f42b_35c7_ce24_22564222542f -->|method| ed32ecbe_ba45_fa03_530e_5cb5acf9ecac d7f9827d_84ff_0713_3f72_59888be5e4c2["componentWillUnmount()"] 85a7bb5e_f42b_35c7_ce24_22564222542f -->|method| d7f9827d_84ff_0713_3f72_59888be5e4c2 c7886fe3_1b80_c7df_c482_5d2ab80c9be9["render()"] 85a7bb5e_f42b_35c7_ce24_22564222542f -->|method| c7886fe3_1b80_c7df_c482_5d2ab80c9be9
Relationship Graph
Source Code
fixtures/concurrent/time-slicing/src/Clock.js lines 6–105
export default class Clock extends PureComponent {
faceRef = createRef();
arcGroupRef = createRef();
clockHandRef = createRef();
frame = null;
hitCounter = 0;
rotation = 0;
t0 = Date.now();
arcs = [];
animate = () => {
const now = Date.now();
const td = now - this.t0;
this.rotation = (this.rotation + SPEED * td) % (2 * Math.PI);
this.t0 = now;
this.arcs.push({rotation: this.rotation, td});
let lx, ly, tx, ty;
if (this.arcs.length > FRAMES) {
this.arcs.forEach(({rotation, td}, i) => {
lx = tx;
ly = ty;
const r = 145;
tx = 155 + r * Math.cos(rotation);
ty = 155 + r * Math.sin(rotation);
const bigArc = SPEED * td < Math.PI ? '0' : '1';
const path = `M${tx} ${ty}A${r} ${r} 0 ${bigArc} 0 ${lx} ${ly}L155 155`;
const hue = 120 - Math.min(120, td / 4);
const colour = `hsl(${hue}, 100%, ${60 - i * (30 / FRAMES)}%)`;
if (i !== 0) {
const arcEl = this.arcGroupRef.current.children[i - 1];
arcEl.setAttribute('d', path);
arcEl.setAttribute('fill', colour);
}
});
this.clockHandRef.current.setAttribute('d', `M155 155L${tx} ${ty}`);
this.arcs.shift();
}
if (this.hitCounter > 0) {
this.faceRef.current.setAttribute(
'fill',
`hsla(0, 0%, ${this.hitCounter}%, 0.95)`
);
this.hitCounter -= 1;
} else {
this.hitCounter = 0;
this.faceRef.current.setAttribute('fill', 'hsla(0, 0%, 5%, 0.95)');
}
this.frame = requestAnimationFrame(this.animate);
};
componentDidMount() {
this.frame = requestAnimationFrame(this.animate);
if (this.faceRef.current) {
this.faceRef.current.addEventListener('click', this.handleClick);
}
}
componentDidUpdate() {
console.log('componentDidUpdate()', this.faceRef.current);
}
componentWillUnmount() {
this.faceRef.current.removeEventListener('click', this.handleClick);
if (this.frame) {
cancelAnimationFrame(this.frame);
}
}
handleClick = e => {
e.stopPropagation();
this.hitCounter = 50;
};
render() {
const paths = new Array(FRAMES);
for (let i = 0; i < FRAMES; i++) {
paths.push(<path className="arcHand" key={i} />);
Domain
Source
Frequently Asked Questions
What is the Clock class?
Clock is a class in the react codebase, defined in fixtures/concurrent/time-slicing/src/Clock.js.
Where is Clock defined?
Clock is defined in fixtures/concurrent/time-slicing/src/Clock.js at line 6.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free