Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Commit

Permalink
add deprecation stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Westby committed Nov 15, 2016
1 parent 423a6a9 commit fb7704d
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Worker

Start Elm apps without views
## This package is deprecated as of Elm 0.18 and the addition of `Platform.program`.

### Example
The example below explains how to use `Platform.program` to provide the
functionality you might have used this package for prior to 0.18.

### Example

**Main.elm**
```elm
port module Main exposing (..)

import Worker
import Platform

{-| We'll receive messages from the world in the form of strings here -}
port messagesIn : (String -> msg) -> Sub msg
Expand All @@ -32,14 +34,27 @@ type Msg
| NoOp


{-| This update will send a Cmd to send the model out over a port on every msg. This
can be abstracted into a separate function as your app becomes larger and your
updates become more complicated.
-}
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Increment ->
(model + 1, Cmd.none)
let
(nextModel, nextCmd) =
case msg of
Increment ->
(model + 1, Cmd.none)

NoOp ->
(model, Cmd.none)
NoOp ->
(model, Cmd.none)
in
( nextModel
, Cmd.batch
[ nextCmd
, modelOut nextModel
]
)


{-| In this function we define `parse` in order to go from
Expand All @@ -62,16 +77,9 @@ subscriptions _ =
messagesIn parse


{-| The first argument to Worker.worker lets us wrap our update
function with additional Cmds to execute on every change. In this
case we want to send our model out to JS on every update so we
pass it our `modelOut` port. We are already receiving messages from
our `messagesIn` port via `subscriptions` so now we're fully connected
to the JavaScript side of the application!
-}
main : Program Never
main =
Worker.program modelOut
Platform.program
{ init = init
, update = update
, subscriptions = subscriptions
Expand Down

0 comments on commit fb7704d

Please sign in to comment.