Skip to content

Commit 3ddfa00

Browse files
renovate[bot]manolara
authored andcommitted
Update dependency @testing-library/react to v14 (P5-wrapper#228)
add deepCompare boolean prop address comments add deepCompare prop
1 parent b32d28d commit 3ddfa00

File tree

8 files changed

+2646
-5194
lines changed

8 files changed

+2646
-5194
lines changed

example/app.jsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import React, { Fragment, useCallback, useMemo, useState } from "react";
22
import { createRoot } from "react-dom/client";
3-
3+
import * as Tone from "tone";
44
import * as box from "./sketches/box";
55
import * as plane from "./sketches/plane";
66
import * as torus from "./sketches/torus";
7+
import * as synth from "./sketches/synth";
78
import { ReactP5Wrapper } from "../src/index.tsx";
89
import "./example.css";
910

1011
function App() {
1112
const sketches = useMemo(
12-
() => [box.sketch, torus.sketch, plane.sketch],
13-
[box, torus, plane]
13+
() => [box.sketch, torus.sketch, plane.sketch, synth.sketch],
14+
[box, torus, plane, synth]
1415
);
1516
const [state, setState] = useState({
1617
rotation: 160,
@@ -42,7 +43,7 @@ function App() {
4243
rotation: parseInt(event.target.value, 10)
4344
}));
4445
},
45-
[box, plane, torus]
46+
[box, plane, torus, synth]
4647
);
4748

4849
if (state.unmount) {
@@ -53,10 +54,17 @@ function App() {
5354
</Fragment>
5455
);
5556
}
57+
const synth1 = useMemo(()=>new Tone.Synth({oscillator:{
58+
type: "sine"}})
59+
.toDestination(),[]);
60+
const gain = useMemo(()=>new Tone.Gain(0.5).toDestination(),[]);
61+
const synth2 = useMemo(()=>new Tone.Synth().connect(gain),[]);
62+
const [currentSynth, setCurrentSynth] = useState(synth1);
63+
5664

5765
return (
5866
<Fragment>
59-
<ReactP5Wrapper sketch={state.sketch} rotation={state.rotation} />
67+
<ReactP5Wrapper sketch={state.sketch} rotation={state.rotation} deepCompare={false} synth={currentSynth} />
6068
<input
6169
type="range"
6270
defaultValue={state.rotation}
@@ -65,8 +73,13 @@ function App() {
6573
step="1"
6674
onChange={onRotationChange}
6775
/>
76+
6877
<button onClick={onChangeSketch}>Change Sketch</button>
6978
<button onClick={onMountStateChange}>Unmount</button>
79+
{state.sketch=== synth.sketch?<>
80+
<button onClick={()=>setCurrentSynth(synth1)}>Synth 1</button>
81+
<button onClick={()=>setCurrentSynth(synth2)}>Synth 2</button>
82+
</>:null}
7083
</Fragment>
7184
);
7285
}

example/sketches/box.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export function sketch(p5) {
33

44
p5.setup = () => p5.createCanvas(300, 300, p5.WEBGL);
55

6-
p5.updateWithProps = props => {
6+
p5.updateWithProps = (props) => {
77
if (props.rotation) {
88
rotation = (props.rotation * Math.PI) / 180;
99
}

example/sketches/synth.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as Tone from "tone";
2+
3+
export function sketch(p5) {
4+
let rotation = 0;
5+
let currentSynth;
6+
7+
const loop = new Tone.Loop((time) => {
8+
if (currentSynth) {
9+
currentSynth.triggerAttackRelease("C4", "8n", time);
10+
}
11+
}, "4n");
12+
13+
p5.setup = () => {
14+
p5.createCanvas(300, 300, p5.WEBGL);
15+
p5.createButton("start").mousePressed(() => {
16+
Tone.start();
17+
Tone.Transport.start();
18+
loop.start();
19+
});
20+
};
21+
22+
p5.updateWithProps = (props) => {
23+
if (props.rotation) {
24+
rotation = (props.rotation * Math.PI) / 180;
25+
}
26+
if (props.synth) {
27+
currentSynth = props.synth;
28+
}
29+
};
30+
31+
p5.draw = () => {
32+
p5.background(100);
33+
p5.normalMaterial();
34+
p5.noStroke();
35+
36+
p5.push();
37+
p5.translate(-35, 0);
38+
p5.rotateY(rotation);
39+
p5.rotateX(-0.9);
40+
p5.box(100);
41+
p5.pop();
42+
43+
p5.noFill();
44+
p5.stroke(255);
45+
p5.push();
46+
p5.translate(400, p5.height * 0.35, -200);
47+
p5.sphere(300);
48+
p5.pop();
49+
};
50+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"@rollup/plugin-replace": "^5.0.2",
8989
"@rollup/plugin-terser": "^0.4.0",
9090
"@rollup/plugin-typescript": "^11.0.0",
91-
"@testing-library/react": "^13.4.0",
91+
"@testing-library/react": "^14.0.0",
9292
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
9393
"@types/jest": "^29.2.3",
9494
"@types/p5": "^1.4.3",
@@ -114,6 +114,7 @@
114114
"rimraf": "^4.0.0",
115115
"rollup": "^3.4.0",
116116
"style-loader": "^3.3.1",
117+
"tone": "^14.7.77",
117118
"ts-jest": "^29.0.3",
118119
"ts-loader": "^9.4.1",
119120
"tslib": "^2.4.1",

0 commit comments

Comments
 (0)