Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Updates for 0.12 (#22)
Browse files Browse the repository at this point in the history
* Updates for 0.12

* most examples

* Update deps, add async example

* Travis
  • Loading branch information
paf31 authored Jun 24, 2018
1 parent d1abd6d commit 7782c35
Show file tree
Hide file tree
Showing 30 changed files with 200 additions and 385 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
dist: trusty
sudo: required
node_js: stable
install:
- npm install -g bower
- npm install
- bower install
script:
- npm run -s build
13 changes: 8 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
"url": "git://github.com/paf31/purescript-sdom.git"
},
"dependencies": {
"purescript-dom": "^4.13.2",
"purescript-behaviors": "^6.3.0",
"purescript-profunctor": "^3.2.0",
"purescript-refs": "^3.0.0"
"purescript-event": "^1.2.3",
"purescript-profunctor": "^4.0.0",
"purescript-refs": "^4.0.0",
"purescript-web-dom": "^1.0.0",
"purescript-web-html": "^1.0.0"
},
"devDependencies": {
"purescript-psci-support": "^3.0.0"
"purescript-psci-support": "^4.0.0",
"purescript-profunctor-lenses": "^4.0.0",
"purescript-drawing": "^4.0.0"
}
}
4 changes: 4 additions & 0 deletions examples/async/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
purs compile '../../src/**/*.purs' '../../bower_components/purescript-*/src/**/*.purs' src/Main.purs
purs bundle --main Main --module Main --output html/index.js output/*/*.js

15 changes: 0 additions & 15 deletions examples/async/bower.json

This file was deleted.

14 changes: 0 additions & 14 deletions examples/async/package.json

This file was deleted.

26 changes: 9 additions & 17 deletions examples/async/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@ module Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION, throw)
import Control.Monad.Eff.Ref (REF)
import DOM (DOM)
import DOM.HTML (window)
import DOM.HTML.Types (htmlDocumentToNonElementParentNode)
import DOM.HTML.Window (document)
import DOM.Node.NonElementParentNode (getElementById)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.Newtype (wrap)
import FRP (FRP)
import Effect (Effect)
import Effect.Exception (throw)
import FRP.Event (Event)
import FRP.Event.Time (interval)
import SDOM (SDOM, attach, mapChannel, withAsync, text, text_)
import SDOM.Attributes as A
import SDOM.Elements as E
import SDOM.Events as Events
import Web.DOM.NonElementParentNode (getElementById)
import Web.HTML (window)
import Web.HTML.HTMLDocument (toNonElementParentNode)
import Web.HTML.Window (document)

data Mode = Increasing | Decreasing | Neither

Expand Down Expand Up @@ -67,14 +63,10 @@ counter_ =
interpreter Decreasing = interval 100 $> \{ value } -> { mode: Decreasing, value: value - 1 }
interpreter Neither = pure \{ value } -> { mode: Neither, value }

main :: Eff ( dom :: DOM
, exception :: EXCEPTION
, frp :: FRP
, ref :: REF
) Unit
main :: Effect Unit
main = do
document <- map htmlDocumentToNonElementParentNode (window >>= document)
container <- getElementById (wrap "container") document
document <- map toNonElementParentNode (window >>= document)
container <- getElementById "container" document
case container of
Just el -> void do
attach el { value: 0, mode: Neither } counter_
Expand Down
4 changes: 4 additions & 0 deletions examples/canvas/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
purs compile '../../src/**/*.purs' '../../bower_components/purescript-*/src/**/*.purs' src/Main.purs
purs bundle --main Main --module Main --output html/index.js output/*/*.js

17 changes: 0 additions & 17 deletions examples/canvas/bower.json

This file was deleted.

14 changes: 0 additions & 14 deletions examples/canvas/package.json

This file was deleted.

51 changes: 21 additions & 30 deletions examples/canvas/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,12 @@ module Main where
import Prelude

import Color (rgba, white)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION, throw)
import Control.Monad.Eff.Ref (REF)
import Control.Monad.Eff.Unsafe (unsafeCoerceEff)
import Control.Plus (empty)
import DOM (DOM)
import DOM.HTML (window)
import DOM.HTML.Types (htmlDocumentToDocument, htmlDocumentToNonElementParentNode)
import DOM.HTML.Window (document)
import DOM.Node.Document (createElement)
import DOM.Node.Node (appendChild)
import DOM.Node.NonElementParentNode (getElementById)
import DOM.Node.Types (elementToNode)
import Data.Int (round, toNumber)
import Data.Maybe (Maybe(Nothing, Just))
import Data.Newtype (wrap)
import Data.Profunctor (dimap, lmap)
import FRP (FRP)
import Data.Maybe (Maybe(..))
import Data.Profunctor (dimap, lcmap)
import Effect (Effect)
import Effect.Exception (throw)
import FRP.Event (subscribe)
import Global (readInt)
import Graphics.Canvas (getContext2D, setCanvasHeight, setCanvasWidth)
Expand All @@ -29,21 +17,28 @@ import SDOM (SDOM, attach, text_, unsafeSDOM)
import SDOM.Components (textbox)
import SDOM.Elements as E
import Unsafe.Coerce (unsafeCoerce)
import Web.DOM.Document (createElement)
import Web.DOM.Element (toNode)
import Web.DOM.Node (appendChild)
import Web.DOM.NonElementParentNode (getElementById)
import Web.HTML (window)
import Web.HTML.HTMLDocument (toDocument, toNonElementParentNode)
import Web.HTML.Window (document)

drawing :: forall channel context model. SDOM channel context Drawing model
drawing = unsafeSDOM \node _ d updates -> unsafeCoerceEff do
drawing = unsafeSDOM \node _ d updates -> do
doc <- window >>= document
canvasEl <- createElement "canvas" (htmlDocumentToDocument doc)
canvasEl <- createElement "canvas" (toDocument doc)
let canvas = unsafeCoerce canvasEl
_ <- setCanvasWidth 200.0 canvas
_ <- setCanvasHeight 200.0 canvas
_ <- setCanvasWidth canvas 200.0
_ <- setCanvasHeight canvas 200.0
context <- getContext2D canvas
_ <- appendChild (elementToNode canvasEl) node
_ <- appendChild (toNode canvasEl) node
render context d
unsubscribe <- updates `subscribe` \{ new } -> render context new
pure
{ events: empty
, unsubscribe: unsafeCoerceEff unsubscribe
, unsubscribe
}

renderCircle :: Int -> Drawing
Expand All @@ -57,20 +52,16 @@ app
app =
E.div_
[ E.h1_ [ text_ "Canvas" ]
, lmap renderCircle drawing
, lcmap renderCircle drawing
, E.p_ [ text_ "Radius: "
, dimap show (round <<< readInt 10) textbox
]
]

main :: Eff ( dom :: DOM
, exception :: EXCEPTION
, frp :: FRP
, ref :: REF
) Unit
main :: Effect Unit
main = do
document <- map htmlDocumentToNonElementParentNode (window >>= document)
container <- getElementById (wrap "container") document
document <- map toNonElementParentNode (window >>= document)
container <- getElementById "container" document
case container of
Just el -> void do
attach el 100 app
Expand Down
4 changes: 4 additions & 0 deletions examples/counter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
purs compile '../../src/**/*.purs' '../../bower_components/purescript-*/src/**/*.purs' src/Main.purs
purs bundle --main Main --module Main --output html/index.js output/*/*.js

15 changes: 0 additions & 15 deletions examples/counter/bower.json

This file was deleted.

26 changes: 9 additions & 17 deletions examples/counter/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ module Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION, throw)
import Control.Monad.Eff.Ref (REF)
import DOM (DOM)
import DOM.HTML (window)
import DOM.HTML.Types (htmlDocumentToNonElementParentNode)
import DOM.HTML.Window (document)
import DOM.Node.NonElementParentNode (getElementById)
import Data.Maybe (Maybe(..))
import Data.Newtype (wrap)
import FRP (FRP)
import Effect (Effect)
import Effect.Exception (throw)
import SDOM (SDOM, attach, text, text_)
import SDOM.Elements as E
import SDOM.Events as Events
import Web.DOM.NonElementParentNode (getElementById)
import Web.HTML (window)
import Web.HTML.HTMLDocument (toNonElementParentNode)
import Web.HTML.Window (document)

counter
:: forall channel context
Expand All @@ -29,14 +25,10 @@ counter =
[ text \_ value -> "(" <> show value <> ") Increment" ]
]

main :: Eff ( dom :: DOM
, exception :: EXCEPTION
, frp :: FRP
, ref :: REF
) Unit
main :: Effect Unit
main = do
document <- map htmlDocumentToNonElementParentNode (window >>= document)
container <- getElementById (wrap "container") document
document <- map toNonElementParentNode (window >>= document)
container <- getElementById "container" document
case container of
Just el -> void do
attach el 0 counter
Expand Down
4 changes: 4 additions & 0 deletions examples/select/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
purs compile '../../src/**/*.purs' '../../bower_components/purescript-*/src/**/*.purs' src/Main.purs
purs bundle --main Main --module Main --output html/index.js output/*/*.js

15 changes: 0 additions & 15 deletions examples/select/bower.json

This file was deleted.

14 changes: 0 additions & 14 deletions examples/select/package.json

This file was deleted.

26 changes: 9 additions & 17 deletions examples/select/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ module Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION, throw)
import Control.Monad.Eff.Ref (REF)
import DOM (DOM)
import DOM.HTML (window)
import DOM.HTML.Types (htmlDocumentToNonElementParentNode)
import DOM.HTML.Window (document)
import DOM.Node.NonElementParentNode (getElementById)
import Data.Maybe (Maybe(..))
import Data.Newtype (wrap)
import FRP (FRP)
import Effect (Effect)
import Effect.Exception (throw)
import SDOM (SDOM, attach, text, text_)
import SDOM.Components as Components
import SDOM.Elements as E
import Web.DOM.NonElementParentNode (getElementById)
import Web.HTML (window)
import Web.HTML.HTMLDocument (toNonElementParentNode)
import Web.HTML.Window (document)

data WidgetType
= BasicWidget
Expand Down Expand Up @@ -61,14 +57,10 @@ select =
, E.p_ [ text \_ selectedProduct -> "The price is " <> priceOf selectedProduct ]
]

main :: Eff ( dom :: DOM
, exception :: EXCEPTION
, frp :: FRP
, ref :: REF
) Unit
main :: Effect Unit
main = do
document <- map htmlDocumentToNonElementParentNode (window >>= document)
container <- getElementById (wrap "container") document
document <- map toNonElementParentNode (window >>= document)
container <- getElementById "container" document
case container of
Just el -> void do
attach el BasicWidget select
Expand Down
4 changes: 4 additions & 0 deletions examples/todo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
purs compile '../../src/**/*.purs' '../../bower_components/purescript-*/src/**/*.purs' src/Main.purs
purs bundle --main Main --module Main --output html/index.js output/*/*.js

Loading

0 comments on commit 7782c35

Please sign in to comment.