Skip to content

Commit

Permalink
change reference from Key to Foreign for FFI functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Jul 7, 2017
1 parent 3705bbc commit 808de4f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/Database/IndexedDB/IDBFactory.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Database.IndexedDB.Core
-- INTERFACE
--
-- Type alias for binding listeners to an initial open action.
type OpenRequest e =
type Callbacks e =
{ onBlocked :: Maybe (Eff (| e) Unit)
, onUpgradeNeeded :: Maybe (Database -> Transaction -> Eff (| e) Unit)
}
Expand Down Expand Up @@ -55,7 +55,7 @@ open
:: forall e e'
. DatabaseName
-> Maybe Version
-> OpenRequest e'
-> Callbacks e'
-> Aff (idb :: IDB | e) Database
open name mver req =
Fn.runFn4 _open fromMaybe name mver req
Expand All @@ -72,4 +72,4 @@ foreign import _deleteDatabase

foreign import _open
:: forall a e e'
. Fn4 (a -> Maybe a -> a) String (Maybe Int) (OpenRequest e') (Aff (idb :: IDB | e) Database)
. Fn4 (a -> Maybe a -> a) String (Maybe Int) (Callbacks e') (Aff (idb :: IDB | e) Database)
32 changes: 16 additions & 16 deletions src/Database/IndexedDB/IDBIndex/Internal.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ module Database.IndexedDB.IDBIndex.Internal where

import Prelude

import Control.Monad.Aff (Aff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (Error)
import Data.Foreign (Foreign, unsafeFromForeign)
import Data.Function.Uncurried as Fn
import Data.Function.Uncurried (Fn2, Fn3, Fn4)
import Data.Maybe (Maybe)
import Data.Nullable (Nullable, toMaybe, toNullable)
import Control.Monad.Aff (Aff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (Error)
import Data.Foreign (Foreign, unsafeFromForeign)
import Data.Function.Uncurried as Fn
import Data.Function.Uncurried (Fn2, Fn3, Fn4)
import Data.Maybe (Maybe)
import Data.Nullable (Nullable, toMaybe, toNullable)

import Database.IndexedDB.Core (IDB, CursorDirection, Index, Key, KeyCursor, KeyRange,
KeyPath, ObjectStore, ValueCursor)
import Database.IndexedDB.Core (IDB, CursorDirection, Index, Key, KeyCursor, KeyRange, KeyPath, ObjectStore, ValueCursor)
import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key(..))


--------------------
Expand Down Expand Up @@ -166,10 +166,10 @@ instance idbIndexIndex :: IDBIndex Index where
(toMaybe >>> map unsafeFromForeign) <$> Fn.runFn2 _get index range

getAllKeys index range count =
Fn.runFn3 _getAllKeys index (toNullable range) (toNullable count)
map Key <$> Fn.runFn3 _getAllKeys index (toNullable range) (toNullable count)

getKey index range =
toMaybe <$> Fn.runFn2 _getKey index range
(toMaybe >>> map Key) <$> Fn.runFn2 _getKey index range

openCursor index range dir cb =
Fn.runFn4 _openCursor index (toNullable range) (show dir) cb
Expand All @@ -186,10 +186,10 @@ instance idbIndexObjectStore :: IDBIndex ObjectStore where
(toMaybe >>> map unsafeFromForeign) <$> Fn.runFn2 _get store range

getAllKeys store range count =
Fn.runFn3 _getAllKeys store (toNullable range) (toNullable count)
map Key <$> Fn.runFn3 _getAllKeys store (toNullable range) (toNullable count)

getKey store range =
toMaybe <$> Fn.runFn2 _getKey store range
(toMaybe >>> map Key) <$> Fn.runFn2 _getKey store range

openCursor store range dir cb =
Fn.runFn4 _openCursor store (toNullable range) (show dir) cb
Expand Down Expand Up @@ -238,12 +238,12 @@ foreign import _get

foreign import _getAllKeys
:: forall index e
. Fn3 index (Nullable KeyRange) (Nullable Int) (Aff (idb :: IDB | e) (Array Key))
. Fn3 index (Nullable KeyRange) (Nullable Int) (Aff (idb :: IDB | e) (Array Foreign))


foreign import _getKey
:: forall index e
. Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Key))
. Fn2 index KeyRange (Aff (idb :: IDB | e) (Nullable Foreign))


foreign import _openCursor
Expand Down
38 changes: 26 additions & 12 deletions src/Database/IndexedDB/IDBKeyRange.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import Database.IndexedDB.IDBKey.Internal (class IDBKey, Key(..), toKey, extract
-- | The IDBKeyRange interface represents a key range.
class IDBKeyRange range where
-- | Returns true if key is included in the range, and false otherwise.
includes :: range -> Key -> Boolean

includes :: forall k. (IDBKey k) => range -> k -> Boolean

-- | Type alias for open
type Open = Boolean
Expand Down Expand Up @@ -121,34 +120,49 @@ upperOpen =
--
instance idbKeyRangeKeyRange :: IDBKeyRange KeyRange where
includes range =
extractForeign >>> Fn.runFn2 _includes range
toKey >>> extractForeign >>> Fn.runFn2 _includes range


--------------------
-- FFI
--
foreign import _bound :: Fn4 Foreign Foreign Boolean Boolean (Nullable KeyRange)
foreign import _bound
:: Fn4 Foreign Foreign Boolean Boolean (Nullable KeyRange)


foreign import _includes :: forall range. Fn2 range Foreign Boolean
foreign import _includes
:: forall range
. Fn2 range Foreign Boolean


foreign import _lower :: KeyRange -> Nullable Foreign
foreign import _lower
:: KeyRange
-> Nullable Foreign


foreign import _lowerBound :: Fn2 Foreign Boolean KeyRange
foreign import _lowerBound
:: Fn2 Foreign Boolean KeyRange


foreign import _lowerOpen :: KeyRange -> Boolean
foreign import _lowerOpen
:: KeyRange
-> Boolean


foreign import _only :: Foreign -> KeyRange
foreign import _only
:: Foreign
-> KeyRange


foreign import _upper :: KeyRange -> Nullable Foreign
foreign import _upper
:: KeyRange
-> Nullable Foreign


foreign import _upperBound :: Fn2 Foreign Boolean KeyRange
foreign import _upperBound
:: Fn2 Foreign Boolean KeyRange


foreign import _upperOpen :: KeyRange -> Boolean
foreign import _upperOpen
:: KeyRange
-> Boolean

0 comments on commit 808de4f

Please sign in to comment.