Skip to content

Commit 642fbea

Browse files
committed
Collect children props in component registry, serve in config.
1 parent 3a26a40 commit 642fbea

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

dash/dash-renderer/src/TreeContainer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
pipe,
2121
propOr,
2222
path as rpath,
23+
pathOr,
2324
type
2425
} from 'ramda';
2526
import {notifyObservers, updateProps} from './actions';
@@ -210,7 +211,15 @@ class BaseTreeContainer extends Component {
210211
const element = Registry.resolve(_dashprivate_layout);
211212

212213
// Hydrate components props
213-
const childrenProps = propOr([], 'childrenProps', _dashprivate_layout);
214+
const childrenProps = pathOr(
215+
[],
216+
[
217+
'children_props',
218+
_dashprivate_layout.namespace,
219+
_dashprivate_layout.type
220+
],
221+
_dashprivate_config
222+
);
214223
const props = pipe(
215224
dissoc('children'),
216225
...childrenProps

dash/dash.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ def _config(self):
615615
"show_undo_redo": self.config.show_undo_redo,
616616
"suppress_callback_exceptions": self.config.suppress_callback_exceptions,
617617
"update_title": self.config.update_title,
618+
"children_props": ComponentRegistry.children_props,
618619
}
619620
if self._dev_tools.hot_reload:
620621
config["hot_reload"] = {

dash/development/_py_components_generation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def generate_class_string(
5151
c = '''class {typename}(Component):
5252
"""{docstring}"""
5353
_children_props = {children_props}
54+
_namespace = '{namespace}'
55+
_type = '{typename}'
5456
@_explicitize_args
5557
def __init__(self, {default_argtext}):
5658
self._prop_names = {list_of_valid_keys}
57-
self._type = '{typename}'
58-
self._namespace = '{namespace}'
5959
self._valid_wildcard_attributes =\
6060
{list_of_valid_wildcard_attr_prefixes}
6161
self.available_properties = {list_of_valid_keys}

dash/development/base_component.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import abc
2+
import collections
23
import inspect
34
import sys
45
import uuid
@@ -16,6 +17,7 @@ class ComponentRegistry:
1617
"""Holds a registry of the namespaces used by components."""
1718

1819
registry = set()
20+
children_props = collections.defaultdict(dict)
1921

2022
@classmethod
2123
def get_resources(cls, resource_name):
@@ -41,6 +43,9 @@ def __new__(mcs, name, bases, attributes):
4143
return component
4244

4345
ComponentRegistry.registry.add(module)
46+
ComponentRegistry.children_props[attributes.get("_namespace", module)][
47+
name
48+
] = attributes.get("_children_props")
4449

4550
return component
4651

@@ -222,9 +227,6 @@ def to_plotly_json(self):
222227
"namespace": self._namespace, # pylint: disable=no-member
223228
}
224229

225-
if self._children_props:
226-
as_json["childrenProps"] = self._children_props
227-
228230
return as_json
229231

230232
# pylint: disable=too-many-branches, too-many-return-statements

tests/unit/development/metadata_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ class Table(Component):
8787
8888
- optionalUnion (string | number; optional)"""
8989
_children_props = ['optionalNode', 'optionalElement']
90+
_namespace = 'TableComponents'
91+
_type = 'Table'
9092
@_explicitize_args
9193
def __init__(self, children=None, optionalArray=Component.UNDEFINED, optionalBool=Component.UNDEFINED, optionalFunc=Component.UNDEFINED, optionalNumber=Component.UNDEFINED, optionalObject=Component.UNDEFINED, optionalString=Component.UNDEFINED, optionalSymbol=Component.UNDEFINED, optionalNode=Component.UNDEFINED, optionalElement=Component.UNDEFINED, optionalMessage=Component.UNDEFINED, optionalEnum=Component.UNDEFINED, optionalUnion=Component.UNDEFINED, optionalArrayOf=Component.UNDEFINED, optionalObjectOf=Component.UNDEFINED, optionalObjectWithExactAndNestedDescription=Component.UNDEFINED, optionalObjectWithShapeAndNestedDescription=Component.UNDEFINED, optionalAny=Component.UNDEFINED, customProp=Component.UNDEFINED, customArrayProp=Component.UNDEFINED, id=Component.UNDEFINED, **kwargs):
9294
self._prop_names = ['children', 'id', 'aria-*', 'customArrayProp', 'customProp', 'data-*', 'in', 'optionalAny', 'optionalArray', 'optionalArrayOf', 'optionalBool', 'optionalElement', 'optionalEnum', 'optionalNode', 'optionalNumber', 'optionalObject', 'optionalObjectOf', 'optionalObjectWithExactAndNestedDescription', 'optionalObjectWithShapeAndNestedDescription', 'optionalString', 'optionalUnion']
93-
self._type = 'Table'
94-
self._namespace = 'TableComponents'
9595
self._valid_wildcard_attributes = ['data-', 'aria-']
9696
self.available_properties = ['children', 'id', 'aria-*', 'customArrayProp', 'customProp', 'data-*', 'in', 'optionalAny', 'optionalArray', 'optionalArrayOf', 'optionalBool', 'optionalElement', 'optionalEnum', 'optionalNode', 'optionalNumber', 'optionalObject', 'optionalObjectOf', 'optionalObjectWithExactAndNestedDescription', 'optionalObjectWithShapeAndNestedDescription', 'optionalString', 'optionalUnion']
9797
self.available_wildcard_properties = ['data-', 'aria-']

0 commit comments

Comments
 (0)