From 54bcd27d7b611049e00610c0693e659a1dad6352 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Thu, 27 Jul 2017 23:37:25 +0200 Subject: [PATCH] make use of the purescript-read lib instead of FromString class --- bower.json | 8 ++++++-- src/Database/IndexedDB/Core.purs | 17 ++++++----------- src/Database/IndexedDB/IDBCursor.purs | 7 ++++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bower.json b/bower.json index 413e017..dd903a6 100644 --- a/bower.json +++ b/bower.json @@ -25,9 +25,13 @@ "url": "git://github.com/truqu/purescript-indexedDB.git" }, "dependencies": { - "purescript-maybe": "^3.0.0", "purescript-aff": "^3.1.0", - "purescript-datetime": "^3.2.0" + "purescript-datetime": "^3.2.0", + "purescript-eff": "^3.1.0", + "purescript-exceptions": "https://github.com/truqu/purescript-exceptions.git#3.1.0", + "purescript-maybe": "^3.0.0", + "purescript-prelude": "^3.1.0", + "purescript-read": "^1.0.0" }, "devDependencies": { "purescript-spec": "^1.0.0", diff --git a/src/Database/IndexedDB/Core.purs b/src/Database/IndexedDB/Core.purs index 6e26a96..6df4e82 100644 --- a/src/Database/IndexedDB/Core.purs +++ b/src/Database/IndexedDB/Core.purs @@ -8,8 +8,7 @@ -- | by the API. module Database.IndexedDB.Core - ( class FromString, parse - , IDB + ( IDB , CursorDirection(..) , CursorSource(..) , Database @@ -28,6 +27,7 @@ import Prelude (class Show) import Control.Monad.Eff (kind Effect) import Data.Maybe (Maybe(..)) +import Data.String.Read (class Read) import Database.IndexedDB.IDBKey @@ -109,11 +109,6 @@ foreign import data Transaction :: Type foreign import data ValueCursor :: Type --- | FromString represents enumerations that can be represented as Strings. -class FromString a where - parse :: String -> Maybe a - - foreign import _showCursor :: forall cursor. cursor -> String instance showKeyCursor :: Show KeyCursor where show = _showCursor @@ -175,8 +170,8 @@ instance showTransactionMode :: Show TransactionMode where VersionChange -> "versionchange" -instance fromStringCursorDirection :: FromString CursorDirection where - parse s = +instance readCursorDirection :: Read CursorDirection where + read s = case s of "next" -> Just Next "nextunique" -> Just NextUnique @@ -185,8 +180,8 @@ instance fromStringCursorDirection :: FromString CursorDirection where _ -> Nothing -instance fromStringTransactionMode :: FromString TransactionMode where - parse s = +instance readTransactionMode :: Read TransactionMode where + read s = case s of "readonly" -> Just ReadOnly "readwrite" -> Just ReadWrite diff --git a/src/Database/IndexedDB/IDBCursor.purs b/src/Database/IndexedDB/IDBCursor.purs index 76a4611..8da88de 100644 --- a/src/Database/IndexedDB/IDBCursor.purs +++ b/src/Database/IndexedDB/IDBCursor.purs @@ -16,11 +16,12 @@ module Database.IndexedDB.IDBCursor import Prelude (Unit, ($), (>>>), map) import Control.Monad.Aff (Aff) +import Data.Foreign (Foreign, toForeign, unsafeFromForeign) import Data.Function.Uncurried as Fn import Data.Function.Uncurried (Fn2, Fn3) import Data.Maybe (Maybe) import Data.Nullable (Nullable, toNullable) -import Data.Foreign (Foreign, toForeign, unsafeFromForeign) +import Data.String.Read (read) import Database.IndexedDB.Core import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key(..), toKey, extractForeign) @@ -80,7 +81,7 @@ direction' :: KeyCursor -> CursorDirection direction' = - Fn.runFn2 _direction (parse >>> toNullable) + Fn.runFn2 _direction (read >>> toNullable) -- | Returns the key of the cursor. Throws a "InvalidStateError" DOMException @@ -122,7 +123,7 @@ direction :: ValueCursor -> CursorDirection direction = - Fn.runFn2 _direction (parse >>> toNullable) + Fn.runFn2 _direction (read >>> toNullable) -- | Returns the key of the cursor. Throws a "InvalidStateError" DOMException