Skip to content

Commit 1faf5e6

Browse files
committed
adjusting setProps.ts -> clientsideFunctions.ts and adding test for using setProps
1 parent 9f5ac40 commit 1faf5e6

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

dash/dash-renderer/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {DashRenderer} from './DashRenderer';
2-
import './utils/setProps';
2+
import './utils/clientsideFunctions';
33

44
// make DashRenderer globally available
55
window.DashRenderer = DashRenderer;

dash/dash-renderer/src/utils/setProps.ts renamed to dash/dash-renderer/src/utils/clientsideFunctions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import {updateProps, notifyObservers} from '../actions/index';
22
import {getPath} from '../actions/paths';
33

4-
const setProps = (updates: {}) => {
4+
const setProps = (updates: []) => {
55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
66
// @ts-ignore
77
const ds = (window.dash_stores = window.dash_stores || []);
88
for (let y = 0; y < ds.length; y++) {
99
const {dispatch, getState} = ds[y];
1010
const {paths} = getState();
11-
Object.entries(updates).forEach(([componentId, props]) => {
12-
const componentPath = getPath(paths, componentId);
11+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
12+
// @ts-ignore
13+
updates.forEach(({id, ...props}) => {
14+
const componentPath = getPath(paths, id);
1315
dispatch(
1416
updateProps({
1517
props,
1618
itempath: componentPath
1719
})
1820
);
19-
dispatch(notifyObservers({id: componentId, props}));
21+
dispatch(notifyObservers({id, props}));
2022
});
2123
}
2224
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"private::initialize.renderer": "cd dash/dash-renderer && npm ci",
99
"private::cibuild.components": "python dash/development/update_components.py 'all' --ci True",
1010
"private::build.components": "python dash/development/update_components.py 'all'",
11-
"private::cibuild.renderer": "cd dash/dash-renderer && renderer build && sh renderer-test.sh",
12-
"private::build.renderer": "cd dash/dash-renderer && renderer build && sh renderer-test.sh",
11+
"private::cibuild.renderer": "cd dash/dash-renderer && rimraf build/dash_renderer.min.js && renderer build && sh renderer-test.sh",
12+
"private::build.renderer": "cd dash/dash-renderer && rimraf build/dash_renderer.min.js && renderer build && sh renderer-test.sh",
1313
"private::build.jupyterlab": "cd @plotly/dash-jupyterlab && jlpm install && jlpm build:pack",
1414
"private::lint.black": "node -e \"if ((process.env.PYVERSION || 'python312') !== 'python38'){process.exit(1)} \" || black dash tests --exclude metadata_test.py --check",
1515
"private::lint.flake8": "flake8 --exclude=metadata_test.py dash tests",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from dash import *
2+
import json
3+
from multiprocessing import Value
4+
import time
5+
6+
def test_sp001_clientside_setprops(dash_duo):
7+
8+
call_count = Value("i", 0)
9+
10+
app = Dash(__name__)
11+
12+
ids = [{'id': {'index': '1', 'type': 'test'}, 'children': ['rawr']}, {'id': 'two', 'children': 'this is a test'}, {'id': 'three', 'children': 'i see trees of green'}]
13+
14+
app.layout = html.Div([*[html.Div(id=x['id']) for x in ids], html.Div(id='four'), html.Button(id='setup', children='test setprops')])
15+
16+
app.clientside_callback(
17+
"""
18+
() => {
19+
window.dash_clientside.setProps(""" + json.dumps(ids) + """)
20+
return window.dash_clientside.no_update
21+
}
22+
""",
23+
Output('setup', 'id'),
24+
Input('setup', 'n_clicks'),
25+
prevent_initial_call=True
26+
)
27+
28+
for x in ids:
29+
@app.callback(Output(x['id'],'id', allow_duplicate=True), Output('four','children', allow_duplicate=True), Input(x['id'], 'children'),
30+
State(x['id'], 'id'), prevent_initial_call=True)
31+
def prinout(c, id):
32+
call_count.value += 1
33+
for y in ids:
34+
if y['id'] == id:
35+
assert y['children'] == c
36+
return no_update, call_count.value
37+
38+
dash_duo.start_server(app)
39+
40+
dash_duo.wait_for_text_to_equal("#setup", 'test setprops')
41+
dash_duo.find_element("#setup").click()
42+
time.sleep(1)
43+
dash_duo.wait_for_text_to_equal("#two", 'this is a test')
44+
dash_duo.wait_for_text_to_equal("#three", 'i see trees of green')
45+
dash_duo.wait_for_text_to_equal("#four", '3')

0 commit comments

Comments
 (0)