Effect

The application effects.

type Effect msg

An opaque type that represents all the effects that init and update functions may produce.

Application

type alias Model r =
{ r | session : Session, env : Env }

The partial top level model required to perform effects.

{ init : Session -> Url -> Key -> ( Model r, Effect msg )
, view : Model r -> Document msg
, update : msg -> Model r -> ( Model r, Effect msg )
, ignore : String -> msg
, subscriptions : Model r -> Sub msg
, onUrlChange : Url -> msg
, onUrlRequest : UrlRequest -> msg
}
-> Program Value (Model r) msg

A custom application that will turn init and update effects into actual Cmd and state changes.

The additional ignore function is used to ignore events at a single place in the whole application. Compared to the commonly used NoOp, it takes an additional String description to be more informative in the debugger.

Fancy effects

none : Effect msg

No effect.

batch : List (Effect msg) -> Effect msg

Batch several effects together.

map : (a -> msg) -> Effect a -> Effect msg

Transform the messages produced by an effect.

Navigation

replaceUrl : Route -> Effect msg

Replace the current URL without adding an entry to the browser history.

pushUrl : Url -> Effect msg

Change the URL and add a new entry to the browser history.

loadUrl : String -> Effect msg

Leave the current page and load the given URL.

Time

getTimeZone : (Zone -> msg) -> Effect msg

Retrieve a time zone based on the current UTC offset.

Scrolling

Scroll page to top.

User

(Result Errors Session -> msg)
-> { username : String
, email : String
, password : String
}
-> Effect msg

Create a new user.

(Result Errors Session -> msg)
-> { email : String
, password : String
}
-> Effect msg

Authenticate with the backend.

Log in with an authenticated session.

Logout

fetchSettings : (Result Errors Settings -> msg) -> Effect msg

Fetch the logged in user settings.

updateSettings : (Result Errors Session -> msg) -> Cred -> Settings -> Effect msg

Update the logged in user settings.

Tags

fetchTags : (Result Errors (List Tag) -> msg) -> Effect msg

Fetch tags.

Article

fetchArticle : (Result Errors (Article Full) -> msg) -> Slug -> Effect msg

Fetch an article.

(Result Errors (Article Full) -> msg)
-> Cred
-> { title : String
, description : String
, body : String
, tags : String
}
-> Effect msg

Create a new article.

(Result Errors (Article Full) -> msg)
-> Cred
-> Slug
-> { r | title : String, description : String, body : String }
-> Effect msg

Edit a previously created article.

deleteArticle : (Result Errors () -> msg) -> Cred -> Slug -> Effect msg

Delete a previously created article.

favorite : (Result Errors (Article Preview) -> msg) -> Cred -> Slug -> Effect msg

Set an article as favorite.

unfavorite : (Result Errors (Article Preview) -> msg) -> Cred -> Slug -> Effect msg

Unset an article as favorite.

Articles feed

(Result Errors (PaginatedList (Article Preview)) -> msg)
-> Int
-> Effect msg

Fetch the user articles feed.

(Result Errors (PaginatedList (Article Preview)) -> msg)
-> Int
-> Effect msg

Fetch the global articles feed.

(Result Errors (PaginatedList (Article Preview)) -> msg)
-> Int
-> Tag
-> Effect msg

Fetch the current tag feed.

(Result Errors (PaginatedList (Article Preview)) -> msg)
-> Int
-> Username
-> Effect msg

Fetch an author feed.

(Result Errors (PaginatedList (Article Preview)) -> msg)
-> Int
-> Username
-> Effect msg

Fetch the favorite artciles feed.

Comments

fetchComments : (Result Errors (List Comment) -> msg) -> Slug -> Effect msg

Fetch an article comments.

postComment : (Result Errors Comment -> msg) -> Cred -> Slug -> String -> Effect msg

Post an article comment.

deleteComment : (Result Errors () -> msg) -> Cred -> Slug -> CommentId -> Effect msg

Delete a previously posted article comment.

Authors

fetchAuthor : (Result Errors Author -> msg) -> Username -> Effect msg

Fetch an author profile.

follow : (Result Errors Author -> msg) -> Cred -> UnfollowedAuthor -> Effect msg

Follow an author.

unfollow : (Result Errors Author -> msg) -> Cred -> FollowedAuthor -> Effect msg

Unfollow an author.

Errors

This is a placeholder API for how we might log errors to a server.

Whenever you see Effect.logError used in this code base, it means "Something unexpected happened. This is where we would log an error to a server with some diagnostic info so we could investigate what happened later."

(Since this is outside the scope of the RealWorld spec, and is only a placeholder anyway, this function does not accept actual diagnostic info, authentication tokens, etc.)