MCPcopy Index your code
hub / github.com/plotly/dash / add_hook

Method add_hook

dash/_hooks.py:64–87  ·  view source on GitHub ↗
(
        self,
        hook: str,
        func: _t.Callable,
        priority: _t.Optional[int] = None,
        final: bool = False,
        data: _t.Optional[HookDataType] = None,
    )

Source from the content-addressed store, hash-verified

62 self._finals: _t.Dict[str, _t.Any] = {}
63
64 def add_hook(
65 self,
66 hook: str,
67 func: _t.Callable,
68 priority: _t.Optional[int] = None,
69 final: bool = False,
70 data: _t.Optional[HookDataType] = None,
71 ):
72 if final:
73 existing = self._finals.get(hook)
74 if existing:
75 raise HookError("Final hook already present")
76 self._finals[hook] = _Hook(func, final, data=data)
77 return
78 hks = self._ns.get(hook, [])
79
80 p = priority or 0
81 if not priority and len(hks):
82 # Take the minimum value and remove 1 to keep the order.
83 priority_min = min(h.priority for h in hks)
84 p = priority_min - 1
85
86 hks.append(_Hook(func, priority=p, data=data))
87 self._ns[hook] = sorted(hks, reverse=True, key=lambda h: h.priority)
88
89 def get_hooks(self, hook: str) -> _t.List[_Hook]:
90 final = self._finals.get(hook, None)

Callers 5

_wrapMethod · 0.95
_setupMethod · 0.95
wrapMethod · 0.95
_errorMethod · 0.95
decoratorMethod · 0.95

Calls 4

HookErrorClass · 0.85
_HookClass · 0.85
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected