@@ -115,9 +115,9 @@ the component. Most constructors will also take some other values,
115115that won't change over time, such as the function they can use to
116116((dispatch)) an action.
117117
118- {{index "setState method"}}
118+ {{index "syncState method"}}
119119
120- Each component has a ` setState ` method that is used to synchronize it
120+ Each component has a ` syncState ` method that is used to synchronize it
121121to a new state value. The method takes one argument, the state, which
122122is of the same type as the first argument to its constructor.
123123
@@ -287,21 +287,21 @@ class PictureCanvas {
287287 onmousedown: event => this.mouse(event, pointerDown),
288288 ontouchstart: event => this.touch(event, pointerDown)
289289 });
290- this.setState (picture);
290+ this.syncState (picture);
291291 }
292- setState (picture) {
292+ syncState (picture) {
293293 if (this.picture == picture) return;
294294 this.picture = picture;
295295 drawPicture(this.picture, this.dom, scale);
296296 }
297297}
298298```
299299
300- {{index "setState method", efficiency}}
300+ {{index "syncState method", efficiency}}
301301
302302We draw each pixel as a 10-by-10 square, as determined by the ` scale `
303303constant. To avoid unnecessary work, the component keeps track of its
304- current picture, and does a redraw only when ` setState ` is given a new
304+ current picture, and does a redraw only when ` syncState ` is given a new
305305picture.
306306
307307{{index "drawPicture function"}}
@@ -445,10 +445,10 @@ class PixelEditor {
445445 ...this.controls.reduce(
446446 (a, c) => a.concat(" ", c.dom), []));
447447 }
448- setState (state) {
448+ syncState (state) {
449449 this.state = state;
450- this.canvas.setState (state.picture);
451- for (let ctrl of this.controls) ctrl.setState (state);
450+ this.canvas.syncState (state.picture);
451+ for (let ctrl of this.controls) ctrl.syncState (state);
452452 }
453453}
454454```
@@ -457,14 +457,14 @@ The pointer handler given to `PictureCanvas` calls the currently
457457selected tool with the appropriate arguments and, if that returns a
458458move handler, adapts it to also receive the state.
459459
460- {{index "reduce method", "map method", whitespace, "setState method"}}
460+ {{index "reduce method", "map method", whitespace, "syncState method"}}
461461
462462All controls are constructed and stored in ` this.controls ` so that
463463they can be updated when the application state changes. The call to
464464` reduce ` introduces spaces between the controls' DOM elements. That
465465way they don't look so pressed together.
466466
467- {{index "select (HTML tag)", "change event", "ToolSelect class", "setState method"}}
467+ {{index "select (HTML tag)", "change event", "ToolSelect class", "syncState method"}}
468468
469469The first control is the ((tool)) selection menu. It creates a
470470` <select> ` element with an option for each tool, and sets up a
@@ -481,7 +481,7 @@ class ToolSelect {
481481 }, name)));
482482 this.dom = elt("label", null, "🖌 Tool: ", this.select);
483483 }
484- setState (state) { this.select.value = state.tool; }
484+ syncState (state) { this.select.value = state.tool; }
485485}
486486```
487487
@@ -508,7 +508,7 @@ Depending on the browser, the color picker might look like this:
508508
509509if}}
510510
511- {{index "ColorSelect class", "setState method"}}
511+ {{index "ColorSelect class", "syncState method"}}
512512
513513This ((control)) creates such a field and wires it up to stay
514514synchronized with the application state's ` color ` property.
@@ -523,7 +523,7 @@ class ColorSelect {
523523 });
524524 this.dom = elt("label", null, "🎨 Color: ", this.input);
525525 }
526- setState (state) { this.input.value = state.color; }
526+ syncState (state) { this.input.value = state.color; }
527527}
528528```
529529
@@ -664,7 +664,7 @@ We can now test our application!
664664 controls: [ToolSelect, ColorSelect],
665665 dispatch(action) {
666666 state = updateState(state, action);
667- app.setState (state);
667+ app.syncState (state);
668668 }
669669 });
670670 document.querySelector("div").appendChild(app.dom);
@@ -700,7 +700,7 @@ class SaveButton {
700700 link.click();
701701 link.remove();
702702 }
703- setState (state) { this.picture = state.picture; }
703+ syncState (state) { this.picture = state.picture; }
704704}
705705```
706706
@@ -742,7 +742,7 @@ class LoadButton {
742742 onclick: () => startLoad(dispatch)
743743 }, "📁 Load");
744744 }
745- setState () {}
745+ syncState () {}
746746}
747747
748748function startLoad(dispatch) {
@@ -916,7 +916,7 @@ class UndoButton {
916916 disabled: state.done.length == 0
917917 }, "⮪ Undo");
918918 }
919- setState (state) {
919+ syncState (state) {
920920 this.dom.disabled = state.done.length == 0;
921921 }
922922}
@@ -955,7 +955,7 @@ function startPixelEditor({state = startState,
955955 controls,
956956 dispatch(action) {
957957 state = historyUpdateState(state, action);
958- app.setState (state);
958+ app.syncState (state);
959959 }
960960 });
961961 return app.dom;
@@ -1081,10 +1081,10 @@ keys are held down.
10811081 ...this.controls.reduce(
10821082 (a, c) => a.concat(" ", c.dom), []));
10831083 }
1084- setState (state) {
1084+ syncState (state) {
10851085 this.state = state;
1086- this.canvas.setState (state.picture);
1087- for (let ctrl of this.controls) ctrl.setState (state);
1086+ this.canvas.syncState (state.picture);
1087+ for (let ctrl of this.controls) ctrl.syncState (state);
10881088 }
10891089 }
10901090
@@ -1126,9 +1126,9 @@ in `drawPicture`. Creating a new state and updating the rest of the
11261126DOM isn't very expensive, but repainting all the pixels on the canvas
11271127is quite a bit of work.
11281128
1129- {{index "setState method", "PictureCanvas class"}}
1129+ {{index "syncState method", "PictureCanvas class"}}
11301130
1131- Find a way to make the ` setState ` method of ` PictureCanvas ` faster by
1131+ Find a way to make the ` syncState ` method of ` PictureCanvas ` faster by
11321132redrawing only the pixels that actually changed.
11331133
11341134{{index "drawPicture function", compatibility}}
@@ -1149,7 +1149,7 @@ transparent again.
11491149<div></div>
11501150<script>
11511151 // Change this method
1152- PictureCanvas.prototype.setState = function(picture) {
1152+ PictureCanvas.prototype.syncState = function(picture) {
11531153 if (this.picture == picture) return;
11541154 this.picture = picture;
11551155 drawPicture(this.picture, this.dom, scale);
0 commit comments