Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit ee11bad

Browse files
authored
Merge pull request #5 from slamdata/ps/0.12
update for ps0.12
2 parents 21e83db + edbb689 commit ee11bad

File tree

4 files changed

+59
-63
lines changed

4 files changed

+59
-63
lines changed

bower.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
"package.json"
1919
],
2020
"dependencies": {
21-
"purescript-prelude": "^3.0.0",
22-
"purescript-dom": "^4.2.0",
23-
"purescript-css": "^3.0.0"
21+
"purescript-prelude": "^4.1.0",
22+
"purescript-web-dom": "^1.0.0",
23+
"purescript-css": "^4.0.0"
24+
},
25+
"devDependencies": {
26+
"purescript-web-html": "^1.2.0",
27+
"purescript-web-events": "^1.0.1"
2428
}
2529
}

example/src/Main.purs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,45 @@ import Prelude
44

55
import CSS (Selector, fromString)
66
import Clipboard as C
7-
import Control.Monad.Eff (Eff)
8-
import DOM (DOM)
9-
import DOM.Event.EventTarget (addEventListener, eventListener)
10-
import DOM.HTML (window)
11-
import DOM.HTML.Event.EventTypes (load)
12-
import DOM.HTML.Types (windowToEventTarget, htmlDocumentToDocument)
13-
import DOM.HTML.Window (document)
14-
import DOM.Node.Element (getAttribute)
15-
import DOM.Node.NonElementParentNode (getElementById)
16-
import DOM.Node.Types (Element, ElementId(ElementId), documentToNonElementParentNode)
177
import Data.Maybe (fromJust, fromMaybe)
18-
import Data.Newtype (wrap)
8+
import Effect (Effect)
199
import Partial.Unsafe (unsafePartial)
20-
21-
onLoad :: forall eff. (Eff (dom :: DOM | eff) Unit) -> Eff (dom :: DOM | eff) Unit
22-
onLoad action
23-
= addEventListener load (eventListener (const action)) false
24-
<<< windowToEventTarget
25-
=<< window
26-
27-
stringFromAttr :: forall eff. String -> Element -> Eff (dom :: DOM | eff) String
28-
stringFromAttr attr el = fromMaybe "" <$> getAttribute attr el
29-
30-
testElement :: forall eff. Element -> Eff (dom :: DOM | eff) Unit
10+
import Web.DOM.Element (Element)
11+
import Web.DOM.Element as Element
12+
import Web.DOM.NonElementParentNode (getElementById)
13+
import Web.Event.EventTarget (addEventListener, eventListener)
14+
import Web.HTML (window)
15+
import Web.HTML.Event.EventTypes (load)
16+
import Web.HTML.HTMLDocument as HTMLDocument
17+
import Web.HTML.Window as Window
18+
19+
onLoad :: Effect Unit -> Effect Unit --forall eff. (Eff (dom :: DOM | eff) Unit) -> Eff (dom :: DOM | eff) Unit
20+
onLoad action = do
21+
listener <- eventListener $ const action
22+
win <- map Window.toEventTarget window
23+
addEventListener load listener false win
24+
25+
stringFromAttr :: String -> Element -> Effect String
26+
stringFromAttr attr el = fromMaybe "" <$> Element.getAttribute attr el
27+
28+
testElement :: Element -> Effect Unit
3129
testElement el = void $ C.fromElement el $ stringFromAttr "data-copy-text" el
3230

33-
testSelector :: forall eff. Selector -> Eff (dom :: DOM | eff) Unit
31+
testSelector :: Selector -> Effect Unit
3432
testSelector sel = void $ C.fromCSSSelector sel $ stringFromAttr "data-copy-text"
3533

