-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathmarkerFacetNumber.tsx
More file actions
70 lines (57 loc) · 1.68 KB
/
Copy pathmarkerFacetNumber.tsx
File metadata and controls
70 lines (57 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { useEffect } from 'react'
import { createRoot } from '@react-facet/dom-fiber'
import { useFacetState, Facet, useFacetMap, NO_VALUE, Map } from '@react-facet/core'
import { times } from 'ramda'
interface Marker {
x: number
y: number
}
function Marker({ marker }: { marker: Facet<Marker> }) {
const leftValue = useFacetMap(({ x }) => x * 1920, [], [marker])
const topValue = useFacetMap(({ y }) => y * 1080, [], [marker])
return (
<fast-div
className={'123'}
style={{
width: '4rem',
height: '4rem',
backgroundColor: 'green',
position: 'absolute',
topPX: topValue,
leftPX: leftValue,
}}
/>
)
}
function Performance() {
const [testingFacet, setTestingFacet] = useFacetState(times(() => ({ x: Math.random(), y: Math.random() }), 1000))
useEffect(() => {
let frameId: number
const update = () => {
setTestingFacet((testing) => {
if (testing === NO_VALUE) return []
for (let i = 0; i < testing.length; i++) {
testing[i].x = Math.random()
testing[i].y = Math.random()
}
return testing
})
frameId = window.requestAnimationFrame(update)
}
update()
return () => {
window.cancelAnimationFrame(frameId)
}
}, [setTestingFacet])
return (
<div style={{ width: '1920px', height: '1080px', position: 'relative' }}>
<Map array={testingFacet}>{(item, index) => <Marker key={index} marker={item} />}</Map>
</div>
)
}
document.body.innerHTML = '<div id="root"/>'
const element = document.getElementById('root')
if (element !== null) {
const root = createRoot(element)
root.render(<Performance />)
}