Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove excessive calls to layout() #128

Merged
merged 3 commits into from
Sep 7, 2017
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.18.1 - 2017-09-07
## Fixed
- 🐛 If `app.layout` was supplied a function, then it used to be called excessively. Now it is called just once on startup and just once on page load. https://github.com/plotly/dash/pull/128

0.18.0 - 2017-09-07
## Changed
- 🔒 Removes the `/static/` folder and endpoint that is implicitly initialized by flask. This is too implicit for my comfort level: I worry that users will not be aware that their files in their `static` folder are accessible
Expand All @@ -13,7 +17,7 @@
- ✏️ Fix a typo in an exception
- 🔧 Replaced all illegal characters in environment variable

## Maintenance
##🔧 Maintenance
- 📝 Update README.md
- ✅ Fix CircleCI tests. Note that the the [`dash-renderer`](https://github.com/plotly/dash-renderer) contains the bulk of the integration tests.
- 💄 Flake8 fixes and tests (fixes #99 )
Expand Down
15 changes: 10 additions & 5 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __init__(
self.server.before_first_request(self._setup_server)

self._layout = None
self._cached_layout = None
self.routes = []

class config:
Expand All @@ -119,9 +120,10 @@ def layout(self):

def _layout_value(self):
if isinstance(self._layout, collections.Callable):
return self._layout()
self._cached_layout = self._layout()
else:
return self._layout
self._cached_layout = self._layout
return self._cached_layout

@layout.setter
def layout(self, value):
Expand All @@ -134,8 +136,10 @@ def layout(self, value):
'a dash component.')

self._layout = value
self.css._update_layout(value)
self.scripts._update_layout(value)

layout_value = self._layout_value()
self.css._update_layout(layout_value)
self.scripts._update_layout(layout_value)
self._collect_and_register_resources(
self.scripts.get_all_scripts()
)
Expand Down Expand Up @@ -324,7 +328,8 @@ def react(self, *args, **kwargs):
'so make sure to call `help(app.callback)` to learn more.')

def _validate_callback(self, output, inputs, state, events):
layout = self._layout_value()
layout = self._cached_layout or self._layout_value()

if (layout is None and
not self.config.supress_callback_exceptions):
# Without a layout, we can't do validation on the IDs and
Expand Down
6 changes: 1 addition & 5 deletions dash/resources.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from copy import copy
import json
import warnings
import collections

from .development.base_component import Component

Expand Down Expand Up @@ -64,10 +63,7 @@ def get_all_resources(self):
def get_inferred_resources(self):
namespaces = []
resources = []
if isinstance(self.layout, collections.Callable):
layout = self.layout()
else:
layout = self.layout
layout = self.layout

def extract_resource_from_component(component):
if (isinstance(component, Component) and
Expand Down
2 changes: 1 addition & 1 deletion dash/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.18.0'
__version__ = '0.18.1'