Skip to content

Commit 6141921

Browse files
authored
Bump anywidget to 0.9 & simplify Wasm initialization (#344)
1 parent 2ba95c9 commit 6141921

File tree

7 files changed

+530
-526
lines changed

7 files changed

+530
-526
lines changed

DEVELOP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ poetry run python -m ipykernel install --user --name "lonboard"
3333
JupyterLab is an included dev dependency, so to start JupyterLab you can run
3434

3535
```
36-
poetry run jupyter lab
36+
ANYWIDGET_HMR=1 poetry run jupyter lab
3737
```
3838

3939
Then you should see a tile on the home screen that lets you open a Jupyter Notebook in the `lonboard` environment. You should also be able to open up an example notebook from the `examples/` folder.

package-lock.json

Lines changed: 35 additions & 94 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"@anywidget/react": "^0.0.2",
3+
"@anywidget/react": "^0.0.3",
44
"@babel/runtime": "^7.23.8",
55
"@deck.gl/core": "^8.9.33",
66
"@deck.gl/extensions": "^8.9.33",
@@ -17,6 +17,7 @@
1717
},
1818
"type": "module",
1919
"devDependencies": {
20+
"@anywidget/types": "^0.1.5",
2021
"@jupyter-widgets/base": "^6.0.6",
2122
"@types/react": "^18.2.47",
2223
"@types/uuid": "^9.0.7",

poetry.lock

Lines changed: 478 additions & 401 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include = ["lonboard/static/*.js", "lonboard/static/*.css"]
1010

1111
[tool.poetry.dependencies]
1212
python = "^3.8"
13-
anywidget = "^0.7.1"
13+
anywidget = "^0.9.0"
1414
pyarrow = ">=14.0.1"
1515
geopandas = ">=0.13"
1616
pandas = "^2"

src/index.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as React from "react";
22
import { useState, useEffect } from "react";
33
import { createRender, useModelState, useModel } from "@anywidget/react";
4+
import type { Initialize, InitializeProps, Render } from "@anywidget/types";
45
import Map from "react-map-gl/maplibre";
56
import DeckGL from "@deck.gl/react/typed";
67
import type { Layer } from "@deck.gl/core/typed";
78
import { BaseLayerModel, initializeLayer } from "./model/index.js";
89
import type { WidgetModel } from "@jupyter-widgets/base";
9-
import { useParquetWasm } from "./parquet.js";
10+
import { initParquetWasm } from "./parquet.js";
1011
import { getTooltip } from "./tooltip/index.js";
1112
import { loadChildModels } from "./util.js";
1213
import { v4 as uuidv4 } from "uuid";
@@ -57,7 +58,6 @@ async function getChildModelState(
5758
}
5859

5960
function App() {
60-
let [parquetWasmReady] = useParquetWasm();
6161
let [initialViewState] = useModelState<DataView>("_initial_view_state");
6262
let [mapStyle] = useModelState<string>("basemap_style");
6363
let [mapHeight] = useModelState<number>("_height");
@@ -75,15 +75,7 @@ function App() {
7575
let [stateCounter, setStateCounter] = useState<Date>(new Date());
7676

7777
useEffect(() => {
78-
if (!parquetWasmReady) {
79-
return;
80-
}
81-
8278
const callback = async () => {
83-
if (!parquetWasmReady) {
84-
throw new Error("inside callback but parquetWasm not ready!");
85-
}
86-
8779
const childModels = await loadChildModels(
8880
model.widget_manager,
8981
childLayerIds,
@@ -97,7 +89,7 @@ function App() {
9789
setSubModelState(newSubModelState);
9890
};
9991
callback().catch(console.error);
100-
}, [parquetWasmReady, childLayerIds]);
92+
}, [childLayerIds]);
10193

10294
const layers: Layer[] = [];
10395
for (const subModel of Object.values(subModelState)) {
@@ -147,4 +139,13 @@ function App() {
147139
);
148140
}
149141

150-
export let render = createRender(App);
142+
async function initialize({}: InitializeProps) {
143+
await initParquetWasm();
144+
}
145+
146+
const module: { render: Render; initialize: Initialize } = {
147+
render: createRender(App),
148+
initialize,
149+
};
150+
151+
export default module;

src/parquet.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,3 @@ export function parseParquetBuffers(dataViews: DataView[]): arrow.Table {
5858

5959
return new arrow.Table(batches);
6060
}
61-
62-
export function useParquetWasm(): [boolean] {
63-
const [wasmReady, setWasmReady] = useState<boolean>(false);
64-
65-
// Init parquet wasm
66-
useEffect(() => {
67-
const callback = async () => {
68-
await initParquetWasm();
69-
setWasmReady(true);
70-
};
71-
72-
callback();
73-
}, []);
74-
75-
return [wasmReady];
76-
}

0 commit comments

Comments
 (0)