Skip to content

Commit e10cd31

Browse files
refactor(examples): update for-loops (use const where possible)
1 parent 5ceaf1a commit e10cd31

File tree

20 files changed

+25
-25
lines changed

20 files changed

+25
-25
lines changed

examples/big-font/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Font {
5757
// build index of character pairs & their kern values
5858
// e.g. { L: { Y: -2 } } for a Y following an L will be shifted left
5959
this.rows = rows.slice(0, height);
60-
for (let pair of rows.slice(height)) {
60+
for (const pair of rows.slice(height)) {
6161
if (!pair.length) continue;
6262
const [[a, b], k] = pair.split(" ");
6363
this.kerning = setIn(this.kerning, [a, b], parseInt(k));
@@ -112,7 +112,7 @@ class Font {
112112
getText([first, ...rest]: string, spacing = 0, kern = true) {
113113
let res = this.getChar(first, spacing);
114114
let prev = first;
115-
for (let c of rest) {
115+
for (const c of rest) {
116116
res = this.kernPair(res, prev, c, spacing, kern);
117117
prev = c;
118118
}

examples/boid-basics/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const scene = fromRAF({ timestamp: true }).map((t) => {
105105
// find distance to closest neighbor
106106
let closest: Nullable<Boid>;
107107
let minD = MAX_RADIUS ** 2;
108-
for (let n of neighbors) {
108+
for (const n of neighbors) {
109109
if (n === boid) continue;
110110
const d = distSq2(pos, n.pos.value);
111111
if (d < minD) {

examples/color-themes/src/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const themePart = (
3232
});
3333

3434
export const randomizeThemeParts = () => {
35-
for (let part of Object.values(parts)) {
35+
for (const part of Object.values(parts)) {
3636
part.next({
3737
range: RANGE_IDs[SYSTEM.int() % RANGE_IDs.length],
3838
base: lch.random(),

examples/fiber-basics/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const SNAP = 16;
2020
const cellAnim = (scene: Group, delay: number) =>
2121
function* main(ctx: Fiber) {
2222
// infinite loop over [0..5) interval
23-
for (let x of cycle(range(NUM))) {
23+
for (const x of cycle(range(NUM))) {
2424
// each cell as its own child process
2525
ctx.fork(
2626
cell(scene, x * W, 0, W, SIZE, SYSTEM.probability(0.5), 0.05)
@@ -53,7 +53,7 @@ const cell = (
5353
true
5454
).take(alpha.length >> 1);
5555
// loop to grow/shrink and fade out rect
56-
for (let [a, hh] of zip(alpha, symmetric(height))) {
56+
for (const [a, hh] of zip(alpha, symmetric(height))) {
5757
// add cell rect to scene
5858
const attribs = { fill: setAlpha(null, col, a) };
5959
scene.add(

examples/geom-webgl-attrib-pool/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ meldDeepObj(cursorModel, <Partial<UncompiledModelSpec>>{
244244
// references:
245245
// - https://docs.thi.ng/umbrella/vector-pools/ (readme examples)
246246
// - https://docs.thi.ng/umbrella/vector-pools/classes/AttribPool.html
247-
for (let col of charModel.attribPool!.attribValues<Float32Array>("color")) {
247+
for (const col of charModel.attribPool!.attribValues<Float32Array>("color")) {
248248
// pick random color for each vertex
249249
// see: https://docs.thi.ng/umbrella/color/#md:color-theme-generation
250250
col.set(srgb(colorFromRange("bright")));

examples/geom-webgl-basics/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const model = asWebGlModel(geo, {
6161
// references:
6262
// - https://docs.thi.ng/umbrella/vector-pools/ (readme examples)
6363
// - https://docs.thi.ng/umbrella/vector-pools/classes/AttribPool.html
64-
for (let col of model.attribPool!.attribValues<Float32Array>("color")) {
64+
for (const col of model.attribPool!.attribValues<Float32Array>("color")) {
6565
// pick random color for each vertex
6666
// see: https://docs.thi.ng/umbrella/color/#md:color-theme-generation
6767
col.set(srgb(colorFromRange("bright")));

examples/hdom-benchmark2/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ const grid = <any>{
106106
);
107107
let mergedCells = new Set(changed);
108108
if (this.prevChanged) {
109-
for (let x of this.prevChanged) {
109+
for (const x of this.prevChanged) {
110110
mergedCells.add(x);
111111
}
112112
}
113113
const mergedRows = new Set(changedRows);
114114
if (this.prevChangedRows) {
115-
for (let x of this.prevChangedRows) {
115+
for (const x of this.prevChangedRows) {
116116
mergedRows.add(x);
117117
}
118118
}

examples/imgui-basics/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const updateGUI = () => {
8888
let inner = grid.nest(PRESETS.length);
8989
// create button for each volume preset
9090
// and update state if a button was pressed
91-
for (let preset of PRESETS) {
91+
for (const preset of PRESETS) {
9292
res = buttonH({
9393
gui,
9494
layout: inner,

examples/poisson-image/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const points = timed(() =>
4242
);
4343

4444
// set pixels in result image
45-
for (let p of points) res.setAtUnsafe(p[0], p[1], 0);
45+
for (const p of points) res.setAtUnsafe(p[0], p[1], 0);
4646

4747
// create canvas from pixel buffer and attach to DOM
4848
canvasFromPixelBuffer(res, document.body);

examples/poly-subdiv/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function* update() {
147147
// polygon splitting variance (should be in [0..0.1] range, YMMV)
148148
const eps = 0;
149149
// cycle(...) creates an infinitely repeating sequence of values
150-
for (let base of cycle(range(0.01, 1, 0.01))) {
150+
for (const base of cycle(range(0.01, 1, 0.01))) {
151151
// pointfree dataflow pipeline to iteratively subdivide a seed polygon
152152
// and transform the result shapes. the given operations are executed in
153153
// sequence, with each result being threaded (as last arg) to the

0 commit comments

Comments
 (0)