Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
9d501e76
Commit
9d501e76
authored
Jul 03, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[cacheAPI] add CacheAPI support
parent
680db391
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
131 additions
and
5 deletions
+131
-5
psc-package.json
psc-package.json
+2
-0
purs-packages.nix
purs-packages.nix
+20
-0
Common.purs
src/Gargantext/Components/Nodes/Corpus/Chart/Common.purs
+3
-0
REST.purs
src/Gargantext/Config/REST.purs
+19
-4
Loader.purs
src/Gargantext/Hooks/Loader.purs
+2
-1
CacheAPI.js
src/Gargantext/Utils/CacheAPI.js
+50
-0
CacheAPI.purs
src/Gargantext/Utils/CacheAPI.purs
+35
-0
No files found.
psc-package.json
View file @
9d501e76
...
...
@@ -4,6 +4,7 @@
"source"
:
".psc-package/local/.set/packages.json"
,
"depends"
:
[
"affjax"
,
"aff-promise"
,
"argonaut"
,
"console"
,
"css"
,
...
...
@@ -20,6 +21,7 @@
"markdown-smolder"
,
"math"
,
"maybe"
,
"milkis"
,
"nonempty"
,
"numbers"
,
"prelude"
,
...
...
purs-packages.nix
View file @
9d501e76
...
...
@@ -12,6 +12,16 @@
};
};
"aff-promise"
=
pkgs
.
stdenv
.
mkDerivation
{
name
=
"aff-promise"
;
version
=
"v2.1.0"
;
fetched
=
pkgs
.
fetchgit
{
url
=
"https://github.com/nwolverson/purescript-aff-promise.git"
;
rev
=
"033d6b90252e0390b0de7845e21de919bc4c3a0e"
;
sha256
=
"0khm53lvxgvc7fbsvcr2h2wlhcgay8vq45755f0w8vpk1441dvww"
;
};
};
"affjax"
=
pkgs
.
stdenv
.
mkDerivation
{
name
=
"affjax"
;
version
=
"v9.0.0"
;
...
...
@@ -572,6 +582,16 @@
};
};
"milkis"
=
pkgs
.
stdenv
.
mkDerivation
{
name
=
"milkis"
;
version
=
"v7.2.0"
;
fetched
=
pkgs
.
fetchgit
{
url
=
"https://github.com/justinwoo/purescript-milkis.git"
;
rev
=
"6a55398de664595406e0b5fe7cd3646a4501f1ed"
;
sha256
=
"1i6l8k4clrnq4wxbdzzq08kagk591yr24xip86z1j7xap98y02xg"
;
};
};
"mmorph"
=
pkgs
.
stdenv
.
mkDerivation
{
name
=
"mmorph"
;
version
=
"v5.1.0"
;
...
...
src/Gargantext/Components/Nodes/Corpus/Chart/Common.purs
View file @
9d501e76
...
...
@@ -18,6 +18,9 @@ type MetricsLoadViewProps a = (
| MetricsProps
)
cacheName :: String
cacheName = "metrics"
metricsLoadView :: forall a. Record (MetricsLoadViewProps a) -> R.Element
metricsLoadView p = R.createElement metricsLoadViewCpt p []
...
...
src/Gargantext/Config/REST.purs
View file @
9d501e76
...
...
@@ -4,7 +4,7 @@ import Affjax (defaultRequest, printResponseFormatError, request)
import Affjax.RequestBody (RequestBody(..), formData, formURLEncoded)
import Affjax.RequestHeader as ARH
import Affjax.ResponseFormat as ResponseFormat
import DOM.Simple.Console (log)
import DOM.Simple.Console (log
, log2
)
import Data.Argonaut (class DecodeJson, decodeJson, class EncodeJson, encodeJson)
import Data.Either (Either(..))
import Data.Foldable (foldMap)
...
...
@@ -12,13 +12,18 @@ import Data.FormURLEncoded as FormURLEncoded
import Data.HTTP.Method (Method(..))
import Data.Maybe (Maybe(..))
import Data.MediaType.Common (applicationFormURLEncoded, applicationJSON, multipartFormData)
import Data.Tuple (Tuple)
import Data.Tuple (Tuple(..))
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, throwError)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Milkis as Milkis
import Unsafe.Coerce (unsafeCoerce)
import Web.XHR.FormData as XHRFormData
import Gargantext.Prelude
import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Reactix as R2
import Web.XHR.FormData as XHRFormData
type Token = String
...
...
@@ -26,7 +31,7 @@ type Token = String
send :: forall a b. EncodeJson a => DecodeJson b =>
Method -> Maybe Token -> String -> Maybe a -> Aff b
send m mtoken url reqbody = do
affResp <- request $
defaultRequest
let req =
defaultRequest
{ url = url
, responseFormat = ResponseFormat.json
, method = Left m
...
...
@@ -38,6 +43,16 @@ send m mtoken url reqbody = do
) mtoken
, content = (Json <<< encodeJson) <$> reqbody
}
cache <- GUC.openCache $ GUC.CacheName "test"
let method = unsafeCoerce (show m) :: Milkis.Method
let options = { method, headers: Milkis.makeHeaders {"content-type": "application/json"} }
let req' = GUC.makeRequest (Milkis.URL url) options
res <- GUC.cached cache req'
liftEffect $ log2 "[send] cache res" res
liftEffect $ log2 "[send] res json" $ Milkis.json res
affResp <- request req
case mtoken of
Nothing -> pure unit
Just token -> liftEffect $ do
...
...
src/Gargantext/Hooks/Loader.purs
View file @
9d501e76
module Gargantext.Hooks.Loader where
import Gargantext.Prelude
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (:=), (~>), jsonEmptyObject)
import Data.Argonaut.Core (stringify)
import Data.Argonaut.Parser (jsonParser)
...
...
@@ -14,6 +13,8 @@ import Effect.Class (liftEffect)
import Reactix as R
import Web.Storage.Storage as WSS
import Gargantext.Prelude
import Gargantext.Components.LoadingSpinner (loadingSpinner)
import Gargantext.Utils as GU
import Gargantext.Utils.Reactix as R2
...
...
src/Gargantext/Utils/CacheAPI.js
0 → 100644
View file @
9d501e76
exports
.
_makeRequest
=
function
()
{
return
function
(
url
)
{
return
function
(
options
)
{
console
.
log
(
'[_makeRequest] url'
,
url
);
console
.
log
(
'[_makeRequest] options'
,
options
);
return
new
Request
(
url
,
options
);
}
}
}
exports
.
_openCache
=
function
(
cacheName
)
{
return
function
()
{
return
caches
.
open
(
cacheName
);
}
}
exports
.
_cached
=
function
(
cache
)
{
return
function
(
req
)
{
return
function
(
onError
,
onSuccess
)
{
cache
.
match
(
req
).
then
(
function
(
res
)
{
if
(
res
)
{
console
.
log
(
'[_getC] cache hit with'
,
req
);
onSuccess
(
res
)
}
else
{
cache
.
add
(
req
).
then
(
function
(
res
)
{
console
.
log
(
'[_getC] cache miss with'
,
req
);
onSuccess
(
res
);
},
function
(
err
)
{
onError
(
err
);
})
}
},
function
(
err
)
{
onError
(
err
);
})
return
function
(
cancelError
,
onCancelerError
,
onCancelerSuccess
)
{
onCancelerSuccess
();
}
}
}
}
exports
.
_delete
=
function
(
cache
)
{
return
function
(
req
)
{
return
function
()
{
cache
.
delete
(
req
);
}
}
}
src/Gargantext/Utils/CacheAPI.purs
0 → 100644
View file @
9d501e76
module Gargantext.Utils.CacheAPI where
import Control.Promise (Promise, toAffE)
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff)
import Milkis as M
import Type.Row (class Union)
import Gargantext.Prelude
foreign import data Cache :: Type
foreign import data Request :: Type
newtype CacheName = CacheName String
makeRequest :: forall options trash. Union options trash M.Options =>
M.URL -> { method :: M.Method | options } -> Request
makeRequest url options = _makeRequest url options
openCache :: CacheName -> Aff Cache
openCache (CacheName cacheName) = toAffE $ _openCache cacheName
cached :: Cache -> Request -> Aff M.Response
cached cache req = fromEffectFnAff $ _cached cache req
delete :: Cache -> Request -> Aff Unit
delete cache req = toAffE $ _delete cache req
foreign import _makeRequest :: forall options trash. Union options trash M.Options =>
M.URL -> { method :: M.Method | options } -> Request
foreign import _openCache :: String -> Effect (Promise Cache)
foreign import _cached :: Cache -> Request -> EffectFnAff M.Response
foreign import _delete :: Cache -> Request -> Effect (Promise Unit)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment