mirror of
https://github.com/ilyakooo0/purescript-indexedDB.git
synced 2024-09-11 06:55:48 +03:00
make use of the purescript-read lib instead of FromString class
This commit is contained in:
parent
86207adf61
commit
54bcd27d7b
@ -25,9 +25,13 @@
|
|||||||
"url": "git://github.com/truqu/purescript-indexedDB.git"
|
"url": "git://github.com/truqu/purescript-indexedDB.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"purescript-maybe": "^3.0.0",
|
|
||||||
"purescript-aff": "^3.1.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": {
|
"devDependencies": {
|
||||||
"purescript-spec": "^1.0.0",
|
"purescript-spec": "^1.0.0",
|
||||||
|
@ -8,8 +8,7 @@
|
|||||||
-- | by the API.
|
-- | by the API.
|
||||||
|
|
||||||
module Database.IndexedDB.Core
|
module Database.IndexedDB.Core
|
||||||
( class FromString, parse
|
( IDB
|
||||||
, IDB
|
|
||||||
, CursorDirection(..)
|
, CursorDirection(..)
|
||||||
, CursorSource(..)
|
, CursorSource(..)
|
||||||
, Database
|
, Database
|
||||||
@ -28,6 +27,7 @@ import Prelude (class Show)
|
|||||||
|
|
||||||
import Control.Monad.Eff (kind Effect)
|
import Control.Monad.Eff (kind Effect)
|
||||||
import Data.Maybe (Maybe(..))
|
import Data.Maybe (Maybe(..))
|
||||||
|
import Data.String.Read (class Read)
|
||||||
|
|
||||||
import Database.IndexedDB.IDBKey
|
import Database.IndexedDB.IDBKey
|
||||||
|
|
||||||
@ -109,11 +109,6 @@ foreign import data Transaction :: Type
|
|||||||
foreign import data ValueCursor :: 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
|
foreign import _showCursor :: forall cursor. cursor -> String
|
||||||
instance showKeyCursor :: Show KeyCursor where
|
instance showKeyCursor :: Show KeyCursor where
|
||||||
show = _showCursor
|
show = _showCursor
|
||||||
@ -175,8 +170,8 @@ instance showTransactionMode :: Show TransactionMode where
|
|||||||
VersionChange -> "versionchange"
|
VersionChange -> "versionchange"
|
||||||
|
|
||||||
|
|
||||||
instance fromStringCursorDirection :: FromString CursorDirection where
|
instance readCursorDirection :: Read CursorDirection where
|
||||||
parse s =
|
read s =
|
||||||
case s of
|
case s of
|
||||||
"next" -> Just Next
|
"next" -> Just Next
|
||||||
"nextunique" -> Just NextUnique
|
"nextunique" -> Just NextUnique
|
||||||
@ -185,8 +180,8 @@ instance fromStringCursorDirection :: FromString CursorDirection where
|
|||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
|
|
||||||
instance fromStringTransactionMode :: FromString TransactionMode where
|
instance readTransactionMode :: Read TransactionMode where
|
||||||
parse s =
|
read s =
|
||||||
case s of
|
case s of
|
||||||
"readonly" -> Just ReadOnly
|
"readonly" -> Just ReadOnly
|
||||||
"readwrite" -> Just ReadWrite
|
"readwrite" -> Just ReadWrite
|
||||||
|
@ -16,11 +16,12 @@ module Database.IndexedDB.IDBCursor
|
|||||||
import Prelude (Unit, ($), (>>>), map)
|
import Prelude (Unit, ($), (>>>), map)
|
||||||
|
|
||||||
import Control.Monad.Aff (Aff)
|
import Control.Monad.Aff (Aff)
|
||||||
|
import Data.Foreign (Foreign, toForeign, unsafeFromForeign)
|
||||||
import Data.Function.Uncurried as Fn
|
import Data.Function.Uncurried as Fn
|
||||||
import Data.Function.Uncurried (Fn2, Fn3)
|
import Data.Function.Uncurried (Fn2, Fn3)
|
||||||
import Data.Maybe (Maybe)
|
import Data.Maybe (Maybe)
|
||||||
import Data.Nullable (Nullable, toNullable)
|
import Data.Nullable (Nullable, toNullable)
|
||||||
import Data.Foreign (Foreign, toForeign, unsafeFromForeign)
|
import Data.String.Read (read)
|
||||||
|
|
||||||
import Database.IndexedDB.Core
|
import Database.IndexedDB.Core
|
||||||
import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key(..), toKey, extractForeign)
|
import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key(..), toKey, extractForeign)
|
||||||
@ -80,7 +81,7 @@ direction'
|
|||||||
:: KeyCursor
|
:: KeyCursor
|
||||||
-> CursorDirection
|
-> CursorDirection
|
||||||
direction' =
|
direction' =
|
||||||
Fn.runFn2 _direction (parse >>> toNullable)
|
Fn.runFn2 _direction (read >>> toNullable)
|
||||||
|
|
||||||
|
|
||||||
-- | Returns the key of the cursor. Throws a "InvalidStateError" DOMException
|
-- | Returns the key of the cursor. Throws a "InvalidStateError" DOMException
|
||||||
@ -122,7 +123,7 @@ direction
|
|||||||
:: ValueCursor
|
:: ValueCursor
|
||||||
-> CursorDirection
|
-> CursorDirection
|
||||||
direction =
|
direction =
|
||||||
Fn.runFn2 _direction (parse >>> toNullable)
|
Fn.runFn2 _direction (read >>> toNullable)
|
||||||
|
|
||||||
|
|
||||||
-- | Returns the key of the cursor. Throws a "InvalidStateError" DOMException
|
-- | Returns the key of the cursor. Throws a "InvalidStateError" DOMException
|
||||||
|
Loading…
Reference in New Issue
Block a user