glre 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/native.ts +17 -23
- package/package.json +1 -1
- package/react.ts +1 -0
- package/solid.ts +4 -5
package/native.ts
CHANGED
|
@@ -6,42 +6,36 @@ import { frame } from 'refr'
|
|
|
6
6
|
import type { GL } from './types'
|
|
7
7
|
import type { Fun } from 'refr'
|
|
8
8
|
|
|
9
|
-
export const useGLEvent = <T>(props: Partial<GL & T> = {}, self = gl) => {
|
|
10
|
-
const memo = useMutable(props) as Partial<GL>
|
|
11
|
-
return useMemo(() => self(memo), [])
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
export const useGL = (props: Partial<GL> = {}, self = gl) => {
|
|
15
|
-
const
|
|
16
|
-
|
|
10
|
+
const change = () => {
|
|
11
|
+
self.resize(
|
|
12
|
+
void 0,
|
|
13
|
+
self.gl.drawingBufferWidth,
|
|
14
|
+
self.gl.drawingBufferHeight
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
const memo1 = useMutable(props) as Partial<GL>
|
|
18
|
+
const memo2 = useMutable({
|
|
17
19
|
ref(gl: any) {
|
|
18
|
-
self(memo)
|
|
19
20
|
self.el = {}
|
|
20
21
|
self.gl = gl
|
|
21
22
|
self.mount()
|
|
22
23
|
},
|
|
23
24
|
mount() {
|
|
24
|
-
const {
|
|
25
|
-
drawingBufferWidth: width,
|
|
26
|
-
drawingBufferHeight: height,
|
|
27
|
-
} = self.gl
|
|
28
|
-
self.size = [width, height]
|
|
29
25
|
self.init()
|
|
30
|
-
|
|
31
|
-
Dimensions.addEventListener('change', self.change)
|
|
26
|
+
change()
|
|
32
27
|
frame.start()
|
|
28
|
+
Dimensions.addEventListener('change', change)
|
|
33
29
|
},
|
|
34
30
|
clean() {
|
|
31
|
+
self(memo2)(memo1)
|
|
35
32
|
frame.cancel()
|
|
36
33
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
self.resize(void 0, width, height)
|
|
43
|
-
},
|
|
44
|
-
})
|
|
34
|
+
}) as Partial<GL>
|
|
35
|
+
|
|
36
|
+
useEffect(() => self.clean, [self])
|
|
37
|
+
|
|
38
|
+
return useMemo(() => self(memo2)(memo1), [self, memo2, memo1])
|
|
45
39
|
}
|
|
46
40
|
|
|
47
41
|
export function useTexture(props: any, self = gl) {
|
package/package.json
CHANGED
package/react.ts
CHANGED
|
@@ -30,6 +30,7 @@ export const useGL = (props: Partial<GL> = {}, self = gl) => {
|
|
|
30
30
|
window.addEventListener('mousemove', self.mousemove)
|
|
31
31
|
},
|
|
32
32
|
clean() {
|
|
33
|
+
self(memo2)(memo1)
|
|
33
34
|
frame.cancel()
|
|
34
35
|
window.removeEventListener('resize', self.resize)
|
|
35
36
|
window.removeEventListener('mousemove', self.mousemove)
|
package/solid.ts
CHANGED
|
@@ -5,8 +5,7 @@ import type { Fun } from 'reev/types'
|
|
|
5
5
|
|
|
6
6
|
export function createGL(props?: any, self = gl) {
|
|
7
7
|
onCleanup(self.clean)
|
|
8
|
-
|
|
9
|
-
return self({
|
|
8
|
+
const memo = {
|
|
10
9
|
ref(target: unknown) {
|
|
11
10
|
if (target) {
|
|
12
11
|
self.target = target
|
|
@@ -14,7 +13,6 @@ export function createGL(props?: any, self = gl) {
|
|
|
14
13
|
}
|
|
15
14
|
},
|
|
16
15
|
mount() {
|
|
17
|
-
self(props)
|
|
18
16
|
self.el = self.target
|
|
19
17
|
self.gl = self.target.getContext('webgl2')
|
|
20
18
|
self.init()
|
|
@@ -24,12 +22,13 @@ export function createGL(props?: any, self = gl) {
|
|
|
24
22
|
window.addEventListener('mousemove', self.mousemove)
|
|
25
23
|
},
|
|
26
24
|
clean() {
|
|
27
|
-
self(props)
|
|
25
|
+
self(props)(memo)
|
|
28
26
|
frame.cancel()
|
|
29
27
|
window.removeEventListener('resize', self.resize)
|
|
30
28
|
window.removeEventListener('mousemove', self.mousemove)
|
|
31
29
|
},
|
|
32
|
-
}
|
|
30
|
+
}
|
|
31
|
+
return self(props)(memo)
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
export function onFrame(fun: Fun, self = gl) {
|