Skip to content

Commit

Permalink
fix js unique id
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Nov 19, 2024
1 parent eb10ca0 commit 9e953a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 58 deletions.
67 changes: 13 additions & 54 deletions example/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "5df2c405",
"metadata": {},
"outputs": [],
Expand All @@ -25,33 +25,19 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "e74c9c9e",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "80b8268cbfe0416494f266f6f8a19aa1",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"WidgetCodeInput(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"w"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "4d389a14",
"metadata": {},
"outputs": [],
Expand All @@ -61,28 +47,17 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "2fc2b3ed",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"my_function(1, 2)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "e90010bd",
"metadata": {},
"outputs": [],
Expand All @@ -92,26 +67,10 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "75900629",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9238263cacc04a728e878c13d8fac749",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"WidgetCodeInput(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"w2 = WidgetCodeInput(\n",
" function_name = \"my_function\",\n",
Expand Down Expand Up @@ -142,7 +101,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.15"
}
},
"nbformat": 4,
Expand Down
15 changes: 11 additions & 4 deletions js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ import { nord } from 'cm6-theme-nord'
import { solarizedLight } from 'cm6-theme-solarized-light'
import { basicLight } from 'cm6-theme-basic-light'
import './widget.css';

function generateRandomString(length) {
let result = "";
while (result.length < length) {
result += Math.random().toString(36).substring(2);
}
return result.substring(0, length);
}


export default{
initialize({ model }) {
// /* (optional) model initialization logic */

},


/** @param {{ model: DOMWidgetModel, el: HTMLElement }} context */

render({model,el}) {



var unique_funcbody_id = model.get('widget_instance_count_trait')
var unique_funcbody_id = generateRandomString(6)


model.attributes={function_body_id:unique_funcbody_id}
Expand Down

0 comments on commit 9e953a6

Please sign in to comment.