From de0e1eb6b62daed957fb9187f9602fddc6f4e8cb Mon Sep 17 00:00:00 2001 From: Kartal Kaan Bozdogan Date: Sun, 17 Dec 2023 23:50:42 +0100 Subject: [PATCH] Improve README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f124917..935dab5 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ First you define your state: ``` int? currentThreshold; -List currentUnfilteredItems; +var currentUnfilteredItems = []; ``` Followed by setting up listeners: @@ -116,6 +116,7 @@ And your state computation logic: ``` void updateDB() { + if (currentThreshold == null) return ; final filteredItems = currentUnfilteredItems. filter((x) => x > currentThreshold). toList(); @@ -196,7 +197,7 @@ final sum = Computed.withPrev((prev) { - A: Short answer is: you can't. The functions passed to Computed should be pure computations, free of side effects. If you are meaning to use an external value as part of the computation, see `.use`. If you want to react to a stream of external events, see `.react`. If you wish to produce external side effects, see `.listen` or `.as[Broadcast]Stream`. - Q: Why am I getting `Computed expressions must be purely functional. Please use listeners for side effects.` -- A: On debug mode, Computed runs the given computations twice to make sure they behave identically. If this does not hold, it throws this assertion. Possible reasons include mutating and using a mutable value inside the computation or returning a type which does not implement deep comparisons, like `List` or `Set`. +- A: On debug mode, Computed runs the given computations twice and checks if both calls return the same value. If this does not hold, it throws this assertion. Possible reasons include mutating and using a mutable value inside the computation or returning a type which does not implement deep comparisons, like `List` or `Set`. ## Pitfalls