Skip to content

Commit c3d4c85

Browse files
committed
Stop returning GJ from mutation methods
1 parent a65386c commit c3d4c85

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

backend/src/lib.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ impl LTN {
123123
}
124124

125125
#[wasm_bindgen(js_name = setCurrentNeighbourhood)]
126-
pub fn set_current_neighbourhood(&mut self, name: String) -> Result<String, JsValue> {
126+
pub fn set_current_neighbourhood(&mut self, name: String) -> Result<(), JsValue> {
127127
let boundary_gj = self.map.boundaries.get(&name).cloned().unwrap();
128128
let mut boundary_geo: Polygon = boundary_gj.try_into().map_err(err_to_js)?;
129129
self.map.mercator.to_mercator_in_place(&mut boundary_geo);
130130

131131
self.neighbourhood =
132132
Some(Neighbourhood::new(&self.map, name, boundary_geo).map_err(err_to_js)?);
133-
self.render_neighbourhood()
133+
Ok(())
134134
}
135135

136136
/// Takes a LngLat
137137
#[wasm_bindgen(js_name = addModalFilter)]
138-
pub fn add_modal_filter(&mut self, input: JsValue, kind: String) -> Result<String, JsValue> {
138+
pub fn add_modal_filter(&mut self, input: JsValue, kind: String) -> Result<(), JsValue> {
139139
let pos: LngLat = serde_wasm_bindgen::from_value(input)?;
140140
self.map.add_modal_filter(
141141
self.map.mercator.pt_to_mercator(Coord {
@@ -145,16 +145,12 @@ impl LTN {
145145
&self.neighbourhood.as_ref().unwrap().interior_roads,
146146
FilterKind::from_string(&kind).unwrap(),
147147
);
148-
self.render_neighbourhood()
148+
Ok(())
149149
}
150150

151151
/// Takes a LineString feature
152152
#[wasm_bindgen(js_name = addManyModalFilters)]
153-
pub fn add_many_modal_filters(
154-
&mut self,
155-
input: JsValue,
156-
kind: String,
157-
) -> Result<String, JsValue> {
153+
pub fn add_many_modal_filters(&mut self, input: JsValue, kind: String) -> Result<(), JsValue> {
158154
let gj: Feature = serde_wasm_bindgen::from_value(input)?;
159155
let mut linestring: LineString = gj.try_into().map_err(err_to_js)?;
160156
self.map.mercator.to_mercator_in_place(&mut linestring);
@@ -164,22 +160,19 @@ impl LTN {
164160
&self.neighbourhood.as_ref().unwrap().interior_roads,
165161
FilterKind::from_string(&kind).unwrap(),
166162
);
167-
self.render_neighbourhood()
163+
Ok(())
168164
}
169165

170166
#[wasm_bindgen(js_name = deleteModalFilter)]
171-
pub fn delete_modal_filter(&mut self, road: usize) -> Result<String, JsValue> {
167+
pub fn delete_modal_filter(&mut self, road: usize) {
172168
self.map.delete_modal_filter(RoadID(road));
173-
self.render_neighbourhood()
174169
}
175170

176-
pub fn undo(&mut self) -> Result<String, JsValue> {
171+
pub fn undo(&mut self) {
177172
self.map.undo();
178-
self.render_neighbourhood()
179173
}
180-
pub fn redo(&mut self) -> Result<String, JsValue> {
174+
pub fn redo(&mut self) {
181175
self.map.redo();
182-
self.render_neighbourhood()
183176
}
184177

185178
#[wasm_bindgen(js_name = getShortcutsCrossingRoad)]

web/src/edit/NeighbourhoodMode.svelte

+13-8
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
let boundary: Feature<Polygon> | null;
2828
2929
let gjInput: FeatureCollection;
30-
render($app!.renderNeighbourhood());
30+
rerender();
3131
32-
function render(gjString: string) {
33-
gjInput = JSON.parse(gjString);
32+
function rerender() {
33+
gjInput = JSON.parse($app!.renderNeighbourhood());
3434
boundary = gjInput.features.find(
3535
(f) => f.properties!.kind == "boundary"
3636
)! as Feature<Polygon>;
@@ -50,7 +50,8 @@
5050
stopAddingFilter();
5151
});
5252
function onClick(e: MapMouseEvent) {
53-
render($app!.addModalFilter(e.lngLat, filterType));
53+
$app!.addModalFilter(e.lngLat, filterType);
54+
rerender();
5455
stopAddingFilter();
5556
}
5657
function stopAddingFilter() {
@@ -61,7 +62,8 @@
6162
6263
function deleteFilter(f: Feature) {
6364
if (f.properties!.kind == "modal_filter") {
64-
render($app!.deleteModalFilter(f.properties!.road));
65+
$app!.deleteModalFilter(f.properties!.road);
66+
rerender();
6567
}
6668
}
6769
@@ -77,10 +79,12 @@
7779
}
7880
}
7981
function undo() {
80-
render($app!.undo());
82+
$app!.undo();
83+
rerender();
8184
}
8285
function redo() {
83-
render($app!.redo());
86+
$app!.redo();
87+
rerender();
8488
}
8589
8690
function pickNewNeighbourhood() {
@@ -92,7 +96,8 @@
9296
function gotFreehandLine(e: CustomEvent<Feature<LineString> | null>) {
9397
let f = e.detail;
9498
if (f) {
95-
render($app!.addManyModalFilters(f, filterType));
99+
$app!.addManyModalFilters(f, filterType);
100+
rerender();
96101
}
97102
98103
addingMultipleFilters = false;

0 commit comments

Comments
 (0)