From 79f8c24e9f055c9cb6572f20014d67b670ba14fb Mon Sep 17 00:00:00 2001 From: Chris P Date: Sat, 30 Mar 2019 13:13:26 -0400 Subject: [PATCH] :racehorse: clientside callback interface see associated PR & examples in https://github.com/plotly/dash-renderer/pull/143 --- dash/dash.py | 13 +++++++++++-- dash/dependencies.py | 13 +++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 040152f29b..ed1460fab2 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -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() ]) @@ -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) @@ -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) diff --git a/dash/dependencies.py b/dash/dependencies.py index 3f946f1ebf..1e7985c4cc 100644 --- a/dash/dependencies.py +++ b/dash/dependencies.py @@ -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 + )