Skip to content

Commit 8c4f29a

Browse files
committed
Update loaded class
Moved loaded class to core and apply to container after init
1 parent c4f0c7d commit 8c4f29a

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/core/shader.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ export class Shader extends domHandler {
1414
private shaderProgram: WebGLProgram;
1515
private vertexBuffer: WebGLBuffer;
1616
private uniforms: Array<UniformValue> | undefined
17+
private loadedClass: string = 'loaded'
1718

1819
constructor(container: HTMLCanvasElement, args: ShaderArgs) {
1920
super(container);
2021
this.gl = container.getContext('webgl') as WebGLRenderingContext;
2122
this.shaderProgram = this.initializeShader(args.vertShader, args.fragShader);
2223
this.vertexBuffer = this.initBuffers();
23-
this.uniforms = args.uniforms
24-
// Initialize custom logic if provided
25-
args.hooks?.forEach((hook) => {
24+
25+
if (args.uniforms) this.uniforms = args.uniforms
26+
if (args.loadedClass) this.loadedClass = args.loadedClass
27+
if (args.hooks) args.hooks.forEach((hook) => {
2628
this.addHook(hook.methodName, hook.hook)
2729
})
2830
}
@@ -37,6 +39,7 @@ export class Shader extends domHandler {
3739
this.uniforms?.forEach((uniform) => {
3840
this.setUniform(uniform)
3941
})
42+
this.container.classList.add(this.loadedClass)
4043
}
4144

4245
public addHook(methodName: MethodName, hook: ShaderHook): void {

src/react/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import { ShaderArgs } from "../types";
66

77
export const SimpleShaderCanvas = ({
88
args,
9-
className,
10-
loadedClass = 'loaded'
9+
className
1110
}: {
1211
args: ShaderArgs,
13-
className?: string,
14-
loadedClass?: string
12+
className?: string
1513
}) => {
1614

1715
const ref = useRef<HTMLCanvasElement>(null);
@@ -28,7 +26,7 @@ export const SimpleShaderCanvas = ({
2826
return (
2927
<canvas
3028
ref={ref}
31-
className={`${className} ${loadedClass}`}
29+
className={`${className}`}
3230
style={{ width: '100%' }}
3331
/>
3432
)

src/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ declare namespace simpleShaderComponent {
1313
fragShader?: string,
1414
uniforms?: Array<UniformValue>,
1515
hooks?: Array<{ methodName: MethodName, hook: ShaderHook }>
16+
/** Default 'loaded' */
17+
loadedClass?: string
1618
}
1719

1820
type UniformValue = {

0 commit comments

Comments
 (0)