Skip to content

Commit 9e953a6

Browse files
committed
fix js unique id
1 parent eb10ca0 commit 9e953a6

File tree

2 files changed

+24
-58
lines changed

2 files changed

+24
-58
lines changed

example/example.ipynb

+13-54
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": null,
66
"id": "5df2c405",
77
"metadata": {},
88
"outputs": [],
@@ -25,33 +25,19 @@
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 2,
28+
"execution_count": null,
2929
"id": "e74c9c9e",
30-
"metadata": {},
31-
"outputs": [
32-
{
33-
"data": {
34-
"application/vnd.jupyter.widget-view+json": {
35-
"model_id": "80b8268cbfe0416494f266f6f8a19aa1",
36-
"version_major": 2,
37-
"version_minor": 1
38-
},
39-
"text/plain": [
40-
"WidgetCodeInput(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…"
41-
]
42-
},
43-
"execution_count": 2,
44-
"metadata": {},
45-
"output_type": "execute_result"
46-
}
47-
],
30+
"metadata": {
31+
"scrolled": true
32+
},
33+
"outputs": [],
4834
"source": [
4935
"w"
5036
]
5137
},
5238
{
5339
"cell_type": "code",
54-
"execution_count": 3,
40+
"execution_count": null,
5541
"id": "4d389a14",
5642
"metadata": {},
5743
"outputs": [],
@@ -61,28 +47,17 @@
6147
},
6248
{
6349
"cell_type": "code",
64-
"execution_count": 4,
50+
"execution_count": null,
6551
"id": "2fc2b3ed",
6652
"metadata": {},
67-
"outputs": [
68-
{
69-
"data": {
70-
"text/plain": [
71-
"3"
72-
]
73-
},
74-
"execution_count": 4,
75-
"metadata": {},
76-
"output_type": "execute_result"
77-
}
78-
],
53+
"outputs": [],
7954
"source": [
8055
"my_function(1, 2)"
8156
]
8257
},
8358
{
8459
"cell_type": "code",
85-
"execution_count": 5,
60+
"execution_count": null,
8661
"id": "e90010bd",
8762
"metadata": {},
8863
"outputs": [],
@@ -92,26 +67,10 @@
9267
},
9368
{
9469
"cell_type": "code",
95-
"execution_count": 6,
70+
"execution_count": null,
9671
"id": "75900629",
9772
"metadata": {},
98-
"outputs": [
99-
{
100-
"data": {
101-
"application/vnd.jupyter.widget-view+json": {
102-
"model_id": "9238263cacc04a728e878c13d8fac749",
103-
"version_major": 2,
104-
"version_minor": 1
105-
},
106-
"text/plain": [
107-
"WidgetCodeInput(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…"
108-
]
109-
},
110-
"execution_count": 6,
111-
"metadata": {},
112-
"output_type": "execute_result"
113-
}
114-
],
73+
"outputs": [],
11574
"source": [
11675
"w2 = WidgetCodeInput(\n",
11776
" function_name = \"my_function\",\n",
@@ -142,7 +101,7 @@
142101
"name": "python",
143102
"nbconvert_exporter": "python",
144103
"pygments_lexer": "ipython3",
145-
"version": "3.10.12"
104+
"version": "3.10.15"
146105
}
147106
},
148107
"nbformat": 4,

js/widget.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,27 @@ import { nord } from 'cm6-theme-nord'
1313
import { solarizedLight } from 'cm6-theme-solarized-light'
1414
import { basicLight } from 'cm6-theme-basic-light'
1515
import './widget.css';
16+
17+
function generateRandomString(length) {
18+
let result = "";
19+
while (result.length < length) {
20+
result += Math.random().toString(36).substring(2);
21+
}
22+
return result.substring(0, length);
23+
}
24+
25+
1626
export default{
1727
initialize({ model }) {
1828
// /* (optional) model initialization logic */
1929

2030
},
2131

22-
2332
/** @param {{ model: DOMWidgetModel, el: HTMLElement }} context */
2433

2534
render({model,el}) {
2635

27-
28-
29-
var unique_funcbody_id = model.get('widget_instance_count_trait')
36+
var unique_funcbody_id = generateRandomString(6)
3037

3138

3239
model.attributes={function_body_id:unique_funcbody_id}

0 commit comments

Comments
 (0)