Skip to content

Commit d083b69

Browse files
committed
feat: Extend Composition APIs with IDSignal method to expose the
componet's ID as a state.Signal
1 parent abd3ae4 commit d083b69

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

v1/composition/composition.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ func (c *Component) Prop(key string, sig signalAny) {
7676
c.HTMLComponent.Props[key] = sig
7777
}
7878

79+
// IDSignal exposes the component's ID as a state.Signal stored under the "id" prop.
80+
// Updating the returned signal does not modify the component's actual ID.
81+
func (c *Component) IDSignal() *state.Signal[string] {
82+
s := state.NewSignal(c.ID)
83+
c.Prop("id", s)
84+
return s
85+
}
86+
7987
// OnUnmount cleans up the composition store when the component is removed.
8088
func (c *Component) OnUnmount() {
8189
for name := range c.createdStores {

0 commit comments

Comments
 (0)