Closed cambiata closed 4 years ago
The simplest model would be something like this:
class Persistence<Data> implements Model {
@:constant var load:()->Promise<Data>;
@:constant var save:Data->Promise<Noise>;
@:observable private var revision:Int = 0;
@:loaded var data:Data = {revision; load();}
@:transition
function save(data:Data) {
return save(data).swap({revision: revision + 1});
// note: you can also use some local cache mechanism to avoid the reload
}
@:transition
function refresh() {
return {revision: revision + 1}
}
}
Thanks, very helpful!
Here's my take on implementing the whole chain, if anyone's interested: https://gist.github.com/cambiata/0298d909ae151f638cb1be4dbfc60392
Closing for now. One day we will move this to the website.
It would be great with an example or two how to best deal with model persistence, at least from and to json data.