hyperknot
hyperknot
Explore posts from servers
SSolidJS
Created by hyperknot on 9/27/2024 in #support
Questions about migrating from MobX
Thank you Alex! Sorry, I wasn't clear, I'd never use classes for that kind of use. I simply want to have my store in a class, like this:
class ChatStore {
constructor() {
const [state, setStore] = createStore({
apiKey: localStorage.getItem('apiKey') || '',
messages: [],
currentMessage: '',
isStreaming: false,
})

this.state = state
this.setStore = setStore
}

setStoreOnce(updater) {
this.setStore(produce(updater))
}

resetChat() {
this.setStoreOnce((s) => {
s.messages = []
s.currentMessage = ''
s.isStreaming = false
})
}
class ChatStore {
constructor() {
const [state, setStore] = createStore({
apiKey: localStorage.getItem('apiKey') || '',
messages: [],
currentMessage: '',
isStreaming: false,
})

this.state = state
this.setStore = setStore
}

setStoreOnce(updater) {
this.setStore(produce(updater))
}

resetChat() {
this.setStoreOnce((s) => {
s.messages = []
s.currentMessage = ''
s.isStreaming = false
})
}
It works well, but I don't know how much is it a pattern / antipattern in Solid land.
4 replies