Skip to content

Commit

Permalink
Merge pull request #321 from andressommerhoff/patch-2
Browse files Browse the repository at this point in the history
Enhance `DashBlueprint.register()` to accept custom PrefixIdTransform instances in `prefix` param
  • Loading branch information
emilhe committed May 4, 2024
2 parents 59b6d93 + 9ac65c2 commit 2e10e8b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dash_extensions/enrich.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,19 @@ def _resolve_callbacks(self) -> Tuple[List[CallbackBlueprint], List[CallbackBlue
return callbacks, clientside_callbacks

# TODO: Include or not? The plugin still seems a bit immature.
def register(self, app: Union[dash.Dash, DashProxy], module, prefix=None, **kwargs):
if prefix is not None:
def register(self, app: Union[dash.Dash, DashProxy], module, prefix: Union[str, PrefixIdTransform, None]=None, **kwargs):
# Deal with the prefix -> # prefix can be a string but now also custom PrefixIdTransform instance
if isinstance(prefix, str) and prefix:
# Create a PrefixIdTransform if prefix is a non-empty string and append it to transforms.
prefix_transform = PrefixIdTransform(prefix)
self.transforms.append(prefix_transform)
elif prefix is not None:
# Register the prefix as an instance of PrefixIdTransform or similar.
self.transforms.append(prefix)
# Register the callbacks and page.
self.register_callbacks(app)
dash.register_page(module, layout=self._layout_value, **kwargs)

def clear(self):
self.callbacks = []
self.clientside_callbacks = []
Expand Down

0 comments on commit 2e10e8b

Please sign in to comment.