How to add calculated getter in a existing store?

const [store, setStore] = createStore({firstName: "Foo", lastName: "Bar"})
11 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
REEEEE
REEEEE3y ago
const [store, setStore] = createStore({
firstName: "foo",
lastName: "bar",
get fullName(){
return this.firstName + this.lastName
}
})
const [store, setStore] = createStore({
firstName: "foo",
lastName: "bar",
get fullName(){
return this.firstName + this.lastName
}
})
Sorry on mobile
PureSoul
PureSoulOP3y ago
@._rb I want to set it after store is created. @ofabram This is not working.
REEEEE
REEEEE3y ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Otonashi
Otonashi3y ago
this isn't reactive though you probably can't do this, if the properties you want to set aren't top level you can but you'd have to replace the entire object
REEEEE
REEEEE3y ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Otonashi
Otonashi3y ago
but that's not really a getter
Otonashi
Otonashi3y ago
anyway it turns out the copy produce gives you works with defineProperty so this works https://playground.solidjs.com/anonymous/c7b438d5-42e6-464d-aa01-73dd755423e1
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Otonashi
Otonashi3y ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
REEEEE
REEEEE3y ago
Oh nice, good to know
PureSoul
PureSoulOP3y ago
@otonashi9 Thanks

Did you find this page helpful?