Replies: 2 comments 2 replies
-
I did introduce the concept of a "store" in v1 but had to drop it. It wasn't as easy as you might think. Things to consider:
|
Beta Was this translation helpful? Give feedback.
-
How about designing an abstract store? It would be independent of the frontend and backend, serving as an abstract entity that provides APIs to both the frontend and backend. For instance, on the frontend, you could implement the interface using Observable, while on the backend, it could be Observable[T any]. The data in this store doesn't reside in the frontend but rather in the backend, and the synchronization between the frontend and backend is maintained within the Wails environment. Users are not allowed to modify data arbitrarily; instead, they need to access the corresponding API in a secure environment when they want to read or modify data. Like this func (o *Observable[T]) Read(fn func(data T)) {
o.lock.RLock()
defer o.lock.RUnlock()
fn(*o.data)
}
func (o *Observable[T]) Update(fn func(data *T)) {
o.lock.Lock()
defer o.lock.Unlock()
fn(o.data)
// sync to the frontend
}
func Foo() {
observable := NewObservable[string]("hello")
observable.Update(func(data *string) {
*data = "world"
})
} |
Beta Was this translation helpful? Give feedback.
-
What about planning to support two-way Data Binding in future?
If changes are made to the frontend data, the corresponding backend data will be updated instantly. Additionally, invoking the Update() method ensures that the frontend data is also synchronized. However, it's important to note that implementing these features involves a substantial amount of work."
I hope this helps! Let me know if you have any further requests or if there's anything else I can assist you with.
Beta Was this translation helpful? Give feedback.
All reactions