Observer pattern
まだ誰も着手していません。
評価
調査の方向性
switch.py と issue に示されている Widget/YDoc の実装から始め、その後、psygnal と traitlets が監視対象の属性をどのように表現しているかを確認します。実用的な observer 設計で YMap の値エントリとネストされた YDoc 構造をカバーできるか判断します。実装範囲について合意され、これらの構造を監視するための明確なアプローチが定まれば完了とします。
索引モデルが issue の本文から書いたものです。
説明
In https://github.com/jupyter-widgets/ipywidgets/issues/3293#issuecomment-1433848240 @tlambert03 mentioned psygnal, that could be used to implement the equivalent of traitlets.
I think it is a good idea, but I'm not sure how it could fit here. For instance, take the Switch model, currently implemented as:
from .ypywidgets import Widget
class Switch(Widget):
def __init__(self, value: bool = False, open_comm: bool = True) -> None:
super().__init__(name="switch", open_comm=open_comm)
self.yvalue = self.ydoc.get_map("value")
self._set(value)
def _set(self, value: bool) -> None:
with self.ydoc.begin_transaction() as t:
self.yvalue.set(t, "value", value)
@property
def value(self) -> bool:
return self.yvalue["value"]
@value.setter
def value(self, value: bool):
if value == self.value:
return
self._set(value)
def toggle(self):
self.value = not self.value
Its YDoc consists of a YMap named value, with a single entry in it, also named value, which contains the boolean value of the switch. Here the observer pattern is manually implemented using a getter and a setter function for the value attribute.
If we were to use psygnal, we would need a way to point to the YDoc's structure (self.yvalue and value entry in it) from the psygnal's attribute.
I think that's the reason why traitlets use Python's descriptor protocol, which allows to get the name of an attribute at runtime.
Also, I'm not sure how we could connect nested YDoc structures (e.g. a YMap can contain other Y structures), but I don't think it was possible with traitlets anyway, so that would be an improvement.
- 主要言語
- Python
- スター
- 16
- フォーク
- 7
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
QuantStack/ypywidgets のほかの issue
-
Move to another org オープン
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
QuantStack/ypywidgets#12 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
QuantStack/ypywidgets#2 ·
QuantStack/ypywidgets の issue をすべて見る
似ている issue
-
bug priority:low
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
CyberAgent/psd2svg#436 ·
-
area/install-update comp/cli comp/desktop P3 sweeper:risk-compatibility type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
NousResearch/hermes-agent#122386 · コメント 1 件 ·
-
ai-generated
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
vllm-project/production-stack#1105 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100