Skip to content

Commit 2097c60

Browse files
committed
Iterate
1 parent 2a8ee8f commit 2097c60

2 files changed

Lines changed: 72 additions & 15 deletions

File tree

examples/simple-yjs-widget/notebooks/simple.ipynb

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"id": "2a245ed3-5838-4be6-ad5e-9fa75b9c7ab0",
77
"metadata": {},
88
"outputs": [],
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": null,
16+
"execution_count": 2,
1717
"id": "6d9538c9-4858-4c9d-b347-18965660115d",
1818
"metadata": {},
1919
"outputs": [],
@@ -31,7 +31,7 @@
3131
"\n",
3232
" @property\n",
3333
" def value(self):\n",
34-
" return self._state.get('value')\n",
34+
" return self._state['value']\n",
3535
"\n",
3636
" @value.setter\n",
3737
" def value(self, v):\n",
@@ -64,28 +64,55 @@
6464
},
6565
{
6666
"cell_type": "code",
67-
"execution_count": null,
67+
"execution_count": 3,
6868
"id": "8cfb218c-e6fe-48da-a6ee-599bfe524e15",
6969
"metadata": {},
70-
"outputs": [],
70+
"outputs": [
71+
{
72+
"data": {
73+
"application/vnd.jupyter.ywidget-view+json": {
74+
"model_id": "4a2524e43c7244d9b93aeb95383cdc85",
75+
"version_major": 2,
76+
"version_minor": 0
77+
},
78+
"text/plain": [
79+
"<__main__.MySlider object at 0x7fe44436af90>"
80+
]
81+
},
82+
"execution_count": 3,
83+
"metadata": {},
84+
"output_type": "execute_result"
85+
}
86+
],
7187
"source": [
7288
"w = MySlider()\n",
7389
"w"
7490
]
7591
},
7692
{
7793
"cell_type": "code",
78-
"execution_count": null,
94+
"execution_count": 4,
7995
"id": "9269a3f1-a061-478f-8728-7393a4aec2d0",
8096
"metadata": {},
81-
"outputs": [],
97+
"outputs": [
98+
{
99+
"data": {
100+
"text/plain": [
101+
"50.0"
102+
]
103+
},
104+
"execution_count": 4,
105+
"metadata": {},
106+
"output_type": "execute_result"
107+
}
108+
],
82109
"source": [
83110
"w.value"
84111
]
85112
},
86113
{
87114
"cell_type": "code",
88-
"execution_count": null,
115+
"execution_count": 5,
89116
"id": "8ac7ea5c-8315-44eb-aa62-f223f86d267d",
90117
"metadata": {},
91118
"outputs": [],
@@ -95,7 +122,7 @@
95122
},
96123
{
97124
"cell_type": "code",
98-
"execution_count": null,
125+
"execution_count": 6,
99126
"id": "bd2c92fb-9653-4de5-8a20-d463205f3a9e",
100127
"metadata": {},
101128
"outputs": [],
@@ -105,9 +132,30 @@
105132
},
106133
{
107134
"cell_type": "code",
108-
"execution_count": null,
135+
"execution_count": 7,
109136
"id": "3a5680c6-77ae-4f71-a982-b3447dcb4fd0",
110137
"metadata": {},
138+
"outputs": [
139+
{
140+
"data": {
141+
"text/plain": [
142+
"36.0"
143+
]
144+
},
145+
"execution_count": 7,
146+
"metadata": {},
147+
"output_type": "execute_result"
148+
}
149+
],
150+
"source": [
151+
"w.value"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"id": "839e129b-4040-4293-9287-abe4bfd5491d",
158+
"metadata": {},
111159
"outputs": [],
112160
"source": []
113161
}

examples/simple-yjs-widget/src/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,29 @@ class MySlider {
3030

3131
this._stateChanged();
3232

33+
this.slider.onchange = this._sliderChanged.bind(this);
34+
3335
node.appendChild(this.slider);
3436
}
3537

3638
_stateChanged(): void {
37-
this.slider.setAttribute('min', this.state.get('min'));
38-
this.slider.setAttribute('max', this.state.get('max'));
39-
this.slider.setAttribute('value', this.state.get('value'));
40-
this.slider.setAttribute('step', this.state.get('step'));
39+
this.slider.min = this.state.get('min');
40+
this.slider.max = this.state.get('max');
41+
this.slider.value = this.state.get('value');
42+
this.slider.step = this.state.get('step');
43+
}
44+
45+
_sliderChanged(): void {
46+
this.state.set('min', parseInt(this.slider.min ?? '0'));
47+
this.state.set('max', parseInt(this.slider.max ?? '100'));
48+
this.state.set('value', parseInt(this.slider.value ?? '50'));
49+
this.state.set('step', parseInt(this.slider.step ?? '1'));
4150
}
4251

4352
state: Y.Map<any>;
4453
yModel: IJupyterYModel;
4554
node: HTMLElement;
46-
slider: HTMLElement;
55+
slider: HTMLInputElement;
4756
}
4857

4958
const simple: JupyterFrontEndPlugin<void> = {

0 commit comments

Comments
 (0)