Skip to content

Commit 5aa4761

Browse files
committed
We now create an initial contribution state from contribution
1 parent 78efef2 commit 5aa4761

File tree

2 files changed

+4
-59
lines changed

2 files changed

+4
-59
lines changed

dashipy/dashipy/contribs/panel.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,4 @@
66
class Panel(Contribution):
77
"""Panel contribution"""
88
def __init__(self, name: str, title: str):
9-
super().__init__(name)
10-
self.title = title
11-
12-
def to_dict(self) -> dict[str, Any]:
13-
return {
14-
**super().to_dict(),
15-
"title": self.title
16-
17-
}
9+
super().__init__(name, title=title)

dashipy/dashipy/lib/extension.py

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,6 @@
1-
from typing import Any, Callable
2-
from abc import ABC
1+
from typing import Any
32

4-
from .callback import Callback, Output, Input
5-
6-
7-
class Contribution(ABC):
8-
# noinspection PyShadowingBuiltins
9-
def __init__(self, name: str):
10-
self.name = name
11-
self.extension: Extension | None = None
12-
self.layout_callback: Callback | None = None
13-
self.callbacks: list[Callback] = []
14-
15-
def to_dict(self) -> dict[str, Any]:
16-
d = dict(name=self.name)
17-
if self.extension is not None:
18-
d.update(extension=self.extension.name)
19-
if self.layout_callback is not None:
20-
d.update(layout=self.layout_callback.to_dict())
21-
if self.callbacks:
22-
d.update(callbacks=[cb.to_dict() for cb in self.callbacks])
23-
return d
24-
25-
def layout(self, *args) -> Callable:
26-
"""Decorator."""
27-
28-
def decorator(function: Callable) -> Callable:
29-
self.layout_callback = Callback.from_decorator(
30-
"layout", args, function, outputs_allowed=False
31-
)
32-
return function
33-
34-
return decorator
35-
36-
def callback(self, *args: Input | Output) -> Callable[[Callable], Callable]:
37-
"""Decorator."""
38-
39-
def decorator(function: Callable) -> Callable:
40-
self.callbacks.append(
41-
Callback.from_decorator(
42-
"callback", args, function, outputs_allowed=True
43-
)
44-
)
45-
return function
46-
47-
return decorator
48-
49-
def __str__(self):
50-
return self.name
3+
from dashipy.lib.contribution import Contribution
514

525

536
class Extension:
@@ -79,7 +32,7 @@ def add(self, contribution: Contribution):
7932
raise TypeError(
8033
f"unrecognized contribution of type {contrib_type.__qualname__}"
8134
)
82-
contribution.extension = self
35+
contribution.extension = self.name
8336
contributions: list[Contribution] = getattr(self, contrib_point_name)
8437
contributions.append(contribution)
8538

0 commit comments

Comments
 (0)