From ea27dd9bf3c327500a8d2817502e076c1c0e5849 Mon Sep 17 00:00:00 2001 From: Jens Krause Date: Fri, 9 Jun 2017 17:45:57 +0200 Subject: [PATCH 1/6] Add `classList` + functions of `DOMTokenList` - Following functions of `DOMTokenList` are supported by modern browsers: * `add` * `remove` * `toggle` * `contains` * `item` - incl. tests --- bower.json | 7 +- package.json | 3 +- src/DOM/HTML/HTMLElement.js | 6 ++ src/DOM/HTML/HTMLElement.purs | 10 ++- src/DOM/Node/DOMTokenList.js | 51 +++++++++++ src/DOM/Node/DOMTokenList.purs | 31 +++++++ test/DOM/HTML/Window.purs | 2 +- test/DOM/Node/DomTokenList.purs | 155 ++++++++++++++++++++++++++++++++ test/Main.purs | 25 +++--- 9 files changed, 272 insertions(+), 18 deletions(-) create mode 100644 src/DOM/Node/DOMTokenList.js create mode 100644 src/DOM/Node/DOMTokenList.purs create mode 100644 test/DOM/Node/DomTokenList.purs diff --git a/bower.json b/bower.json index 74255db..89b0e47 100644 --- a/bower.json +++ b/bower.json @@ -31,5 +31,10 @@ "purescript-nullable": "^3.0.0", "purescript-prelude": "^3.0.0", "purescript-unsafe-coerce": "^3.0.0" - } + }, + "devDependencies": { + "purescript-test-unit": "^11.0.0", + "purescript-phantom": "^2.0.0", + "purescript-exitcodes": "^3.0.0" + } } diff --git a/package.json b/package.json index 6a89f99..bbb47ef 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "private": true, "scripts": { "clean": "rimraf output && rimraf .pulp-cache", - "build": "eslint src && pulp build -- --censor-lib --strict" + "build": "eslint src && pulp build -- --censor-lib --strict", + "test": "PHANTOM_TEST_PATH=$(pwd) pulp test --runtime phantomjs" }, "devDependencies": { "eslint": "^3.19.0", diff --git a/src/DOM/HTML/HTMLElement.js b/src/DOM/HTML/HTMLElement.js index 6fffb89..f5aa96f 100644 --- a/src/DOM/HTML/HTMLElement.js +++ b/src/DOM/HTML/HTMLElement.js @@ -68,6 +68,12 @@ exports.setClassName = function (className) { }; }; +exports.classList = function (element) { + return function () { + return element.classList; + }; +}; + // ---------------------------------------------------------------------------- exports.hidden = function (elt) { diff --git a/src/DOM/HTML/HTMLElement.purs b/src/DOM/HTML/HTMLElement.purs index 950a6c9..bb35fcc 100644 --- a/src/DOM/HTML/HTMLElement.purs +++ b/src/DOM/HTML/HTMLElement.purs @@ -7,6 +7,7 @@ module DOM.HTML.HTMLElement , setDir , className , setClassName + , classList , hidden , setHidden , tabIndex @@ -30,12 +31,13 @@ module DOM.HTML.HTMLElement ) where import Prelude + import Control.Monad.Eff (Eff) -import Data.Nullable (Nullable, toMaybe) -import Data.Maybe (Maybe) import DOM (DOM) import DOM.HTML.Types (HTMLElement) -import DOM.Node.Types (Element) +import DOM.Node.Types (DOMTokenList, Element) +import Data.Maybe (Maybe) +import Data.Nullable (Nullable, toMaybe) foreign import title :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) String foreign import setTitle :: forall eff. String -> HTMLElement -> Eff (dom :: DOM | eff) Unit @@ -49,6 +51,8 @@ foreign import setDir :: forall eff. String -> HTMLElement -> Eff (dom :: DOM | foreign import className :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) String foreign import setClassName :: forall eff. String -> HTMLElement -> Eff (dom :: DOM | eff) Unit +foreign import classList :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) DOMTokenList + foreign import hidden :: forall eff. HTMLElement -> Eff (dom :: DOM | eff) Boolean foreign import setHidden :: forall eff. Boolean -> HTMLElement -> Eff (dom :: DOM | eff) Unit diff --git a/src/DOM/Node/DOMTokenList.js b/src/DOM/Node/DOMTokenList.js new file mode 100644 index 0000000..2e96ef9 --- /dev/null +++ b/src/DOM/Node/DOMTokenList.js @@ -0,0 +1,51 @@ +"use strict"; + +exports.add = function(token) { + return function(list) { + return function() { + return list.add(token); + }; + }; +}; + +exports.remove = function(token) { + return function(list) { + return function() { + return list.remove(token); + }; + }; +}; + +exports.contains = function(token) { + return function(list) { + return function() { + return list.contains(token); + }; + }; +}; + +exports.toggle = function(token) { + return function(list) { + return function() { + return list.toggle(token); + }; + }; +}; + +exports.toggleForce = function(token) { + return function(force) { + return function(list) { + return function() { + return list.toggle(token, force); + }; + }; + }; +}; + +exports._item = function(index) { + return function(list) { + return function() { + return list.item(index); + }; + }; +}; diff --git a/src/DOM/Node/DOMTokenList.purs b/src/DOM/Node/DOMTokenList.purs new file mode 100644 index 0000000..1ffe9fe --- /dev/null +++ b/src/DOM/Node/DOMTokenList.purs @@ -0,0 +1,31 @@ +module DOM.Node.ClassList + ( add + , contains + , item + , remove + , toggle + , toggleForce + ) where + +import Prelude + +import Control.Monad.Eff (Eff) +import DOM (DOM) +import DOM.Node.Types (DOMTokenList) +import Data.Maybe (Maybe) +import Data.Nullable (Nullable, toMaybe) + +foreign import add :: forall eff. String -> DOMTokenList -> Eff (dom :: DOM | eff) Unit + +foreign import remove :: forall eff. String -> DOMTokenList -> Eff (dom :: DOM | eff) Unit + +foreign import contains :: forall eff. String -> DOMTokenList -> Eff (dom :: DOM | eff) Boolean + +foreign import toggle :: forall eff. String -> DOMTokenList -> Eff (dom :: DOM | eff) Boolean + +foreign import toggleForce :: forall eff. String -> Boolean -> DOMTokenList -> Eff (dom :: DOM | eff) Boolean + +foreign import _item :: forall eff. Int -> DOMTokenList -> Eff (dom :: DOM | eff) (Nullable String) + +item :: forall eff. Int -> DOMTokenList -> Eff (dom :: DOM | eff) (Maybe String) +item index = map toMaybe <<< _item index diff --git a/test/DOM/HTML/Window.purs b/test/DOM/HTML/Window.purs index 9bb6a11..12bdbe7 100644 --- a/test/DOM/HTML/Window.purs +++ b/test/DOM/HTML/Window.purs @@ -1,6 +1,6 @@ module Test.DOM.HTML.Window where -import Prelude (Unit, bind, (<<<)) +import Prelude (Unit, bind, (<<<), discard) import DOM (DOM) import DOM.HTML (window) import DOM.HTML.Types (WINDOW) diff --git a/test/DOM/Node/DomTokenList.purs b/test/DOM/Node/DomTokenList.purs new file mode 100644 index 0000000..c3edbdf --- /dev/null +++ b/test/DOM/Node/DomTokenList.purs @@ -0,0 +1,155 @@ +module Test.DOM.Node.DOMTokenList where + +import Prelude + +import Control.Monad.Aff.Console (CONSOLE) +import Control.Monad.Eff.Class (liftEff) +import Control.Monad.Free (Free) +import DOM (DOM) +import DOM.HTML (window) +import DOM.HTML.Document (body) +import DOM.HTML.HTMLElement (classList, className, setClassName) +import DOM.HTML.Types (WINDOW) +import DOM.HTML.Window (document) +import DOM.Node.ClassList (add, contains, remove, toggle, toggleForce, item) as CL +import Data.Maybe (Maybe(..), fromMaybe) +import Test.Unit (TestF, describe, it) +import Test.Unit.Assert (shouldEqual) + +domTokenListTests :: forall eff. Free (TestF (dom :: DOM, console :: CONSOLE, + window :: WINDOW | eff)) Unit +domTokenListTests = do + describe "DOMTokenList of classList" do + it "contains a token" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b c" body'' + list <- classList body'' + CL.contains "a" list + Nothing -> pure false + + result `shouldEqual` true + + it "adds a token" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + -- clear class names, first + _ <- setClassName "" body'' + list <- classList body'' + _ <- CL.add "a" list + className body'' + Nothing -> pure "failed" + + result `shouldEqual` "a" + + it "removes a token" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b c" body'' + list <- classList body'' + _ <- CL.remove "b" list + resultA <- CL.contains "a" list + resultB <- CL.contains "b" list + resultC <- CL.contains "c" list + -- Only "b" should be removed + pure $ resultA && not resultB && resultC + Nothing -> pure false + + result `shouldEqual` true + + it "toggles a token by removing its value" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b c" body'' + list <- classList body'' + _ <- CL.toggle "c" list + className body'' + Nothing -> pure "failed" + + result `shouldEqual` "a b" + + it "toggles a token by adding its value" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b" body'' + list <- classList body'' + _ <- CL.toggle "c" list + className body'' + Nothing -> pure "failed" + + result `shouldEqual` "a b c" + + it "toggles a token by forcing to add its value" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b" body'' + list <- classList body'' + _ <- CL.toggleForce "c" true list + className body'' + Nothing -> pure "failed" + + result `shouldEqual` "a b c" + + it "toggles a token by forcing to add (but not to remove) its value" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b c" body'' + list <- classList body'' + _ <- CL.toggleForce "c" true list + className body'' + Nothing -> pure "failed" + + result `shouldEqual` "a b c" + + it "toggles a token by forcing to remove its value" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b c" body'' + list <- classList body'' + _ <- CL.toggleForce "c" false list + className body'' + Nothing -> pure "failed" + + result `shouldEqual` "a b" + + it "toggles a token by forcing to remove (but not to add) its value" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b" body'' + list <- classList body'' + _ <- CL.toggleForce "c" false list + className body'' + Nothing -> pure "failed" + + result `shouldEqual` "a b" + + it "returns an item if available" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b c" body'' + list <- classList body'' + CL.item 2 list + Nothing -> pure Nothing + + (fromMaybe "not found" result) `shouldEqual` "c" + + it "returns not an item if it's not available" do + body' <- liftEff $ window >>= document >>= body + result <- case body' of + Just body'' -> liftEff do + _ <- setClassName "a b c" body'' + list <- classList body'' + CL.item 5 list + Nothing -> pure Nothing + + (fromMaybe "not found" result) `shouldEqual` "not found" diff --git a/test/Main.purs b/test/Main.purs index 83a4920..2920a9c 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,33 +1,34 @@ module Test.Main where -import Prelude (($), bind) +import Control.Monad.Aff (launchAff, Canceler) +import Control.Monad.Aff.AVar (AVAR) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Class (liftEff) +import Control.Monad.Eff.Console (CONSOLE) +import Control.Monad.Eff.Exception (EXCEPTION) import DOM (DOM) import DOM.HTML.Types (WINDOW) import Data.Enum (fromEnum) import ExitCodes (ExitCode(Success)) import PhantomJS.Phantom (exit, PHANTOMJS) -import Control.Monad.Aff (Aff, launchAff, Canceler) -import Control.Monad.Eff.Class (liftEff) as EffClass -import Control.Monad.Aff.AVar (AVAR) -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE) -import Control.Monad.Eff.Exception (EXCEPTION) +import Prelude (($), discard) +import Test.DOM.HTML.Window (domHtmlWindowTests) +import Test.DOM.Node.DOMTokenList (domTokenListTests) import Test.Unit (describe, it) import Test.Unit.Assert (assert) import Test.Unit.Output.Simple (runTest) -import Test.DOM.HTML.Window (domHtmlWindowTests) - -liftEff :: forall eff a. Eff (phantomjs :: PHANTOMJS | eff) a -> Aff (phantomjs :: PHANTOMJS | eff) a -liftEff = EffClass.liftEff +-- liftEff :: forall eff a. Eff (phantomjs :: PHANTOMJS | eff) a -> Aff (phantomjs :: PHANTOMJS | eff) a +-- liftEff = EffClass.liftEff main :: forall eff - . Eff (err :: EXCEPTION, console :: CONSOLE, avar :: AVAR, dom :: DOM, window :: WINDOW, phantomjs :: PHANTOMJS | eff) + . Eff (exception :: EXCEPTION, console :: CONSOLE, avar :: AVAR, dom :: DOM, window :: WINDOW, phantomjs :: PHANTOMJS | eff) (Canceler (console :: CONSOLE, avar :: AVAR, dom :: DOM, window :: WINDOW, phantomjs :: PHANTOMJS | eff)) main = launchAff $ runTest do domHtmlWindowTests + domTokenListTests describe "exit" $ do it "should exit" $ do From 921b39baad29bd106de5442258791150692e11b2 Mon Sep 17 00:00:00 2001 From: Jens Krause Date: Fri, 9 Jun 2017 15:36:57 +0200 Subject: [PATCH 2/6] Add test dependencies which was removed by `522e1d6` before. Also add test script to `package.json` to run tests. --- bower.json | 2 +- test/Main.purs | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index 89b0e47..fa08ac9 100644 --- a/bower.json +++ b/bower.json @@ -36,5 +36,5 @@ "purescript-test-unit": "^11.0.0", "purescript-phantom": "^2.0.0", "purescript-exitcodes": "^3.0.0" - } + } } diff --git a/test/Main.purs b/test/Main.purs index 2920a9c..13c0c44 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,5 +1,6 @@ module Test.Main where +import Prelude (($), discard) import Control.Monad.Aff (launchAff, Canceler) import Control.Monad.Aff.AVar (AVAR) import Control.Monad.Eff (Eff) @@ -11,17 +12,12 @@ import DOM.HTML.Types (WINDOW) import Data.Enum (fromEnum) import ExitCodes (ExitCode(Success)) import PhantomJS.Phantom (exit, PHANTOMJS) -import Prelude (($), discard) import Test.DOM.HTML.Window (domHtmlWindowTests) import Test.DOM.Node.DOMTokenList (domTokenListTests) import Test.Unit (describe, it) import Test.Unit.Assert (assert) import Test.Unit.Output.Simple (runTest) - --- liftEff :: forall eff a. Eff (phantomjs :: PHANTOMJS | eff) a -> Aff (phantomjs :: PHANTOMJS | eff) a --- liftEff = EffClass.liftEff - main :: forall eff . Eff (exception :: EXCEPTION, console :: CONSOLE, avar :: AVAR, dom :: DOM, window :: WINDOW, phantomjs :: PHANTOMJS | eff) From 2aded22705d6cb6402a367199af42d441014abd7 Mon Sep 17 00:00:00 2001 From: Christoph Hegemann Date: Sat, 10 Jun 2017 10:07:11 +0200 Subject: [PATCH 3/6] Fix repository links --- bower.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index fa08ac9..04e69c7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "purescript-dom", - "homepage": "https://github.com/purescript-contrib/purescript-dom", + "homepage": "https://github.com/purescript-web/purescript-dom", "description": "PureScript type definitions and effect for interacting with the DOM", "keywords": [ "purescript" @@ -8,7 +8,7 @@ "license": "MIT", "repository": { "type": "git", - "url": "git://github.com/purescript-contrib/purescript-dom.git" + "url": "git://github.com/purescript-web/purescript-dom.git" }, "ignore": [ "**/.*", From ecc6d9f272b4c940b9f58c1a2952e7e12c94ce69 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sat, 10 Jun 2017 20:12:00 +0100 Subject: [PATCH 4/6] Create README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1fc1c56..2dd377a 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # purescript-dom -[![Latest release](http://img.shields.io/github/release/purescript-contrib/purescript-dom.svg)](https://github.com/purescript-contrib/purescript-dom/releases) -[![Build status](https://travis-ci.org/purescript-contrib/purescript-dom.svg?branch=master)](https://travis-ci.org/purescript-contrib/purescript-dom) +[![Latest release](http://img.shields.io/github/release/purescript-web/purescript-dom.svg)](https://github.com/purescript-web/purescript-dom/releases) +[![Build status](https://travis-ci.org/purescript-web/purescript-dom.svg?branch=master)](https://travis-ci.org/purescript-web/purescript-dom) [![Maintainer: garyb](https://img.shields.io/badge/maintainer-garyb-lightgrey.svg)](http://github.com/garyb) Type definitions, low level interface implementations, and standard effect type for use while interacting with the DOM. @@ -21,9 +21,9 @@ The API isn't primarily intended for "human consumption", but instead aims to pr This consists of: - `foreign data` types for the various interfaces described. - Functions that read `Foreign` typed values (and `IsForeign` instances) for foreign types. -- No classes or other niceties to aid with subtyping relationships. However, coercions are provided from subtypes to their supertypes. For example, from `DOM.Node.Types`, [`elementToNode`](https://github.com/purescript-contrib/purescript-dom/blob/master/docs/DOM/Node/Types.md#elementtonode). +- No classes or other niceties to aid with subtyping relationships. However, coercions are provided from subtypes to their supertypes. For example, from `DOM.Node.Types`, [`elementToNode`](https://github.com/purescript-web/purescript-dom/blob/master/docs/DOM/Node/Types.md#elementtonode). - Functions that can mutate the DOM, or that don't always return the same value, or return a value that may be mutated at a distance use `Eff` with the `DOM` effect -- Enumeration values are provided as ADTs, but with an option to read the raw value too. For example, from `DOM.Node.Node`, [`nodeType`](https://github.com/purescript-contrib/purescript-dom/blob/master/docs/DOM/Node/Node.md#nodetype) and [`nodeTypeIndex`](https://github.com/purescript-contrib/purescript-dom/blob/master/docs/DOM/Node/Node.md#nodetypeindex). +- Enumeration values are provided as ADTs, but with an option to read the raw value too. For example, from `DOM.Node.Node`, [`nodeType`](https://github.com/purescript-web/purescript-dom/blob/master/docs/DOM/Node/Node.md#nodetype) and [`nodeTypeIndex`](https://github.com/purescript-web/purescript-dom/blob/master/docs/DOM/Node/Node.md#nodetypeindex). ## Module structure From 56ecd6fa197387d7a6654e0b9669b6b2887e2e82 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 23 Apr 2017 23:12:12 +0200 Subject: [PATCH 5/6] Documentation fixes for functions that now return Maybe --- src/DOM/Node/HTMLCollection.purs | 4 ++-- src/DOM/Node/Node.purs | 10 +++++----- src/DOM/Node/NodeList.purs | 2 +- src/DOM/Node/NonDocumentTypeChildNode.purs | 4 ++-- src/DOM/Node/ParentNode.purs | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/DOM/Node/HTMLCollection.purs b/src/DOM/Node/HTMLCollection.purs index 27e07a6..1401ad1 100644 --- a/src/DOM/Node/HTMLCollection.purs +++ b/src/DOM/Node/HTMLCollection.purs @@ -14,7 +14,7 @@ import DOM.Node.Types (Element, HTMLCollection, ElementId) -- | The number of elements in a HTMLCollection. foreign import length :: forall eff. HTMLCollection -> Eff (dom :: DOM | eff) Int --- | The element in a HTMLCollection at the specified index, or null if no such +-- | The element in a HTMLCollection at the specified index, or Nothing if no such -- | element exists. item :: forall eff. Int -> HTMLCollection -> Eff (dom :: DOM | eff) (Maybe Element) item i = map toMaybe <<< _item i @@ -22,7 +22,7 @@ item i = map toMaybe <<< _item i foreign import _item :: forall eff. Int -> HTMLCollection -> Eff (dom :: DOM | eff) (Nullable Element) -- | The first element with the specified name or ID in a HTMLCollection, or --- | null if no such element exists. +-- | Nothing if no such element exists. namedItem :: forall eff. ElementId -> HTMLCollection -> Eff (dom :: DOM | eff) (Maybe Element) namedItem id = map toMaybe <<< _namedItem id diff --git a/src/DOM/Node/Node.purs b/src/DOM/Node/Node.purs index 7fa9605..2fed434 100644 --- a/src/DOM/Node/Node.purs +++ b/src/DOM/Node/Node.purs @@ -57,7 +57,7 @@ foreign import nodeName :: Node -> String foreign import baseURI :: forall eff. Node -> Eff (dom :: DOM | eff) String -- | The document the node belongs to, unless the node is a document in which --- | case the value is null. +-- | case the value is Nothing. ownerDocument :: forall eff. Node -> Eff (dom :: DOM | eff) (Maybe Document) ownerDocument = map toMaybe <<< _ownerDocument @@ -81,26 +81,26 @@ foreign import hasChildNodes :: forall eff. Node -> Eff (dom :: DOM | eff) Boole -- | The children of the node. foreign import childNodes :: forall eff. Node -> Eff (dom :: DOM | eff) NodeList --- | The first child of the node, or null if the node has no children. +-- | The first child of the node, or Nothing if the node has no children. firstChild :: forall eff. Node -> Eff (dom :: DOM | eff) (Maybe Node) firstChild = map toMaybe <<< _firstChild foreign import _firstChild :: forall eff. Node -> Eff (dom :: DOM | eff) (Nullable Node) --- | The last child of the node, or null if the node has no children. +-- | The last child of the node, or Nothing if the node has no children. lastChild :: forall eff. Node -> Eff (dom :: DOM | eff) (Maybe Node) lastChild = map toMaybe <<< _lastChild foreign import _lastChild :: forall eff. Node -> Eff (dom :: DOM | eff) (Nullable Node) --- | The previous sibling node, or null if there is no previous sibling. +-- | The previous sibling node, or Nothing if there is no previous sibling. previousSibling :: forall eff. Node -> Eff (dom :: DOM | eff) (Maybe Node) previousSibling = map toMaybe <<< _previousSibling foreign import _previousSibling :: forall eff. Node -> Eff (dom :: DOM | eff) (Nullable Node) --- | The next sibling node, or null if there is no next sibling. +-- | The next sibling node, or Nothing if there is no next sibling. nextSibling :: forall eff. Node -> Eff (dom :: DOM | eff) (Maybe Node) nextSibling = map toMaybe <<< _nextSibling diff --git a/src/DOM/Node/NodeList.purs b/src/DOM/Node/NodeList.purs index 2b96061..2777b98 100644 --- a/src/DOM/Node/NodeList.purs +++ b/src/DOM/Node/NodeList.purs @@ -13,7 +13,7 @@ import DOM.Node.Types (Node, NodeList) -- | The number of items in a NodeList. foreign import length :: forall eff. NodeList -> Eff (dom :: DOM | eff) Int --- | The item in a NodeList at the specified index, or null if no such node +-- | The item in a NodeList at the specified index, or Nothing if no such node -- | exists. item :: forall eff. Int -> NodeList -> Eff (dom :: DOM | eff) (Maybe Node) item i = map toMaybe <<< _item i diff --git a/src/DOM/Node/NonDocumentTypeChildNode.purs b/src/DOM/Node/NonDocumentTypeChildNode.purs index 621ba58..6b6a625 100644 --- a/src/DOM/Node/NonDocumentTypeChildNode.purs +++ b/src/DOM/Node/NonDocumentTypeChildNode.purs @@ -10,13 +10,13 @@ import Data.Nullable (Nullable, toMaybe) import DOM (DOM) import DOM.Node.Types (Element, NonDocumentTypeChildNode) --- | The previous sibling that is an element, or null if no such element exists. +-- | The previous sibling that is an element, or Nothing if no such element exists. previousElementSibling :: forall eff. NonDocumentTypeChildNode -> Eff (dom :: DOM | eff) (Maybe Element) previousElementSibling = map toMaybe <<< _previousElementSibling foreign import _previousElementSibling :: forall eff. NonDocumentTypeChildNode -> Eff (dom :: DOM | eff) (Nullable Element) --- | The next sibling that is an element, or null if no such element exists. +-- | The next sibling that is an element, or Nothing if no such element exists. nextElementSibling :: forall eff. NonDocumentTypeChildNode -> Eff (dom :: DOM | eff) (Maybe Element) nextElementSibling = map toMaybe <<< _nextElementSibling diff --git a/src/DOM/Node/ParentNode.purs b/src/DOM/Node/ParentNode.purs index dccaf76..01320fc 100644 --- a/src/DOM/Node/ParentNode.purs +++ b/src/DOM/Node/ParentNode.purs @@ -22,13 +22,13 @@ import DOM.Node.Types (NodeList, ParentNode, Element, HTMLCollection) -- | The child elements for the node. foreign import children :: forall eff. ParentNode -> Eff (dom :: DOM | eff) HTMLCollection --- | The first child that is an element, or null if no such element exists. +-- | The first child that is an element, or Nothing if no such element exists. firstElementChild :: forall eff. ParentNode -> Eff (dom :: DOM | eff) (Maybe Element) firstElementChild = map toMaybe <<< _firstElementChild foreign import _firstElementChild :: forall eff. ParentNode -> Eff (dom :: DOM | eff) (Nullable Element) --- | The last child that is an element, or null if no such element exists. +-- | The last child that is an element, or Nothing if no such element exists. lastElementChild :: forall eff. ParentNode -> Eff (dom :: DOM | eff) (Maybe Element) lastElementChild = map toMaybe <<< _lastElementChild @@ -44,7 +44,7 @@ derive newtype instance ordQuerySelector :: Ord QuerySelector derive instance newtypeQuerySelector :: Newtype QuerySelector _ -- | Finds the first child that is an element that matches the selector(s), or --- | null if no such element exists. +-- | Nothing if no such element exists. querySelector :: forall eff. QuerySelector -> ParentNode -> Eff (dom :: DOM | eff) (Maybe Element) querySelector qs = map toMaybe <<< _querySelector qs From c32048aa8d4353bb4ac4a0c2c123cbf1c1e29cf4 Mon Sep 17 00:00:00 2001 From: Jens Krause Date: Sun, 11 Jun 2017 10:23:40 +0200 Subject: [PATCH 6/6] Rearrange arguments of `DOMTokenList` functions --- src/DOM/Node/DOMTokenList.js | 26 +++++++++++++------------- src/DOM/Node/DOMTokenList.purs | 14 +++++++------- test/DOM/Node/DomTokenList.purs | 28 ++++++++++++++-------------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/DOM/Node/DOMTokenList.js b/src/DOM/Node/DOMTokenList.js index 2e96ef9..a8fe4fb 100644 --- a/src/DOM/Node/DOMTokenList.js +++ b/src/DOM/Node/DOMTokenList.js @@ -1,40 +1,40 @@ "use strict"; -exports.add = function(token) { - return function(list) { +exports.add = function(list) { + return function(token) { return function() { return list.add(token); }; }; }; -exports.remove = function(token) { - return function(list) { +exports.remove = function(list) { + return function(token) { return function() { return list.remove(token); }; }; }; -exports.contains = function(token) { - return function(list) { +exports.contains = function(list) { + return function(token) { return function() { return list.contains(token); }; }; }; -exports.toggle = function(token) { - return function(list) { +exports.toggle = function(list) { + return function(token) { return function() { return list.toggle(token); }; }; }; -exports.toggleForce = function(token) { - return function(force) { - return function(list) { +exports.toggleForce = function(list) { + return function(token) { + return function(force) { return function() { return list.toggle(token, force); }; @@ -42,8 +42,8 @@ exports.toggleForce = function(token) { }; }; -exports._item = function(index) { - return function(list) { +exports._item = function(list) { + return function(index) { return function() { return list.item(index); }; diff --git a/src/DOM/Node/DOMTokenList.purs b/src/DOM/Node/DOMTokenList.purs index 1ffe9fe..0d49ad5 100644 --- a/src/DOM/Node/DOMTokenList.purs +++ b/src/DOM/Node/DOMTokenList.purs @@ -15,17 +15,17 @@ import DOM.Node.Types (DOMTokenList) import Data.Maybe (Maybe) import Data.Nullable (Nullable, toMaybe) -foreign import add :: forall eff. String -> DOMTokenList -> Eff (dom :: DOM | eff) Unit +foreign import add :: forall eff. DOMTokenList -> String -> Eff (dom :: DOM | eff) Unit -foreign import remove :: forall eff. String -> DOMTokenList -> Eff (dom :: DOM | eff) Unit +foreign import remove :: forall eff. DOMTokenList -> String -> Eff (dom :: DOM | eff) Unit -foreign import contains :: forall eff. String -> DOMTokenList -> Eff (dom :: DOM | eff) Boolean +foreign import contains :: forall eff. DOMTokenList -> String -> Eff (dom :: DOM | eff) Boolean -foreign import toggle :: forall eff. String -> DOMTokenList -> Eff (dom :: DOM | eff) Boolean +foreign import toggle :: forall eff. DOMTokenList -> String -> Eff (dom :: DOM | eff) Boolean -foreign import toggleForce :: forall eff. String -> Boolean -> DOMTokenList -> Eff (dom :: DOM | eff) Boolean +foreign import toggleForce :: forall eff. DOMTokenList -> String -> Boolean -> Eff (dom :: DOM | eff) Boolean -foreign import _item :: forall eff. Int -> DOMTokenList -> Eff (dom :: DOM | eff) (Nullable String) +foreign import _item :: forall eff. DOMTokenList -> Int -> Eff (dom :: DOM | eff) (Nullable String) -item :: forall eff. Int -> DOMTokenList -> Eff (dom :: DOM | eff) (Maybe String) +item :: forall eff. DOMTokenList -> Int -> Eff (dom :: DOM | eff) (Maybe String) item index = map toMaybe <<< _item index diff --git a/test/DOM/Node/DomTokenList.purs b/test/DOM/Node/DomTokenList.purs index c3edbdf..88b1885 100644 --- a/test/DOM/Node/DomTokenList.purs +++ b/test/DOM/Node/DomTokenList.purs @@ -26,7 +26,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b c" body'' list <- classList body'' - CL.contains "a" list + CL.contains list "a" Nothing -> pure false result `shouldEqual` true @@ -38,7 +38,7 @@ domTokenListTests = do -- clear class names, first _ <- setClassName "" body'' list <- classList body'' - _ <- CL.add "a" list + _ <- CL.add list "a" className body'' Nothing -> pure "failed" @@ -50,10 +50,10 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b c" body'' list <- classList body'' - _ <- CL.remove "b" list - resultA <- CL.contains "a" list - resultB <- CL.contains "b" list - resultC <- CL.contains "c" list + _ <- CL.remove list "b" + resultA <- CL.contains list "a" + resultB <- CL.contains list "b" + resultC <- CL.contains list "c" -- Only "b" should be removed pure $ resultA && not resultB && resultC Nothing -> pure false @@ -66,7 +66,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b c" body'' list <- classList body'' - _ <- CL.toggle "c" list + _ <- CL.toggle list "c" className body'' Nothing -> pure "failed" @@ -78,7 +78,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b" body'' list <- classList body'' - _ <- CL.toggle "c" list + _ <- CL.toggle list "c" className body'' Nothing -> pure "failed" @@ -90,7 +90,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b" body'' list <- classList body'' - _ <- CL.toggleForce "c" true list + _ <- CL.toggleForce list "c" true className body'' Nothing -> pure "failed" @@ -102,7 +102,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b c" body'' list <- classList body'' - _ <- CL.toggleForce "c" true list + _ <- CL.toggleForce list "c" true className body'' Nothing -> pure "failed" @@ -114,7 +114,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b c" body'' list <- classList body'' - _ <- CL.toggleForce "c" false list + _ <- CL.toggleForce list "c" false className body'' Nothing -> pure "failed" @@ -126,7 +126,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b" body'' list <- classList body'' - _ <- CL.toggleForce "c" false list + _ <- CL.toggleForce list "c" false className body'' Nothing -> pure "failed" @@ -138,7 +138,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b c" body'' list <- classList body'' - CL.item 2 list + CL.item list 2 Nothing -> pure Nothing (fromMaybe "not found" result) `shouldEqual` "c" @@ -149,7 +149,7 @@ domTokenListTests = do Just body'' -> liftEff do _ <- setClassName "a b c" body'' list <- classList body'' - CL.item 5 list + CL.item list 5 Nothing -> pure Nothing (fromMaybe "not found" result) `shouldEqual` "not found"