Skip to content

Commit

Permalink
Add Step API.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonkearns committed Feb 15, 2024
1 parent f50db29 commit 7078225
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
16 changes: 16 additions & 0 deletions examples/end-to-end/script/src/Steps2.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Steps2 exposing (run)

import BackendTask exposing (BackendTask)
import Pages.Script as Script exposing (Script, doThen, sleep)
import Pages.Script.Spinner as Spinner


run : Script
run =
Script.withoutCliOptions
(Spinner.steps
|> Spinner.withStep "Step 1" (\() -> sleep 3000)
|> Spinner.withStep "Step 2" (\() -> sleep 3000)
|> Spinner.withStep "Step 3" (\() -> sleep 3000)
|> Spinner.runSteps
)
34 changes: 33 additions & 1 deletion src/Pages/Script/Spinner.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Pages.Script.Spinner exposing (CompletionIcon(..), Options, Spinner, encodeCompletionIcon, options, runTask, runTaskExisting, runTaskWithOptions, showStep, spinner, start, withImmediateStart, withNamedAnimation, withOnCompletion)
module Pages.Script.Spinner exposing (CompletionIcon(..), Options, Spinner, encodeCompletionIcon, options, runSteps, runTask, runTaskExisting, runTaskWithOptions, showStep, spinner, start, steps, withImmediateStart, withNamedAnimation, withOnCompletion, withStep)

Check failure on line 1 in src/Pages/Script/Spinner.elm

View workflow job for this annotation

GitHub Actions / elm-review

NoUnused.Modules: Module `Pages.Script.Spinner` is never used.

This module is never used. You may want to remove it to keep your project clean, and maybe detect some unused code in your project.

Check failure on line 1 in src/Pages/Script/Spinner.elm

View workflow job for this annotation

GitHub Actions / elm-review

NoUnused.Exports: Module `Pages.Script.Spinner` is never used.

This module is never used. You may want to remove it to keep your project clean, and maybe detect some unused code in your project.

import BackendTask exposing (BackendTask)
import BackendTask.Http
import BackendTask.Internal.Request
import FatalError exposing (FatalError)
import Json.Decode as Decode
import Json.Encode as Encode

Expand Down Expand Up @@ -279,3 +280,34 @@ encodeCompletionIcon completionIcon =

Custom string ->

Check failure on line 281 in src/Pages/Script/Spinner.elm

View workflow job for this annotation

GitHub Actions / elm-review

NoUnused.Patterns: Value `string` is not used

You should either use this value somewhere or replace it with '_'.
"custom"


type Steps error value
= Steps (BackendTask error value)


steps : Steps FatalError ()
steps =
Steps (BackendTask.succeed ())


withStep : String -> (oldValue -> BackendTask FatalError newValue) -> Steps FatalError oldValue -> Steps FatalError newValue
withStep text backendTask steps_ =
case steps_ of
Steps previousSteps ->
Steps
(BackendTask.map2
(\pipelineValue newSpinner ->
runTaskExisting
newSpinner
(backendTask pipelineValue)
)
previousSteps
(options text |> showStep)
|> BackendTask.andThen identity
)


runSteps : Steps FatalError value -> BackendTask FatalError value
runSteps (Steps steps_) =
steps_

0 comments on commit 7078225

Please sign in to comment.