36-
testInputSelector :: forall eff. Eff (dom :: DOM | eff) Unit
34+
testInputSelector :: Effect Unit
3735
testInputSelector = do
38-
doc <- documentToNonElementParentNode <<< htmlDocumentToDocument <$> (document =<< window)
39-
let getInput = unsafePartial fromJust <$> getElementById (wrap "input-selector") doc
40-
button <- unsafePartial fromJust <$> getElementById (wrap "input-button-selector") doc
36+
doc <- HTMLDocument.toNonElementParentNode <$> (Window.document =<< window)
37+
let getInput = unsafePartial fromJust <$> getElementById "input-selector" doc
38+
button <- unsafePartial fromJust <$> getElementById "input-button-selector" doc
4139
void $ C.fromElementWithTarget button getInput
4240

43-
main :: forall eff. Eff (dom :: DOM | eff) Unit
41+
main :: Effect Unit
4442
main = onLoad do
4543
win <- window
46-
doc <- documentToNonElementParentNode <<< htmlDocumentToDocument <$> document win
47-
element <- getElementById (ElementId "test-element") doc
44+
doc <- HTMLDocument.toNonElementParentNode <$> Window.document win
45+
element <- getElementById "test-element" doc
4846
fromMaybe (pure unit) $ testElement <$> element
4947
testSelector $ fromString ".test-selector"
5048
testInputSelector

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"private": true,
33
"scripts": {
4-
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "eslint src && pulp build -- --censor-lib --strict",
6-
"test": "pulp build -I example/src -- --censor-lib --strict",
7-
"build-example": "pulp browserify -I example/src --to example/example.js"
8-
},
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "eslint src && pulp build -- --censor-lib --strict",
6+
"test": "pulp build -I example/src -- --censor-lib --strict",
7+
"build-example": "pulp browserify -I example/src --to example/example.js"
8+
},
99
"devDependencies": {
1010
"eslint": "^3.19.0",
11-
"pulp": "^11.0.0",
12-
"purescript": "^0.11.4",
13-
"purescript-psa": "^0.5.1",
11+
"pulp": "^12.2.0",
12+
"purescript": "^0.12.0",
13+
"purescript-psa": "^0.6.0",
1414
"rimraf": "^2.6.1"
1515
},
1616
"dependencies": {

src/Clipboard.purs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,35 @@ module Clipboard
88

99
import Prelude
1010

11-
import Control.Monad.Eff (Eff)
12-
import DOM (DOM)
11+
import Effect (Effect)
1312
import CSS (Selector, selector)
14-
import DOM.Node.Types (Element)
13+
import Web.DOM.Element (Element)
1514

1615
foreign import data Clipboard :: Type
1716

1817
foreign import fromElement
19-
:: forall eff
20-
. Element
21-
-> Eff (dom :: DOM | eff) String
22-
-> Eff (dom :: DOM | eff) Clipboard
18+
:: Element
19+
-> Effect String
20+
-> Effect Clipboard
2321

2422
fromCSSSelector
25-
:: forall eff
26-
. Selector
27-
-> (Element -> Eff (dom :: DOM | eff) String)
28-
-> Eff (dom :: DOM | eff) Clipboard
23+
:: Selector
24+
-> (Element -> Effect String)
25+
-> Effect Clipboard
2926
fromCSSSelector = selector >>> fromStringSelector
3027

3128
foreign import fromStringSelector
32-
:: forall eff
33-
. String
34-
-> (Element -> Eff (dom :: DOM | eff) String)
35-
-> Eff (dom :: DOM | eff) Clipboard
29+
:: String
30+
-> (Element -> Effect String)
31+
-> Effect Clipboard
3632

3733
-- | Registers a click handler on an Event, which triggers the passed `Eff` and
3834
-- | copies the text inside the returned element to the clipboard.
3935
foreign import fromElementWithTarget
40-
:: forall eff
41-
. Element
42-
-> Eff (dom :: DOM | eff) Element
43-
-> Eff (dom :: DOM | eff) Clipboard
36+
:: Element
37+
-> Effect Element
38+
-> Effect Clipboard
4439

4540
foreign import destroy
46-
:: forall eff
47-
. Clipboard
48-
-> Eff (dom :: DOM | eff) Unit
41+
:: Clipboard
42+
-> Effect Unit

0 commit comments

Comments
 (0)