git.iko.soy/purescript-indexed-DB
on master help sign in
add documentation for IDBKeys
commit3461bebbce0da2f9a6ff638d790cf343ecf64c12 authorKtorZ <matthias.benkort@gmail.com> dateThu 6 Jul 2017, 14:38 (9 years ago) parentd19b84c
2 files changed+36−7
src/Database/IndexedDB/IDBKey.purs+3 src/Database/IndexedDB/IDBKey/Internal.purs+33−7
src/Database/IndexedDB/IDBKey.purs+3
@@ -1,3 +1,6 @@
1+-- | A key has an associated type which is one of: number, date, string, or array.
2+-- |
3+-- | NOTE: Binary keys aren't supported yet.
14module Database.IndexedDB.IDBKey
25 ( module Database.IndexedDB.IDBKey.Internal
36 ) where
src/Database/IndexedDB/IDBKey/Internal.purs+33−7
@@ -1,3 +1,6 @@
1+-- | A key has an associated type which is one of: number, date, string, or array.
2+-- |
3+-- | NOTE: Binary keys aren't supported yet.
14module Database.IndexedDB.IDBKey.Internal
25 ( Key(..)
36 , class IDBKey, toKey , fromKey , unsafeFromKey
@@ -28,7 +31,9 @@ import Data.Traversable (traverse)
2831newtype Key = Key Foreign
2932
3033
31−extractForeign :: Key -> Foreign
34+extractForeign
35+ :: Key
36+ -> Foreign
3237extractForeign (Key f) =
3338 f
3439
@@ -36,6 +41,9 @@ extractForeign (Key f) =
3641--------------------
3742-- INTERFACES
3843--
44+-- | Interface describing a key. Use the `unsafeFromKey` to convert a key
45+-- | to a known type (e.g if you only strings as keys, or perfectly knows the
46+-- | type of a given key).
3947class IDBKey a where
4048 toKey :: a -> Key
4149 fromKey :: Key -> F a
@@ -137,19 +145,34 @@ instance idbKeyArray :: IDBKey a => IDBKey (Array a) where
137145 unsafeFromKey (Key f) = map unsafeFromKey (Foreign.unsafeFromForeign f)
138146
139147
140−dateTime :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime
148+-- FFI constructor to build a DateTime from years, months, days, hours, minutes, seconds and millis
149+dateTime
150+ :: Int -- ^ years
151+ -> Int -- ^ months
152+ -> Int -- ^ days
153+ -> Int -- ^ hours
154+ -> Int -- ^ minutes
155+ -> Int -- ^ seconds
156+ -> Int -- ^ milliseconds
157+ -> Nullable DateTime
141158dateTime y m d h mi s ms =
142159 toNullable $ DateTime
143160 <$> (Date.canonicalDate <$> toEnum y <*> toEnum m <*> toEnum d)
144161 <*> (Time <$> toEnum h <*> toEnum mi <*> toEnum s <*> toEnum ms)
145162
146163
147−dateTimeF :: DateTime -> F DateTime
164+-- FFI constructor to convert a JS `Date` into a successful `F DateTime`
165+dateTimeF
166+ :: DateTime
167+ -> F DateTime
148168dateTimeF =
149169 Right >>> Identity >>> ExceptT
150170
151171
152−dateTimeE :: String -> F DateTime
172+-- FFI constructor to convert a string into an errored `F DateTime`
173+dateTimeE
174+ :: String
175+ -> F DateTime
153176dateTimeE =
154177 Foreign.TypeMismatch "Date" >>> flip NonEmpty Nil >>> NonEmptyList >>> Left >>> Identity >>> ExceptT
155178
@@ -157,10 +180,13 @@ dateTimeE =
157180--------------------
158181-- FFI
159182--
160−foreign import _dateTimeToForeign :: Fn7 Int Int Int Int Int Int Int Foreign
183+foreign import _dateTimeToForeign
184+ :: Fn7 Int Int Int Int Int Int Int Foreign
161185
162186
163−foreign import _readDateTime :: Fn4 (Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime) (DateTime -> F DateTime) (String -> F DateTime) Foreign (F DateTime)
187+foreign import _readDateTime
188+ :: Fn4 (Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime) (DateTime -> F DateTime) (String -> F DateTime) Foreign (F DateTime)
164189
165190
166−foreign import _unsafeReadDateTime :: Fn2 (Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime) Foreign DateTime
191+foreign import _unsafeReadDateTime
192+ :: Fn2 (Int -> Int -> Int -> Int -> Int -> Int -> Int -> Nullable DateTime) Foreign DateTime