Let me pose a question: I have created a custom store that looks like this:
const MyCustomStore = (Data) => {
const { subscribe, set, update } = writable(Data);
return {
subscribe,
update,
set,
setData: (NewData) => {
set(NewData)
},
getData: () => {
return <<<<<<< "Here lies the problem - how can I retrieve the 'newData'?"
}
}
}
Now, let me explain the scenario. I am developing a script for a FiveM server using Svelte. I have created a store that holds information about vehicles such as Name, Last Name, Plate, and more. I have a method called setData(Vehicle) which sets the data, but in another method, I only need to retrieve the plate. One solution I implemented was creating a variable within the scope and using update instead of set:
const VehicleStore = (Vehicle) => {
let Data = {} // Variable within the scope
const { subscribe, set, update } = writable(Vehicle);
return {
subscribe,
update,
set,
setData: (NewData) => {
update((s) => {
s = NewData
Data = s
return s
})
},
getData: () => {
return Data.Plate
}
}
}
I am uncertain if this is the correct solution; it feels like something might be missing.