Skip to content

Commit 3d2acc5

Browse files
authored
Merge pull request #550 from plotly/no-events
Remove events
2 parents 8e62b13 + 55b8d13 commit 3d2acc5

16 files changed

+107
-195
lines changed

Diff for: .circleci/config.yml

+2-15
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,12 @@ jobs:
3535
paths:
3636
- "venv"
3737

38-
- run:
39-
name: Run lint
40-
command: |
41-
. venv/bin/activate
42-
pylint dash setup.py --rcfile=$PYLINTRC
43-
pylint tests -d all -e C0410,C0411,C0412,C0413,W0109
44-
flake8 dash setup.py
45-
flake8 --ignore=E123,E126,E501,E722,E731,F401,F841,W503,W504 --exclude=metadata_test.py tests
46-
4738
- run:
4839
name: Run tests
4940
command: |
5041
. venv/bin/activate
5142
python --version
52-
python -m unittest tests.development.test_base_component
53-
python -m unittest tests.development.test_component_loader
54-
python -m unittest tests.test_integration
55-
python -m unittest tests.test_resources
56-
python -m unittest tests.test_configs
43+
./test.sh
5744
5845
"python-3.6":
5946
<<: *test-template
@@ -80,4 +67,4 @@ workflows:
8067
jobs:
8168
- "python-2.7"
8269
- "python-3.6"
83-
- "python-3.7"
70+
- "python-3.7"

Diff for: .circleci/requirements/dev-requirements-py37.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dash_core_components>=0.40.2
22
dash_html_components==0.12.0rc3
33
dash-flow-example==0.0.3
44
dash-dangerously-set-inner-html
5-
dash_renderer
5+
git+git://github.com/plotly/dash-renderer@master#egg=dash_renderer
66
percy
77
selenium
88
mock

Diff for: .circleci/requirements/dev-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dash_core_components>=0.40.2
22
dash_html_components>=0.12.0rc3
33
dash_flow_example==0.0.3
44
dash-dangerously-set-inner-html
5-
dash_renderer
5+
git+git://github.com/plotly/dash-renderer@master#egg=dash_renderer
66
percy
77
selenium
88
mock

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased
2+
## Removed
3+
- Removed support for `Event` system. Use event properties instead, for example the `n_clicks` property instead of the `click` event, see [#531](https://github.com/plotly/dash/issues/531) for details. `dash_renderer` MUST be upgraded to >=0.17.0 together with this, and it is recommended to update `dash_core_components` to >=0.43.0 and `dash_html_components` to >=0.14.0. [#550](https://github.com/plotly/dash/pull/550)
4+
15
## [0.35.3] - 2019-01-23
26
## Fixed
37
- Asset blueprint takes routes prefix into it's static path. [#547](https://github.com/plotly/dash/pull/547)

Diff for: dash/dash.py

+17-34
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515

1616
from functools import wraps
1717

18-
import plotly
19-
import dash_renderer
2018
import flask
2119
from flask import Flask, Response
2220
from flask_compress import Compress
2321

24-
from .dependencies import Event, Input, Output, State
22+
import plotly
23+
import dash_renderer
24+
25+
from .dependencies import Input, Output, State
2526
from .resources import Scripts, Css
2627
from .development.base_component import Component
2728
from . import exceptions
@@ -622,7 +623,6 @@ def dependencies(self):
622623
},
623624
'inputs': v['inputs'],
624625
'state': v['state'],
625-
'events': v['events']
626626
} for k, v in self.callback_map.items()
627627
])
628628

@@ -633,7 +633,7 @@ def react(self, *args, **kwargs):
633633
'Use `callback` instead. `callback` has a new syntax too, '
634634
'so make sure to call `help(app.callback)` to learn more.')
635635

636-
def _validate_callback(self, output, inputs, state, events):
636+
def _validate_callback(self, output, inputs, state):
637637
# pylint: disable=too-many-branches
638638
layout = self._cached_layout or self._layout_value()
639639

@@ -652,8 +652,7 @@ def _validate_callback(self, output, inputs, state, events):
652652

653653
for args, obj, name in [([output], Output, 'Output'),
654654
(inputs, Input, 'Input'),
655-
(state, State, 'State'),
656-
(events, Event, 'Event')]:
655+
(state, State, 'State')]:
657656

658657
if not isinstance(args, list):
659658
raise exceptions.IncorrectTypeException(
@@ -721,32 +720,20 @@ def _validate_callback(self, output, inputs, state, events):
721720
component.available_properties).replace(
722721
' ', ''))
723722

