Skip to content

Commit

Permalink
🐎 clientside callback interface
Browse files Browse the repository at this point in the history
see associated PR & examples in
plotly/dash-renderer#143
  • Loading branch information
chriddyp committed Mar 30, 2019
1 parent 0812b1a commit 79f8c24
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 11 additions & 2 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ def dependencies(self):
'output': k,
'inputs': v['inputs'],
'state': v['state'],
'client_function': v['client_function']
} for k, v in self.callback_map.items()
])

Expand Down Expand Up @@ -946,7 +947,7 @@ def _validate_value(val, index=None):
# TODO - Check this map for recursive or other ill-defined non-tree
# relationships
# pylint: disable=dangerous-default-value
def callback(self, output, inputs=[], state=[]):
def callback(self, output, inputs=[], state=[], client_function=None):
self._validate_callback(output, inputs, state)

callback_id = _create_callback_id(output)
Expand All @@ -960,8 +961,16 @@ def callback(self, output, inputs=[], state=[]):
'state': [
{'id': c.component_id, 'property': c.component_property}
for c in state
]
],
}
if client_function is not None:
self.callback_map[callback_id]['client_function'] = {
'namespace': client_function.namespace,
'function_name': client_function.function_name
}
else:
self.callback_map[callback_id]['client_function'] = {}


def wrap_func(func):
@wraps(func)
Expand Down
13 changes: 13 additions & 0 deletions dash/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ class Input(DashDependency):
# pylint: disable=too-few-public-methods
class State(DashDependency):
"""Use the value of a state in a callback but don't trigger updates."""


# pylint: disable=too-few-public-methods
class ClientFunction:
def __init__(self, namespace=None, function_name=None):
self.namespace = namespace
self.function_name = function_name

def __repr__(self):
return 'ClientFunction({}, {})'.format(
self.namespace,
self.function_name
)

0 comments on commit 79f8c24

Please sign in to comment.