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

Don't throw front end exception when rendering boolean #62

Merged
merged 5 commits into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.13.2] - 2018-07-24
### Fixed
- Attempting to render a `Boolean` value to the page no longer crashes the app.

## [0.13.1] - 2018-07-18
### Fixed
- If a callback references an `id` which does not exist in the DOM tree at the time it is executed, throw an informative front-end exception (previously an uninformative front-end exception was thrown). https://github.com/plotly/dash-renderer/issues/57
Expand Down
4 changes: 2 additions & 2 deletions src/TreeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TreeContainer.propTypes = {
}

function render(component) {
if (R.contains(R.type(component), ['String', 'Number', 'Null'])) {
if (R.contains(R.type(component), ['String', 'Number', 'Null', 'Boolean'])) {
return component;
}

Expand All @@ -39,7 +39,7 @@ function render(component) {

} else if (R.contains(
R.type(component.props.children),
['String', 'Number', 'Null'])
['String', 'Number', 'Null', 'Boolean'])
) {

children = [component.props.children];
Expand Down
116 changes: 59 additions & 57 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,39 @@ def test_initial_state(self):
app.layout = html.Div([
'Basic string',
3.14,
True,
None,
html.Div('Child div with basic string',
id='p.c.3',
id='p.c.4',
className="my-class",
title='tooltip',
style={'color': 'red', 'fontSize': 30}
),
html.Div(id='p.c.4'),
html.Div(id='p.c.5'),
html.Div([
html.Div('Grandchild div', id='p.c.5.p.c.0'),
html.Div('Grandchild div', id='p.c.6.p.c.0'),
html.Div([
html.Div('Great grandchild', id='p.c.5.p.c.1.p.c.0'),
html.Div('Great grandchild', id='p.c.6.p.c.1.p.c.0'),
3.14159,
'another basic string'
], id='p.c.5.p.c.1'),
], id='p.c.6.p.c.1'),
html.Div([
html.Div(
html.Div([
html.Div([
html.Div(
id='p.c.5.p.c.2.p.c.0.p.c.p.c.0.p.c.0'
id='p.c.6.p.c.2.p.c.0.p.c.p.c.0.p.c.0'
),
'',
html.Div(
id='p.c.5.p.c.2.p.c.0.p.c.p.c.0.p.c.2'
id='p.c.6.p.c.2.p.c.0.p.c.p.c.0.p.c.2'
)
], id='p.c.5.p.c.2.p.c.0.p.c.p.c.0')
], id='p.c.5.p.c.2.p.c.0.p.c'),
id='p.c.5.p.c.2.p.c.0'
], id='p.c.6.p.c.2.p.c.0.p.c.p.c.0')
], id='p.c.6.p.c.2.p.c.0.p.c'),
id='p.c.6.p.c.2.p.c.0'
)
], id='p.c.5.p.c.2')
], id='p.c.5')
], id='p.c.6.p.c.2')
], id='p.c.6')
])

self.startServer(app)
Expand All @@ -122,16 +123,16 @@ def test_initial_state(self):
Child div with basic string
</div>

<div id="p.c.4">
<div id="p.c.5">
</div>

<div id="p.c.5">
<div id="p.c.5.p.c.0">
<div id="p.c.6">
<div id="p.c.6.p.c.0">
Grandchild div
</div>

<div id="p.c.5.p.c.1">
<div id="p.c.5.p.c.1.p.c.0">
<div id="p.c.6.p.c.1">
<div id="p.c.6.p.c.1.p.c.0">
Great grandchild
</div>

Expand All @@ -140,16 +141,16 @@ def test_initial_state(self):
another basic string
</div>

<div id="p.c.5.p.c.2">
<div id="p.c.5.p.c.2.p.c.0">
<div id="p.c.5.p.c.2.p.c.0.p.c">
<div id="p.c.5.p.c.2.p.c.0.p.c.p.c.0">
<div id="p.c.6.p.c.2">
<div id="p.c.6.p.c.2.p.c.0">
<div id="p.c.6.p.c.2.p.c.0.p.c">
<div id="p.c.6.p.c.2.p.c.0.p.c.p.c.0">

<div id="p.c.5.p.c.2.p.c.0.p.c.p.c.0.p.c.0">
<div id="p.c.6.p.c.2.p.c.0.p.c.p.c.0.p.c.0">
</div>


<div id="p.c.5.p.c.2.p.c.0.p.c.p.c.0.p.c.2">
<div id="p.c.6.p.c.2.p.c.0.p.c.p.c.0.p.c.2">
</div>

