Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit b923e23

Browse files
authored
Merge pull request #333 from plotly/store-nested-data
Fix nested data for the Store component.
2 parents d004b29 + 5d81fb7 commit b923e23

9 files changed

+66
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log for dash-core-components
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
4+
5+
## [0.33.1] -- 2018-10-17
6+
### Fixed
7+
- Fix Store component nested data [#333](https://github.com/plotly/dash-core-components/pull/333)
8+
49
## [0.33.0] -- 2018-10-04
510
### Added
611

dash_core_components/dash_core_components.dev.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dash_core_components/dash_core_components.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_core_components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dash-core-components",
3-
"version": "0.33.0",
3+
"version": "0.33.1",
44
"description": "Core component suite for Dash",
55
"repository": {
66
"type": "git",
@@ -19,7 +19,7 @@
1919
"uninstall-local": "pip uninstall dash-core-components -y",
2020
"build:js": "webpack --mode production",
2121
"build:js-dev": "webpack --mode development",
22-
"build:py": "node ./extract-meta src/components > dash_core_components/metadata.json && cp package.json dash_core_components && npm run generate-python-classes",
22+
"build:py": "node ./extract-meta src/components > dash_core_components/metadata.json && copyfiles package.json dash_core_components && npm run generate-python-classes",
2323
"build:all": "npm run build:js && npm run build:py",
2424
"build:all-dev": "npm run build:js-dev && npm run build:py",
2525
"build:watch": "watch 'npm run build:all' src"

dash_core_components/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.33.0'
1+
__version__ = '0.33.1'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dash-core-components",
3-
"version": "0.33.0",
3+
"version": "0.33.1",
44
"description": "Core component suite for Dash",
55
"repository": {
66
"type": "git",

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tox
88
tox-pyenv
99
six
1010
plotly>=2.0.8
11+
urllib3<=1.22
1112
requests[security]
1213
ipdb
1314
dash-table-experiments

src/components/Store.react.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ function dataCheck(data, old) {
1313
return true;
1414
}
1515
for (let i = 0; i < data.length; i++) {
16-
if (data[i] !== old[i]) {
16+
if (dataCheck(data[i], old[i])) {
1717
return true;
1818
}
1919
}
2020
} else if (R.contains(type, ['String', 'Number'])) {
2121
return old !== data;
2222
} else if (type === 'Object') {
23-
return R.any(([k, v]) => old[k] !== v)(Object.entries(data));
23+
return R.any(([k, v]) => dataCheck(v, old[k]))(Object.entries(data));
2424
}
2525
return false;
2626
}

test/test_integration.py

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,19 +1173,19 @@ def test_storage_component(self):
11731173

11741174
app.layout = html.Div([
11751175
dcc.Store(id='storage',
1176-
storage_type='local'),
1176+
storage_type='local'),
11771177
html.Button('click me', id='btn'),
11781178
html.Button('clear', id='clear-btn'),
11791179
html.Button('set-init-storage',
11801180
id='set-init-storage'),
11811181
dcc.Store(id='dummy',
1182-
storage_type='session',
1183-
data=dummy_data),
1182+
storage_type='session',
1183+
data=dummy_data),
11841184
dcc.Store(id='memory',
1185-
storage_type='memory'),
1185+
storage_type='memory'),
11861186
html.Div(id='memory-output'),
11871187
dcc.Store(id='initial-storage',
1188-
storage_type='session'),
1188+
storage_type='session'),
11891189
html.Div(id='init-output')
11901190
])
11911191

@@ -1269,3 +1269,50 @@ def init_output(ts, data):
12691269
self.assertAlmostEqual(ts, init.get('ts'), delta=1000)
12701270
self.assertEqual('initialized', init.get('data'))
12711271

1272+
def test_store_nested_data(self):
1273+
app = dash.Dash(__name__)
1274+
1275+
nested = {'nested': {'nest': 'much'}}
1276+
nested_list = dict(my_list=[1, 2, 3])
1277+
1278+
app.layout = html.Div([
1279+
dcc.Store(id='store', storage_type='local'),
1280+
html.Button('set object as key', id='obj-btn'),
1281+
html.Button('set list as key', id='list-btn'),
1282+
html.Output(id='output')
1283+
])
1284+
1285+
@app.callback(Output('store', 'data'),
1286+
[Input('obj-btn', 'n_clicks_timestamp'),
1287+
Input('list-btn', 'n_clicks_timestamp')])
1288+
def on_obj_click(obj_ts, list_ts):
1289+
if obj_ts is None and list_ts is None:
1290+
raise PreventUpdate
1291+
1292+
# python 3 got the default props bug. plotly/dash#396
1293+
if (obj_ts and not list_ts) or obj_ts > list_ts:
1294+
return nested
1295+
else:
1296+
return nested_list
1297+
1298+
@app.callback(Output('output', 'children'),
1299+
[Input('store', 'modified_timestamp')],
1300+
[State('store', 'data')])
1301+
def on_ts(ts, data):
1302+
if ts is None:
1303+
raise PreventUpdate
1304+
return json.dumps(data)
1305+
1306+
self.startServer(app)
1307+
1308+
obj_btn = self.wait_for_element_by_css_selector('#obj-btn')
1309+
list_btn = self.wait_for_element_by_css_selector('#list-btn')
1310+
1311+
obj_btn.click()
1312+
time.sleep(3)
1313+
self.wait_for_text_to_equal('#output', json.dumps(nested))
1314+
# it would of crashed the app before adding the recursive check.
1315+
1316+
list_btn.click()
1317+
time.sleep(3)
1318+
self.wait_for_text_to_equal('#output', json.dumps(nested_list))

0 commit comments

Comments
 (0)