remove Synchronous / Asynchronous type and pass fromMaybe as dependency

This commit is contained in:
KtorZ 2017-06-23 10:31:11 +02:00
parent a20d12741a
commit 521f354802
No known key found for this signature in database
GPG Key ID: 3F72E8BC2894C015
6 changed files with 24 additions and 28 deletions

View File

@ -11,12 +11,13 @@
"PS": true
},
"rules": {
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": 0,
"indent": ["error", 4],
"no-param-reassign": 0,
"import/no-unresolved": 0,
"no-underscore-dangle": 0,
"prefer-template": 0,
"no-var": 0,
"object-shorthand": 0,
"no-var": 0
"prefer-template": 0
}
}

View File

@ -6,9 +6,6 @@ import Control.Monad.Aff(Aff)
import Control.Monad.Eff(kind Effect, Eff)
import Control.Monad.Eff.Exception(EXCEPTION)
type Synchronous eff a = Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) a
type Asynchronous eff a = Aff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) a
foreign import data INDEXED_DB :: Effect

View File

@ -1,4 +1,3 @@
const Maybe = require('Data.Maybe');
const Core = require('Database.IndexedDB.Core');
const $Core = require('Database.IndexedDB.Core/foreign');
@ -15,8 +14,8 @@ exports.close = function close(db) {
};
};
exports._createObjectStore = function _createObjectStore(db, name, opts) {
const keyPath = Maybe.fromMaybe(undefined)(opts.keyPath);
exports._createObjectStore = function _createObjectStore(fromMaybe, db, name, opts) {
const keyPath = fromMaybe(undefined)(opts.keyPath);
const autoIncrement = opts.autoIncrement;
return function eff() {

View File

@ -6,23 +6,23 @@ import Control.Monad.Aff(Aff)
import Control.Monad.Eff(Eff)
import Control.Monad.Eff.Exception(EXCEPTION)
import Data.Function.Uncurried as Fn
import Data.Function.Uncurried(Fn2, Fn3)
import Data.Maybe(Maybe)
import Data.Function.Uncurried(Fn2, Fn3, Fn4)
import Data.Maybe(Maybe, fromMaybe)
import Database.IndexedDB.Core
foreign import close :: forall eff. IDBDatabase -> Synchronous eff Unit
foreign import close :: forall eff. IDBDatabase -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) Unit
foreign import _createObjectStore :: forall eff. Fn3 IDBDatabase String { keyPath :: Maybe String, autoIncrement :: Boolean } (Synchronous eff IDBObjectStore)
createObjectStore :: forall eff . IDBDatabase -> String -> { keyPath :: Maybe String, autoIncrement :: Boolean } -> Synchronous eff IDBObjectStore
foreign import _createObjectStore :: forall a eff. Fn4 (a -> Maybe a -> a) IDBDatabase String { keyPath :: Maybe String, autoIncrement :: Boolean } (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore)
createObjectStore :: forall eff. IDBDatabase -> String -> { keyPath :: Maybe String, autoIncrement :: Boolean } -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore
createObjectStore db name opts =
Fn.runFn3 _createObjectStore db name opts
Fn.runFn4 _createObjectStore fromMaybe db name opts
foreign import _deleteObjectStore :: forall eff. Fn2 IDBDatabase String (Synchronous eff IDBObjectStore)
deleteObjectStore :: forall eff . IDBDatabase -> String -> Synchronous eff IDBObjectStore
foreign import _deleteObjectStore :: forall eff. Fn2 IDBDatabase String (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore)
deleteObjectStore :: forall eff . IDBDatabase -> String -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBObjectStore
deleteObjectStore db name =
Fn.runFn2 _deleteObjectStore db name
@ -33,8 +33,8 @@ foreign import name :: IDBDatabase -> String
foreign import objectStoreNames :: IDBDatabase -> Array String
foreign import _transaction :: forall eff. Fn3 IDBDatabase (Array String) IDBTransactionMode (Synchronous eff IDBTransaction)
transaction :: forall eff. IDBDatabase -> Array String -> IDBTransactionMode -> Synchronous eff IDBTransaction
foreign import _transaction :: forall eff. Fn3 IDBDatabase (Array String) IDBTransactionMode (Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBTransaction)
transaction :: forall eff. IDBDatabase -> Array String -> IDBTransactionMode -> Eff (idb :: INDEXED_DB, exception :: EXCEPTION | eff) IDBTransaction
transaction db stores mode =
Fn.runFn3 _transaction db stores mode

View File

@ -1,4 +1,3 @@
const Maybe = require('Data.Maybe');
const $Core = require('Database.IndexedDB.Core/foreign');
const noOp2 = $Core.noOp2;
@ -18,8 +17,8 @@ exports.deleteDatabase = function deleteDatabase(name) {
};
};
exports._open = function _open(name, mver, req) {
const ver = Maybe.fromMaybe(undefined)(mver);
exports._open = function _open(fromMaybe, name, mver, req) {
const ver = fromMaybe(undefined)(mver);
return function aff(success, error) {
const request = indexedDB.open(name, ver);
@ -28,7 +27,7 @@ exports._open = function _open(name, mver, req) {
};
request.onerror = errorHandler(error);
request.onblocked = eventHandler(Maybe.fromMaybe(noOp2)(req.onBlocked));
request.onupgradeneeded = eventHandler(Maybe.fromMaybe(noOp2)(req.onUpgradeNeeded));
request.onblocked = eventHandler(fromMaybe(noOp2)(req.onBlocked));
request.onupgradeneeded = eventHandler(fromMaybe(noOp2)(req.onUpgradeNeeded));
};
};

View File

@ -6,8 +6,8 @@ import Control.Monad.Aff(Aff)
import Control.Monad.Eff(Eff)
import Control.Monad.Eff.Exception(EXCEPTION)
import Data.Function.Uncurried as Fn
import Data.Function.Uncurried(Fn3)
import Data.Maybe(Maybe)
import Data.Function.Uncurried(Fn4)
import Data.Maybe(Maybe, fromMaybe)
import Database.IndexedDB.Core
@ -21,7 +21,7 @@ type IDBOpenRequest eff =
foreign import deleteDatabase :: forall eff. String -> Aff (idb :: INDEXED_DB | eff) Int
foreign import _open :: forall eff. Fn3 String (Maybe Int) (IDBOpenRequest eff) (Aff (idb :: INDEXED_DB | eff) IDBDatabase)
foreign import _open :: forall a eff. Fn4 (a -> Maybe a -> a) String (Maybe Int) (IDBOpenRequest eff) (Aff (idb :: INDEXED_DB | eff) IDBDatabase)
open :: forall eff . String -> Maybe Int -> IDBOpenRequest eff -> Aff (idb :: INDEXED_DB | eff) IDBDatabase
open name mver req =
Fn.runFn3 _open name mver req
Fn.runFn4 _open fromMaybe name mver req