</div>
Expand All @@ -171,7 +172,7 @@ def test_initial_state(self):
'style="font-size: 30px; color: red;"'
]
permutations = itertools.permutations([
'id="p.c.3"',
'id="p.c.4"',
'class="my-class"',
'title="tooltip"',
], 3)
Expand Down Expand Up @@ -224,12 +225,13 @@ def test_initial_state(self):
"children": [
"Basic string",
3.14,
True,
None,
{
"namespace": "dash_html_components",
"props": {
"children": "Child div with basic string",
"id": "p.c.3",
"id": "p.c.4",
'className': "my-class",
'title': 'tooltip',
'style': {
Expand All @@ -242,7 +244,7 @@ def test_initial_state(self):
"namespace": "dash_html_components",
"props": {
"children": None,
"id": "p.c.4"
"id": "p.c.5"
},
"type": "Div"
},
Expand All @@ -254,7 +256,7 @@ def test_initial_state(self):
"namespace": "dash_html_components",
"props": {
"children": "Grandchild div",
"id": "p.c.5.p.c.0"
"id": "p.c.6.p.c.0"
},
"type": "Div"
},
Expand All @@ -266,14 +268,14 @@ def test_initial_state(self):
"namespace": "dash_html_components",
"props": {
"children": "Great grandchild",
"id": "p.c.5.p.c.1.p.c.0"
"id": "p.c.6.p.c.1.p.c.0"
},
"type": "Div"
},
3.14159,
"another basic string"
],
"id": "p.c.5.p.c.1"
"id": "p.c.6.p.c.1"
},
"type": "Div"
},
Expand All @@ -296,7 +298,7 @@ def test_initial_state(self):
"namespace": "dash_html_components",
"props": {
"children": None,
"id": "p.c.5.p.c.2.p.c.0.p.c.p.c.0.p.c.0"
"id": "p.c.6.p.c.2.p.c.0.p.c.p.c.0.p.c.0"
},
"type": "Div"
},
Expand All @@ -305,31 +307,31 @@ def test_initial_state(self):
"namespace": "dash_html_components",
"props": {
"children": None,
"id": "p.c.5.p.c.2.p.c.0.p.c.p.c.0.p.c.2"
"id": "p.c.6.p.c.2.p.c.0.p.c.p.c.0.p.c.2"
},
"type": "Div"
}
],
"id": "p.c.5.p.c.2.p.c.0.p.c.p.c.0"
"id": "p.c.6.p.c.2.p.c.0.p.c.p.c.0"
},
"type": "Div"
}
],
"id": "p.c.5.p.c.2.p.c.0.p.c"
"id": "p.c.6.p.c.2.p.c.0.p.c"
},
"type": "Div"
},
"id": "p.c.5.p.c.2.p.c.0"
"id": "p.c.6.p.c.2.p.c.0"
},
"type": "Div"
}
],
"id": "p.c.5.p.c.2"
"id": "p.c.6.p.c.2"
},
"type": "Div"
}
],
"id": "p.c.5"
"id": "p.c.6"
},
"type": "Div"
}
Expand Down Expand Up @@ -369,60 +371,60 @@ def test_initial_state(self):
'return window.store.getState().paths'
),
{
"p.c.3": [
"props", "children", 3
],
"p.c.4": [
"props", "children", 4
],
"p.c.5": [
"props", "children", 5
],
"p.c.5.p.c.0": [
"props", "children", 5,
"p.c.6": [
"props", "children", 6
],
"p.c.6.p.c.0": [
"props", "children", 6,
"props", "children", 0
],
"p.c.5.p.c.1": [
"props", "children", 5,
"p.c.6.p.c.1": [
"props", "children", 6,
"props", "children", 1
],
"p.c.5.p.c.1.p.c.0": [
"props", "children", 5,
"p.c.6.p.c.1.p.c.0": [
"props", "children", 6,
"props", "children", 1,
"props", "children", 0
],
"p.c.5.p.c.2": [
"props", "children", 5,
"p.c.6.p.c.2": [
"props", "children", 6,
"props", "children", 2
],
"p.c.5.p.c.2.p.c.0": [
"props", "children", 5,
"p.c.6.p.c.2.p.c.0": [
"props", "children", 6,
"props", "children", 2,
"props", "children", 0
],
"p.c.5.p.c.2.p.c.0.p.c": [
"props", "children", 5,
"p.c.6.p.c.2.p.c.0.p.c": [
"props", "children", 6,
"props", "children", 2,
"props", "children", 0,
"props", "children"
],
"p.c.5.p.c.2.p.c.0.p.c.p.c.0": [
"props", "children", 5,
"p.c.6.p.c.2.p.c.0.p.c.p.c.0": [
"props", "children", 6,
"props", "children", 2,
"props", "children", 0,
"props", "children",
"props", "children", 0
],
"p.c.5.p.c.2.p.c.0.p.c.p.c.0.p.c.0": [
"props", "children", 5,
"p.c.6.p.c.2.p.c.0.p.c.p.c.0.p.c.0": [
"props", "children", 6,
"props", "children", 2,
"props", "children", 0,
"props", "children",
"props", "children", 0,
"props", "children", 0
],
"p.c.5.p.c.2.p.c.0.p.c.p.c.0.p.c.2": [
"props", "children", 5,
"p.c.6.p.c.2.p.c.0.p.c.p.c.0.p.c.2": [
"props", "children", 6,
"props", "children", 2,
"props", "children", 0,
"props", "children",
Expand Down