Skip to content

Commit aeb607c

Browse files
[feat]: Add new helper client types for optimistic update to support frontend development.
what changed?: add new helper client types for optimistic update why?: aid in front end development effect?: n/a
1 parent 9326086 commit aeb607c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/SAFE.Client/SAFE.fs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,24 @@ module RemoteData =
185185
/// `Loaded x -> Loading x`;
186186
/// `NotStarted -> Loading None`;
187187
/// `Loading x -> Loading x`;
188-
let startLoading (remote: RemoteData<'T>) = remote.StartLoading
188+
let startLoading (remote: RemoteData<'T>) = remote.StartLoading
189+
190+
///A type which represents optimistic updates.
191+
type Optimistic<'a> = {
192+
Prev: 'a option
193+
Curr: 'a option
194+
}with
195+
196+
///Assign the current value as the now previous value and the passed in value as the new current value
197+
member this.Update value =
198+
{
199+
Curr = Some value
200+
Prev = this.Curr
201+
}
202+
203+
///Rollback to the previous value in the case of a failure
204+
member this.Rollback =
205+
{
206+
Curr = this.Prev
207+
Prev = None
208+
}

0 commit comments

Comments
 (0)