Skip to content

Commit

Permalink
refactor: compute results once.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Oct 14, 2024
1 parent 20326f5 commit b49b6ef
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/Page/Object.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ import Browser.Navigation as Navigation
import Data.Bookmark as Bookmark exposing (Bookmark)
import Data.Dataset as Dataset
import Data.Example as Example
import Data.Impact as Impact
import Data.Impact.Definition as Definition exposing (Definition)
import Data.Key as Key
import Data.Object.Process as Process exposing (Process)
import Data.Object.Query as Query exposing (Query)
import Data.Object.Simulator as Simulator
import Data.Object.Simulator as Simulator exposing (Results)
import Data.Scope as Scope
import Data.Session as Session exposing (Session)
import Data.Uuid exposing (Uuid)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Ports
import Quantity
import Result.Extra as RE
import Route
import Static.Db exposing (Db)
Expand All @@ -54,6 +52,7 @@ type alias Model =
, impact : Definition
, initialQuery : Query
, modal : Modal
, results : Results
}


Expand Down Expand Up @@ -107,6 +106,9 @@ init trigram maybeUrlQuery session =
, impact = Definition.get trigram session.db.definitions
, initialQuery = initialQuery
, modal = NoModal
, results =
Simulator.compute session.db initialQuery
|> Result.withDefault Simulator.emptyResults
}
, session
|> Session.updateObjectQuery initialQuery
Expand Down Expand Up @@ -142,6 +144,9 @@ initFromExample session uuid =
, impact = Definition.get Definition.Ecs session.db.definitions
, initialQuery = exampleQuery
, modal = NoModal
, results =
Simulator.compute session.db exampleQuery
|> Result.withDefault Simulator.emptyResults
}
, session
|> Session.updateObjectQuery exampleQuery
Expand Down Expand Up @@ -387,23 +392,14 @@ simulatorView session model =

-- Score
, customScoreInfo = Nothing
, productMass =
Simulator.compute session.db session.queries.object
|> Result.map Simulator.extractMass
|> Result.withDefault Quantity.zero
, totalImpacts =
Simulator.compute session.db session.queries.object
|> Result.map Simulator.extractImpacts
|> Result.withDefault Impact.empty
, productMass = Simulator.extractMass model.results
, totalImpacts = Simulator.extractImpacts model.results

-- Impacts tabs
, impactTabsConfig =
SwitchImpactsTab
|> ImpactTabs.createConfig session model.impact model.activeImpactsTab (always NoOp)
|> ImpactTabs.forObject
(Simulator.compute session.db session.queries.object
|> Result.withDefault Simulator.emptyResults
)
|> ImpactTabs.forObject model.results
|> Just

-- Bookmarks
Expand Down

0 comments on commit b49b6ef

Please sign in to comment.