Skip to content

[WIP / POC] Ability to prevent initial callback from firing #1123

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

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 13 additions & 7 deletions dash-renderer/src/actions/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,18 +785,24 @@ export function getCallbacksInLayout(graphs, paths, layoutChunk, opts) {
// callbacks found in the layout by output should always run,
// ie this is the initial call of this callback even if it's
// not the page initialization but just a new layout chunk
// (unless the user explicitly didn't want them run)
cb.initialCall = true;
addCallback(cb);
if(!cb.callback.prevent_initial_call) {
addCallback(cb);
}
}
}
if (!outputsOnly && inIdCallbacks) {
const idStr = removedArrayInputsOnly && stringifyId(id);
for (const property in inIdCallbacks) {
getCallbacksByInput(graphs, paths, id, property).forEach(
removedArrayInputsOnly
? addCallbackIfArray(idStr)
: addCallback
);
for (let property in inIdCallbacks) {
getCallbacksByInput(graphs, paths, id, property).forEach(function(...args) {
if(args[0].callback.prevent_initial_call) {
return;
}
return removedArrayInputsOnly
? addCallbackIfArray(idStr)(...args)
: addCallback(...args)
});
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,19 +800,21 @@ def dependencies(self):
"inputs": v["inputs"],
"state": v["state"],
"clientside_function": v.get("clientside_function", None),
"prevent_initial_call": v["prevent_initial_call"]
}
for k, v in self.callback_map.items()
]
)

def _insert_callback(self, output, inputs, state):
def _insert_callback(self, output, inputs, state, prevent_initial_call):
layout = self._cached_layout or self._layout_value()
_validate.validate_callback(self, layout, output, inputs, state)
callback_id = create_callback_id(output)

self.callback_map[callback_id] = {
"inputs": [c.to_dict() for c in inputs],
"state": [c.to_dict() for c in state],
"prevent_initial_call": prevent_initial_call
}
self.used_outputs.extend(output if callback_id.startswith("..") else [output])

Expand Down Expand Up @@ -912,8 +914,8 @@ def clientside_callback(
"function_name": function_name,
}

def callback(self, output, inputs, state=()):
callback_id = self._insert_callback(output, inputs, state)
def callback(self, output, inputs, state=(), prevent_initial_call=False):
callback_id = self._insert_callback(output, inputs, state, prevent_initial_call)
multi = isinstance(output, (list, tuple))

def wrap_func(func):
Expand Down