make use of the purescript-read lib instead of FromString class

This commit is contained in:
KtorZ 2017-07-27 23:37:25 +02:00
parent 86207adf61
commit 54bcd27d7b
No known key found for this signature in database
GPG Key ID: 3F72E8BC2894C015
3 changed files with 16 additions and 16 deletions

View File

@ -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",

View File

@ -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

View File

@ -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