Skip to content

Commit 1f4db3c

Browse files
committed
Update to Babel 6
It was time
1 parent 806d74f commit 1f4db3c

File tree

11 files changed

+79
-94
lines changed

11 files changed

+79
-94
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"optional": ["es7.objectRestSpread", "runtime"]
2+
"presets": ["es2015", "react", "stage-2"],
33
}

mocha.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
--compilers js:babel-core/register
12
--reporter spec
23
--require test-setup

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@
5252
"redux-thunk": "^2.0.1"
5353
},
5454
"devDependencies": {
55-
"babel": "^5.3.1",
56-
"babel-eslint": "^6",
57-
"babel-runtime": "5.8.25",
58-
"babelify": "^6.1.3",
55+
"babel-core": "^6.5.2",
56+
"babel-eslint": "^6.1",
57+
"babel-runtime": "6.9.2",
58+
"babelify": "^7.3.0",
59+
"babel-preset-es2015": "^6",
60+
"babel-preset-react": "^6",
61+
"babel-preset-stage-2": "^6",
5962
"browserify": "^11.0.0",
6063
"chai": "^3.2.0",
6164
"chai-stats": "^0.3.0",

src/state/reducers/views.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import R from 'ramda';
22
import Vector from 'immutable-vector2d';
33

44
import Components from '../../ui/diagram/components';
5-
import DrawingUtils from '../../ui/utils/DrawingUtils.js';
5+
import { diff } from '../../ui/utils/DrawingUtils.js';
66
import { snapToGrid } from '../../ui/diagram/Utils.js';
77
import { hoverFor } from '../../ui/diagram/boundingBox';
88
import { CURRENT } from '../../ui/diagram/Constants';
@@ -22,8 +22,6 @@ import {
2222

2323
const STANDING_OFFSET = CURRENT.DOT_DISTANCE / 2;
2424

25-
const { diff } = DrawingUtils;
26-
2725
const zip3 = (a, b, c) => R.zipWith(R.prepend, a, R.zip(b, c));
2826
const moreThanOne = R.pipe(
2927
R.length,

src/ui/diagram/Constants.js

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
const CONSTANTS = {
2-
LINE_WIDTH: 2,
1+
export const LINE_WIDTH = 2;
32

4-
GRID_SIZE: 20,
3+
export const GRID_SIZE = 20;
54

6-
DRAG_POINT_RADIUS: 8,
5+
export const DRAG_POINT_RADIUS = 8;
76

8-
BOUNDING_BOX_PADDING: 4,
7+
export const BOUNDING_BOX_PADDING = 4;
98

10-
RESISTOR: {
11-
LENGTH: 40,
12-
WIDTH: 12
13-
},
9+
export const RESISTOR = {
10+
LENGTH: 40,
11+
WIDTH: 12
12+
};
13+
14+
export const CAPACITOR = {
15+
WIDTH: 26,
16+
GAP: 10
17+
};
1418

15-
CAPACITOR: {
16-
WIDTH: 26,
17-
GAP: 10
18-
},
19+
export const INDUCTOR = {
20+
WIDTH: 12,
21+
RADIUS: 8
22+
};
1923

20-
INDUCTOR: {
21-
WIDTH: 12,
22-
RADIUS: 8
23-
},
24+
export const CURRENT_SOURCE = {
25+
RADIUS: 18
26+
};
2427

25-
CURRENT_SOURCE: {
26-
RADIUS: 18
27-
},
28-
VOLTAGE_SOURCE: {
29-
RADIUS: 22
30-
}
28+
export const VOLTAGE_SOURCE = {
29+
RADIUS: 22
3130
};
3231

33-
CONSTANTS.CURRENT = {
34-
DOT_DISTANCE: CONSTANTS.GRID_SIZE, // this makes the current flow nicely at the joins
32+
export const CURRENT = {
33+
DOT_DISTANCE: GRID_SIZE, // this makes the current flow nicely at the joins
3534
RADIUS: 4
3635
};
37-
38-
export default CONSTANTS;

src/ui/diagram/Utils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import Vector from 'immutable-vector2d';
2-
import Utils from '../utils/DrawingUtils.js';
2+
import { diff } from '../utils/DrawingUtils.js';
33
import { GRID_SIZE } from './Constants.js';
44

5-
const { diff } = Utils;
6-
75
export function snapToGrid(v: Vector) {
86
return v.snap(GRID_SIZE);
97
}

src/ui/diagram/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
rationaliseCurrentOffsets
1515
} from '../../state/actions';
1616
import resize from '../Resize';
17-
import Utils from '../utils/DrawingUtils';
17+
import {relMouseCoords} from '../utils/DrawingUtils';
1818
import createLoop from './loop';
1919
import createRender from './render';
2020

@@ -59,7 +59,7 @@ class CircuitDiagram extends React.Component {
5959
onMouse(event) {
6060
event.preventDefault();
6161
const { store } = this.context;
62-
const coords = Utils.relMouseCoords(event, this.canvas);
62+
const coords = relMouseCoords(event, this.canvas);
6363
switch (event.type) {
6464
case 'mousedown':
6565
case 'touchstart':

src/ui/diagram/render/labels.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {formatSI} from 'format-si-prefix';
33

44
import { LINE_WIDTH } from '../Constants';
55

6-
import DrawingUtils from '../../utils/DrawingUtils.js';
7-
const { midPoint, direction } = DrawingUtils;
6+
import { midPoint, direction } from '../../utils/DrawingUtils.js';
87

98
import CircuitComponents from '../components';
109
const lookupComponent = viewProps => CircuitComponents[viewProps.typeID];

src/ui/diagram/render/transforms.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import DrawingUtils from '../../utils/DrawingUtils.js';
1+
import { midPoint } from '../../utils/DrawingUtils.js';
22
import R from 'ramda';
33

4-
const { midPoint } = DrawingUtils;
5-
64
const length = dps => {
75
return dps[1].subtract(dps[0]).length();
86
};

src/ui/utils/DrawingUtils.js

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
11
import Vector from 'immutable-vector2d';
22
import evPos from 'ev-pos';
33

4-
const utils = {
5-
6-
midPoint(p1: Vector, p2: Vector): Vector {
7-
return p1.mix(p2);
8-
},
9-
10-
diff(p1: Vector, p2: Vector): Vector {
11-
return p1.subtract(p2);
12-
},
13-
14-
direction(p1: Vector, p2: Vector): Vector {
15-
return p2.subtract(p1).normalize();
16-
},
17-
18-
distance(p1: Vector, p2: Vector): Vector {
19-
return p1.subtract(p2);
20-
},
21-
22-
relMouseCoords(event, node) {
23-
return evPos(event.nativeEvent || event, node);
24-
},
25-
26-
getRectPointsBetween(p1: Vector, p2: Vector, width: number) {
27-
const v = utils.diff(p1, p2);
28-
const p = { // perpendicular
29-
x: v.y,
30-
y: -v.x
31-
};
32-
const l: number = v.length();
33-
const r: number = (width / l) / 2;
34-
const np = { // normalised perpendicular
35-
x: p.x * r,
36-
y: p.y * r
37-
};
38-
39-
const cs = [ // corners
40-
{x: p1.x + np.x, y: p1.y + np.y},
41-
{x: p1.x - np.x, y: p1.y - np.y},
42-
{x: p2.x - np.x, y: p2.y - np.y},
43-
{x: p2.x + np.x, y: p2.y + np.y}
44-
];
45-
46-
return cs;
47-
}
4+
export const midPoint = (p1: Vector, p2: Vector): Vector => {
5+
return p1.mix(p2);
486
};
497

50-
export default utils;
8+
export const diff = (p1: Vector, p2: Vector): Vector => {
9+
return p1.subtract(p2);
10+
};
11+
12+
export const direction = (p1: Vector, p2: Vector): Vector => {
13+
return p2.subtract(p1).normalize();
14+
};
15+
16+
export const distance = (p1: Vector, p2: Vector): Vector => {
17+
return p1.subtract(p2);
18+
};
19+
20+
export const relMouseCoords = (event, node) => {
21+
return evPos(event.nativeEvent || event, node);
22+
};
23+
24+
export const getRectPointsBetween = (p1: Vector, p2: Vector, width: number) => {
25+
const v = diff(p1, p2);
26+
const p = { // perpendicular
27+
x: v.y,
28+
y: -v.x
29+
};
30+
const l: number = v.length();
31+
const r: number = (width / l) / 2;
32+
const np = { // normalised perpendicular
33+
x: p.x * r,
34+
y: p.y * r
35+
};
36+
37+
const cs = [ // corners
38+
{x: p1.x + np.x, y: p1.y + np.y},
39+
{x: p1.x - np.x, y: p1.y - np.y},
40+
{x: p2.x - np.x, y: p2.y - np.y},
41+
{x: p2.x + np.x, y: p2.y + np.y}
42+
];
43+
44+
return cs;
45+
};

0 commit comments

Comments
 (0)