Skip to content

Commit

Permalink
Fix TODO example
Browse files Browse the repository at this point in the history
  • Loading branch information
mstniy committed Dec 3, 2023
1 parent f9e254b commit 2fe0028
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion example/todo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ void main() async {
uiUpdate.react((t) {
b[t.item1] = t.item2;
}, null);
final id = largestId.use;
uiCreate.react((t) {
b[largestId.use] = t;
b[id] = t;
}, null);
},
);
Expand Down
11 changes: 5 additions & 6 deletions lib/src/computed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class ComputedImpl<T> with Computed<T> {
bool get _novalue => _lastResult == null;
_ValueOrException<T>? _lastResult;
_ValueOrException<T>? _prevResult;
T? _initialPrev;
Map<ComputedImpl, _MemoizedValueOrException>?
_lastResultfulUpstreamComputations;
var _lastUpstreamComputations = <ComputedImpl, _MemoizedValueOrException>{};
Expand All @@ -148,8 +149,8 @@ class ComputedImpl<T> with Computed<T> {
T get prev {
final caller = GlobalCtx.currentComputation;
if (caller == this) {
if (_prevResult == null) throw NoValueException();
return _prevResult!.value;
if (_prevResult == null && _initialPrev == null) throw NoValueException();
return (_prevResult?.value ?? _initialPrev)!;
} else {
if (caller._lastResult == null) throw NoValueException();
final mvoe = caller._lastResultfulUpstreamComputations![this];
Expand All @@ -167,10 +168,8 @@ class ComputedImpl<T> with Computed<T> {

static ComputedImpl<T> withPrev<T>(T Function(T prev) f, T initialPrev) {
late ComputedImpl<T> c;
c = ComputedImpl<T>(() {
c._prevResult ??= _ValueOrException.value(initialPrev);
return f(c._prevResult!.value);
});
c = ComputedImpl<T>(() => f(c._prevResult?.value ?? initialPrev));
c._initialPrev = initialPrev;

return c;
}
Expand Down

0 comments on commit 2fe0028

Please sign in to comment.