@@ -124,6 +124,11 @@ def __init__(self, name_root, app_pathname, **kwargs):
124124 nd_apps [self ._uid ] = self
125125
126126 self ._adjust_id = False
127+ self ._dash_dispatch = False
128+
129+ def use_dash_dispatch (self ):
130+ # TODO make this be a function of using kwargs in callbacks
131+ return self ._dash_dispatch
127132
128133 def flask_app (self ):
129134 return self ._flask_app
@@ -181,3 +186,32 @@ def callback(self, output, inputs=[], state=[], events=[]):
181186 [self ._fix_callback_item (x ) for x in state ],
182187 [self ._fix_callback_item (x ) for x in events ])
183188
189+ def dispatch (self ):
190+ import flask
191+ body = flask .request .get_json ()
192+ return self . dispatch_with_args (body , argMap = dict ())
193+
194+ def dispatch_with_args (self , body , argMap ):
195+ inputs = body .get ('inputs' , [])
196+ state = body .get ('state' , [])
197+ output = body ['output' ]
198+
199+ target_id = '{}.{}' .format (output ['id' ], output ['property' ])
200+ args = []
201+ for component_registration in self .callback_map [target_id ]['inputs' ]:
202+ args .append ([
203+ c .get ('value' , None ) for c in inputs if
204+ c ['property' ] == component_registration ['property' ] and
205+ c ['id' ] == component_registration ['id' ]
206+ ][0 ])
207+
208+ for component_registration in self .callback_map [target_id ]['state' ]:
209+ args .append ([
210+ c .get ('value' , None ) for c in state if
211+ c ['property' ] == component_registration ['property' ] and
212+ c ['id' ] == component_registration ['id' ]
213+ ][0 ])
214+
215+ return self .callback_map [target_id ]['callback' ](* args ,** argMap )
216+
217+
0 commit comments