Skip to content

Commit ed4d8cb

Browse files
authored
Remove mobx and legacy version (#309)
* Remove legacy version * Remove mobx so we can write some tests
1 parent 5f37c61 commit ed4d8cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1325
-2682
lines changed

MODULE.bazel.lock

+778-372
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/BUILD

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,20 @@ ts_library(
2020
deps = [
2121
"//:node_modules/@material-ui/core",
2222
"//:node_modules/@material-ui/icons",
23-
"//:node_modules/@types/js-base64",
2423
"//:node_modules/@types/pako",
2524
"//:node_modules/@types/react",
2625
"//:node_modules/@types/react-dom",
2726
"//:node_modules/@types/react-router",
2827
"//:node_modules/@types/react-router-dom",
2928
"//:node_modules/@types/uuid",
3029
"//:node_modules/js-base64",
31-
"//:node_modules/mobx",
32-
"//:node_modules/mobx-react",
3330
"//:node_modules/pako",
3431
"//:node_modules/react",
3532
"//:node_modules/react-dom",
3633
"//:node_modules/react-router",
3734
"//:node_modules/react-router-dom",
3835
"//:node_modules/uuid",
36+
"//common",
3937
],
4038
)
4139

client/app.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
import { Drawer } from "#asciiflow/client/drawer";
1010
import { DrawingId, store, ToolMode } from "#asciiflow/client/store";
1111
import { screenToCell, View } from "#asciiflow/client/view";
12-
import { useObserver } from "mobx-react";
12+
1313
import { HashRouter, Route, useParams } from "react-router-dom";
1414
import * as ReactDOM from "react-dom";
1515
import { Vector } from "#asciiflow/client/vector";
1616
import { textToLayer } from "#asciiflow/client/text_utils";
17+
import { useWatchable } from "#asciiflow/common/watchable";
1718

1819
const controller = new Controller();
1920
const touchController = new TouchController(controller);
@@ -25,7 +26,7 @@ export interface IRouteProps {
2526
}
2627

2728
export const App = () => {
28-
return useObserver(() => {
29+
return useWatchable(() => {
2930
const routeProps = useParams<IRouteProps>();
3031
store.setRoute(
3132
routeProps.share
@@ -86,7 +87,7 @@ document.addEventListener("paste", (e) => {
8687
if (store.selectTool.selectBox) {
8788
position = store.selectTool.selectBox.topLeft();
8889
}
89-
if (store.toolMode === ToolMode.TEXT && store.textTool.currentPosition) {
90+
if (store.toolMode.get() === ToolMode.TEXT && store.textTool.currentPosition) {
9091
position = store.textTool.currentPosition;
9192
}
9293
const pastedLayer = textToLayer(clipboardText, position);

client/controller.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as constants from "#asciiflow/client/constants";
22
import { store, IModifierKeys, ToolMode } from "#asciiflow/client/store";
33
import { Vector } from "#asciiflow/client/vector";
4-
import { screenToCell } from "#asciiflow/client/view";
4+
import { screenToCell, setCanvasCursor } from "#asciiflow/client/view";
55
import { HTMLAttributes } from "react";
66

77
import * as React from "react";
@@ -69,7 +69,7 @@ export class Controller {
6969
let specialKeyCode = null;
7070

7171
if (event.altKey) {
72-
store.altPressed = true;
72+
store.altPressed.set(true);
7373
if (event.keyCode === "1".charCodeAt(0)) {
7474
store.setToolMode(ToolMode.BOX);
7575
event.preventDefault();
@@ -140,7 +140,7 @@ export class Controller {
140140
specialKeyCode = constants.KEY_RIGHT;
141141
}
142142
if (event.keyCode === 32) {
143-
store.panning = true;
143+
store.panning.set(true);
144144
}
145145

146146
if (specialKeyCode != null) {
@@ -150,10 +150,10 @@ export class Controller {
150150

151151
handleKeyUp(event: KeyboardEvent) {
152152
if (event.keyCode === 32) {
153-
store.panning = false;
153+
store.panning.set(false);
154154
}
155155
if (!event.altKey) {
156-
store.altPressed = false;
156+
store.altPressed.set(false);
157157
}
158158
}
159159

@@ -167,10 +167,9 @@ export class Controller {
167167

168168
// Update the cursor pointer, depending on the draw function.
169169
if (!moveCell.equals(this.lastMoveCell)) {
170-
store.setCurrentCursor(store.currentTool.getCursor(
171-
moveCell,
172-
getModifierKeys(e)
173-
));
170+
setCanvasCursor(
171+
store.currentTool.getCursor(moveCell, getModifierKeys(e))
172+
);
174173
}
175174

176175
// In drawing mode, so pass the mouse move on, but remove duplicates.
@@ -214,7 +213,7 @@ export class DesktopController {
214213

215214
handleMouseDown = (e: React.MouseEvent<any>) => {
216215
// Can drag by holding either the control or meta (Apple) key.
217-
if (store.panning) {
216+
if (store.panning.get()) {
218217
this.controller.startDrag(Vector.fromMouseEvent(e));
219218
} else {
220219
this.controller.startDraw(Vector.fromMouseEvent(e), e);

client/draw/freeform.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ export class DrawFreeform extends AbstractDrawFunction {
88

99
start(position: Vector) {
1010
this.currentLayer = new Layer();
11-
this.currentLayer.set(position, store.freeformCharacter);
11+
this.currentLayer.set(position, store.freeformCharacter.get());
1212
store.currentCanvas.setScratchLayer(this.currentLayer);
1313
}
1414

1515
move(position: Vector) {
1616
[this.currentLayer] = new Layer().apply(this.currentLayer);
17-
this.currentLayer.set(position, store.freeformCharacter);
17+
this.currentLayer.set(position, store.freeformCharacter.get());
1818
store.currentCanvas.setScratchLayer(this.currentLayer);
1919
}
2020

@@ -29,7 +29,7 @@ export class DrawFreeform extends AbstractDrawFunction {
2929
handleKey(value: string) {
3030
if (value && value.length === 1) {
3131
// The value is not a special character, so lets use it.
32-
store.freeformCharacter = value;
32+
store.freeformCharacter.set(value);
3333
}
3434
}
3535
}

client/draw/line.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import {
44
connects,
55
disconnect,
66
} from "#asciiflow/client/characters";
7+
import { UNICODE } from "#asciiflow/client/constants";
78
import { Direction } from "#asciiflow/client/direction";
8-
import {
9-
AbstractDrawFunction
10-
} from "#asciiflow/client/draw/function";
9+
import { AbstractDrawFunction } from "#asciiflow/client/draw/function";
1110
import { line } from "#asciiflow/client/draw/utils";
1211
import { Layer, LayerView } from "#asciiflow/client/layer";
1312
import { cellContext } from "#asciiflow/client/render_layer";
@@ -35,9 +34,12 @@ export class DrawLine extends AbstractDrawFunction {
3534
}
3635

3736
draw(modifierKeys: IModifierKeys) {
37+
if (!this.startPosition || !this.endPosition) {
38+
return;
39+
}
3840
const layer = new Layer();
3941
// Try to infer line orientation.
40-
const characters = store.characters;
42+
const characters = UNICODE;
4143
const startContext = cellContext(
4244
this.startPosition,
4345
store.currentCanvas.committed

client/draw/move.ts

-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export class DrawMove extends AbstractDrawFunction {
4949
.filter((a) => a.direction === Direction.DOWN)
5050
.map((a) => a.end.y)
5151
);
52-
console.log(minX, maxX, minY, maxY);
53-
console.log(this.trace);
5452
// Calculate the effective position after calculating bounds.
5553
const effectivePosition = new Vector(
5654
Math.min(Math.max(position.x, minX), maxX),

client/draw/select.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { AbstractDrawFunction } from "#asciiflow/client/draw/function";
1111
import { DrawMove } from "#asciiflow/client/draw/move";
1212
import { Layer } from "#asciiflow/client/layer";
1313
import { snap } from "#asciiflow/client/snap";
14-
import { IModifierKeys, store } from "#asciiflow/client/store";
14+
import { IModifierKeys, store, ToolMode } from "#asciiflow/client/store";
1515
import { layerToText, textToLayer } from "#asciiflow/client/text_utils";
1616
import { Vector } from "#asciiflow/client/vector";
1717

@@ -139,7 +139,7 @@ export class DrawSelect extends AbstractDrawFunction {
139139
return "default";
140140
}
141141

142-
handleKey(value: string) {
142+
handleKey(value: string, modifierKeys: IModifierKeys) {
143143
if (this.selectBox != null) {
144144
// Use the native keyboard for copy pasting.
145145
if (value === KEY_COPY || value === KEY_CUT) {
@@ -176,5 +176,8 @@ export class DrawSelect extends AbstractDrawFunction {
176176
store.currentCanvas.setScratchLayer(layer);
177177
store.currentCanvas.commitScratch();
178178
}
179+
180+
// store.setToolMode(ToolMode.TEXT);
181+
// store.currentTool.handleKey(value, modifierKeys);
179182
}
180183
}

client/draw/text.ts

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class DrawText extends AbstractDrawFunction {
2424
}
2525

2626
handleKey(value: string, modifierKeys: IModifierKeys) {
27+
if (!this.currentPosition) {
28+
return;
29+
}
2730
let newLayer = new Layer();
2831
if (!!this.textLayer) {
2932
[newLayer] = newLayer.apply(this.textLayer);

client/drawer.tsx

+18-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styles from "#asciiflow/client/drawer.module.css";
55
import { ExportDialog } from "#asciiflow/client/export";
66
import { DrawingId, store, ToolMode } from "#asciiflow/client/store";
77
import { DrawingStringifier } from "#asciiflow/client/store/drawing_stringifier";
8+
import { useWatchable } from "#asciiflow/common/watchable";
89
import {
910
Button,
1011
Chip,
@@ -21,17 +22,16 @@ import {
2122
Paper,
2223
Popover,
2324
Snackbar,
24-
TextField
25+
TextField,
2526
} from "@material-ui/core";
2627
import * as Icons from "@material-ui/icons";
27-
import { useObserver } from "mobx-react";
2828
import * as React from "react";
2929
import { useState } from "react";
3030
import { useHistory } from "react-router";
3131

3232
export function Drawer() {
3333
const history = useHistory();
34-
return useObserver(() => {
34+
return useWatchable(() => {
3535
if (!store.controlsOpen.get()) {
3636
return (
3737
<Fab
@@ -77,7 +77,7 @@ export function Drawer() {
7777
<Icons.GetApp />
7878
</IconButton>
7979
}
80-
drawingId={store.route}
80+
drawingId={store.route.get()}
8181
/>
8282

8383
<NewDrawingButton />
@@ -218,14 +218,15 @@ export function Drawer() {
218218
</IconButton>
219219
</ListItemSecondaryAction>
220220
</ListItem>
221-
{!store.editControlsOpen.get() ? null : store.route.shareSpec ? (
221+
{!store.editControlsOpen.get() ? null : store.route.get()
222+
.shareSpec ? (
222223
<>
223224
<div className={styles.helpText}>
224225
This is a shared drawing. To make edits fork it so it can be
225226
saved locally.
226227
</div>
227228
<div className={styles.helpText}>
228-
<ForkDrawingButton drawingId={store.route} />
229+
<ForkDrawingButton drawingId={store.route.get()} />
229230
</div>
230231
</>
231232
) : (
@@ -375,7 +376,7 @@ export function Drawer() {
375376
<ShortcutChip label={"arrow keys"} /> to move around.
376377
</ToolHelp>{" "}
377378
Pan around the canvas by holding <ShortcutChip label="space" />
378-
{store.route.shareSpec ? (
379+
{store.route.get().shareSpec ? (
379380
"."
380381
) : (
381382
<>
@@ -386,9 +387,7 @@ export function Drawer() {
386387
redo.
387388
</>
388389
)}{" "}
389-
View shortcuts by pressing <ShortcutChip label={"alt"} />. You
390-
can return to the previous version of ASCIIFlow{" "}
391-
<a href="legacy">here</a>.
390+
View shortcuts by pressing <ShortcutChip label={"alt"} />.
392391
</div>
393392
)}
394393
</>
@@ -412,8 +411,8 @@ function ShortcutChip({
412411
label: string;
413412
hideUntilAlt?: boolean;
414413
}) {
415-
return useObserver(() => {
416-
if (hideUntilAlt && !store.altPressed) return null;
414+
return useWatchable(() => {
415+
if (hideUntilAlt && !store.altPressed.get()) return null;
417416
return (
418417
<Chip
419418
icon={<Icons.KeyboardOutlined />}
@@ -433,10 +432,10 @@ function ToolControl(
433432
icon: React.ReactNode;
434433
}>
435434
) {
436-
return useObserver(() => {
435+
return useWatchable(() => {
437436
return (
438437
<ListItem
439-
selected={store.toolMode === props.tool}
438+
selected={store.toolMode.get() === props.tool}
440439
button={true}
441440
onClick={() => store.setToolMode(props.tool)}
442441
>
@@ -458,15 +457,15 @@ const shortcutKeys = [
458457
];
459458
function FreeFormCharacterSelect() {
460459
const [anchorEl, setAnchorEl] = useState(null);
461-
return useObserver(() => {
460+
return useWatchable(() => {
462461
return (
463462
<>
464463
<Button
465464
variant="outlined"
466465
className={styles.freeformCharacterButton}
467466
onClick={(event) => setAnchorEl(event.currentTarget)}
468467
>
469-
{store.freeformCharacter}
468+
{store.freeformCharacter.get()}
470469
</Button>
471470
<Popover
472471
open={!!anchorEl}
@@ -483,7 +482,7 @@ function FreeFormCharacterSelect() {
483482
onClick={() => {
484483
setAnchorEl(null);
485484
store.setToolMode(ToolMode.FREEFORM);
486-
store.freeformCharacter = key;
485+
store.freeformCharacter.set(key);
487486
}}
488487
className={styles.freeformCharacterButton}
489488
key={i}
@@ -503,8 +502,8 @@ function ToolHelp(
503502
tool: ToolMode;
504503
}>
505504
) {
506-
return useObserver(() => {
507-
return store.toolMode === props.tool ? <>{props.children}</> : null;
505+
return useWatchable(() => {
506+
return store.toolMode.get() === props.tool ? <>{props.children}</> : null;
508507
});
509508
}
510509

client/export.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { ASCII, UNICODE } from "#asciiflow/client/constants";
1616
import styles from "#asciiflow/client/export.module.css";
1717
import { DrawingId, store } from "#asciiflow/client/store";
1818
import { layerToText } from "#asciiflow/client/text_utils";
19-
import { useObserver } from "mobx-react";
2019
import * as React from "react";
20+
import { useWatchable } from "#asciiflow/common/watchable";
2121

2222
export interface IExportConfig {
2323
wrapper?: "star" | "star-filled" | "triple-quotes" | "hash" | "slash" | "three-slashes" | "dash" | "apostrophe" | "semicolon" | "backticks" | "four-spaces";
@@ -32,7 +32,7 @@ export function ExportDialog({
3232
button: React.ReactNode;
3333
drawingId: DrawingId;
3434
}) {
35-
return useObserver(() => {
35+
return useWatchable(() => {
3636
const [open, setOpen] = React.useState(false);
3737
const exportConfig = store.exportConfig.get();
3838
// Only compute the text if the dialog is open.

client/menu/files.scss

Whitespace-only changes.

client/menu/files.tsx

-8
This file was deleted.

0 commit comments

Comments
 (0)