724-
if (hasattr(arg, 'component_event') and
725-
arg.component_event not in
726-
component.available_events):
723+
if hasattr(arg, 'component_event'):
727724
raise exceptions.NonExistentEventException('''
728-
Attempting to assign a callback with
729-
the event "{}" but the component
730-
"{}" doesn't have "{}" as an event.\n
731-
Here is a list of the available events in "{}":
732-
{}
733-
'''.format(
734-
arg.component_event,
735-
arg.component_id,
736-
arg.component_event,
737-
arg.component_id,
738-
component.available_events).replace(' ', ''))
725+
Events have been removed.
726+
Use the associated property instead.
727+
''')
739728

740-
if state and not events and not inputs:
741-
raise exceptions.MissingEventsException('''
729+
if state and not inputs:
730+
raise exceptions.MissingInputsException('''
742731
This callback has {} `State` {}
743-
but no `Input` elements or `Event` elements.\n
744-
Without `Input` or `Event` elements, this callback
732+
but no `Input` elements.\n
733+
Without `Input` elements, this callback
745734
will never get called.\n
746735
(Subscribing to input components will cause the
747-
callback to be called whenever their values
748-
change and subscribing to an event will cause the
749-
callback to be called whenever the event is fired.)
736+
callback to be called whenever their values change.)
750737
'''.format(
751738
len(state),
752739
'elements' if len(state) > 1 else 'element'
@@ -888,8 +875,8 @@ def _validate_value(val, index=None):
888875
# TODO - Check this map for recursive or other ill-defined non-tree
889876
# relationships
890877
# pylint: disable=dangerous-default-value
891-
def callback(self, output, inputs=[], state=[], events=[]):
892-
self._validate_callback(output, inputs, state, events)
878+
def callback(self, output, inputs=[], state=[]):
879+
self._validate_callback(output, inputs, state)
893880

894881
callback_id = '{}.{}'.format(
895882
output.component_id, output.component_property
@@ -902,10 +889,6 @@ def callback(self, output, inputs=[], state=[], events=[]):
902889
'state': [
903890
{'id': c.component_id, 'property': c.component_property}
904891
for c in state
905-
],
906-
'events': [
907-
{'id': c.component_id, 'event': c.component_event}
908-
for c in events
909892
]
910893
}
911894

Diff for: dash/dependencies.py

-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,3 @@ class State:
1717
def __init__(self, component_id, component_property):
1818
self.component_id = component_id
1919
self.component_property = component_property
20-
21-
22-
# pylint: disable=old-style-class, too-few-public-methods
23-
class Event:
24-
def __init__(self, component_id, component_event):
25-
self.component_id = component_id
26-
self.component_event = component_event

Diff for: dash/development/_py_components_generation.py

+18-32
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44

55
from dash.development.base_component import _explicitize_args
6+
from dash.exceptions import NonExistentEventException
67
from ._all_keywords import python_keywords
78
from .base_component import Component
89

@@ -27,8 +28,7 @@ def generate_class_string(typename, props, description, namespace):
2728
string
2829
2930
"""
30-
# TODO _prop_names, _type, _namespace, available_events,
31-
# and available_properties
31+
# TODO _prop_names, _type, _namespace, and available_properties
3232
# can be modified by a Dash JS developer via setattr
3333
# TODO - Tab out the repr for the repr of these components to make it
3434
# look more like a hierarchical tree
@@ -52,7 +52,6 @@ def __init__(self, {default_argtext}):
5252
self._namespace = '{namespace}'
5353
self._valid_wildcard_attributes =\
5454
{list_of_valid_wildcard_attr_prefixes}
55-
self.available_events = {events}
5655
self.available_properties = {list_of_valid_keys}
5756
self.available_wildcard_properties =\
5857
{list_of_valid_wildcard_attr_prefixes}
@@ -101,11 +100,11 @@ def __repr__(self):
101100
docstring = create_docstring(
102101
component_name=typename,
103102
props=filtered_props,
104-
events=parse_events(props),
105103
description=description).replace('\r\n', '\n')
106104

105+
prohibit_events(props)
106+
107107
# pylint: disable=unused-variable
108-
events = '[' + ', '.join(parse_events(props)) + ']'
109108
prop_keys = list(props.keys())
110109
if 'children' in props:
111110
prop_keys.remove('children')
@@ -122,7 +121,7 @@ def __repr__(self):
122121
for p in prop_keys
123122
if not p.endswith("-*") and
124123
p not in python_keywords and
125-
p not in ['dashEvents', 'fireEvent', 'setProps']] + ['**kwargs']
124+
p != 'setProps'] + ['**kwargs']
126125
)
127126

128127
required_args = required_props(props)
@@ -233,7 +232,7 @@ def required_props(props):
233232
if prop['required']]
234233

235234

236-
def create_docstring(component_name, props, events, description):
235+
def create_docstring(component_name, props, description):
237236
"""
238237
Create the Dash component docstring
239238
@@ -243,8 +242,6 @@ def create_docstring(component_name, props, events, description):
243242
Component name
244243
props: dict
245244
Dictionary with {propName: propMetadata} structure
246-
events: list
247-
List of Dash events
248245
description: str
249246
Component description
250247
@@ -259,9 +256,7 @@ def create_docstring(component_name, props, events, description):
259256
return (
260257
"""A {name} component.\n{description}
261258
262-
Keyword arguments:\n{args}
263-
264-
Available events: {events}"""
259+
Keyword arguments:\n{args}"""
265260
).format(
266261
name=component_name,
267262
description=description,
@@ -274,30 +269,26 @@ def create_docstring(component_name, props, events, description):
274269
description=prop['description'],
275270
indent_num=0,
276271
is_flow_type='flowType' in prop and 'type' not in prop)
277-
for p, prop in list(filter_props(props).items())),
278-
events=', '.join(events))
272+
for p, prop in list(filter_props(props).items())))
279273

280274

281-
def parse_events(props):
275+
def prohibit_events(props):
282276
"""
283-
Pull out the dashEvents from the Component props
277+
Events have been removed. Raise an error if we see dashEvents or fireEvents
284278
285279
Parameters
286280
----------
287281
props: dict
288282
Dictionary with {propName: propMetadata} structure
289283
290-
Returns
284+
Raises
291285
-------
292-
list
293-
List of Dash event strings
286+
?
294287
"""
295-
if 'dashEvents' in props and props['dashEvents']['type']['name'] == 'enum':
296-
events = [v['value'] for v in props['dashEvents']['type']['value']]
297-
else:
298-
events = []
299-
300-
return events
288+
if 'dashEvents' in props or 'fireEvents' in props:
289+
raise NonExistentEventException(
290+
'Events are no longer supported by dash. Use properties instead, '
291+
'eg `n_clicks` instead of a `click` event.')
301292

302293

303294
def parse_wildcards(props):
@@ -349,7 +340,6 @@ def filter_props(props):
349340
Filter props from the Component arguments to exclude:
350341
- Those without a "type" or a "flowType" field
351342
- Those with arg.type.name in {'func', 'symbol', 'instanceOf'}
352-
- dashEvents as a name
353343
354344
Parameters
355345
----------
@@ -415,10 +405,6 @@ def filter_props(props):
415405
else:
416406
raise ValueError
417407

418-
# dashEvents are a special oneOf property that is used for subscribing
419-
# to events but it's never set as a property
420-
if arg_name in ['dashEvents']:
421-
filtered_props.pop(arg_name)
422408
return filtered_props
423409

424410

@@ -518,7 +504,7 @@ def map_js_to_py_types_prop_types(type_object):
518504
', '.join(
519505
"'{}'".format(t)
520506
for t in list(type_object['value'].keys())),
521-
'Those keys have the following types: \n{}'.format(
507+
'Those keys have the following types:\n{}'.format(
522508
'\n'.join(create_prop_docstring(
523509
prop_name=prop_name,
524510
type_object=prop,
@@ -561,7 +547,7 @@ def map_js_to_py_types_flow_types(type_object):
561547
signature=lambda indent_num: 'dict containing keys {}.\n{}'.format(
562548
', '.join("'{}'".format(d['key'])
563549
for d in type_object['signature']['properties']),
564-
'{}Those keys have the following types: \n{}'.format(
550+
'{}Those keys have the following types:\n{}'.format(
565551
' ' * indent_num,
566552
'\n'.join(
567553
create_prop_docstring(

Diff for: dash/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class IncorrectTypeException(CallbackException):
3030
pass
3131

3232

33-
class MissingEventsException(CallbackException):
33+
class MissingInputsException(CallbackException):
3434
pass
3535

3636

Diff for: dash/extract-meta.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const componentPaths = process.argv.slice(3);
88
const ignorePattern = new RegExp(process.argv[2]);
99

1010
const excludedDocProps = [
11-
'setProps', 'id', 'className', 'style', 'dashEvents', 'fireEvent'
11+
'setProps', 'id', 'className', 'style'
1212
];
1313

1414
if (!componentPaths.length) {

Diff for: test.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
EXIT_STATE=0
2+
3+
python -m unittest tests.development.test_base_component || EXIT_STATE=$?
4+
python -m unittest tests.development.test_component_loader || EXIT_STATE=$?
5+
python -m unittest tests.test_integration || EXIT_STATE=$?
6+
python -m unittest tests.test_resources || EXIT_STATE=$?
7+
python -m unittest tests.test_configs || EXIT_STATE=$?
8+
9+
pylint dash setup.py --rcfile=$PYLINTRC || EXIT_STATE=$?
10+
pylint tests -d all -e C0410,C0411,C0412,C0413,W0109 || EXIT_STATE=$?
11+
flake8 dash setup.py || EXIT_STATE=$?
12+
flake8 --ignore=E123,E126,E501,E722,E731,F401,F841,W503,W504 --exclude=metadata_test.py tests || EXIT_STATE=$?
13+
14+
if [ $EXIT_STATE -ne 0 ]; then
15+
echo "One or more tests failed"
16+
else
17+
echo "All tests passed!"
18+
fi
19+
20+
exit $EXIT_STATE

Diff for: tests/development/TestReactComponent.react.js

-10
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,9 @@ ReactComponent.propTypes = {
9191
}
9292
}),
9393

94-
// special dash events
95-
9694
children: React.PropTypes.node,
9795

9896
id: React.PropTypes.string,
99-
100-
101-
// dashEvents is a special prop that is used to events validation
102-
dashEvents: React.PropTypes.oneOf([
103-
'restyle',
104-
'relayout',
105-
'click'
106-
])
10797
};
10898

10999
ReactComponent.defaultProps = {

0 commit comments

Comments
 (0)