Fakultas Ilmu Komputer UI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kape
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fasilkom UI Open Source Software
Kape
Commits
8ff83265
Commit
8ff83265
authored
8 years ago
by
Zamil Majdy
Browse files
Options
Downloads
Patches
Plain Diff
[#140382397] #6 Add caching mechanism on Server.jsx library
parent
c7d8cf8f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
assets/js/lib/server.jsx
+16
-9
16 additions, 9 deletions
assets/js/lib/server.jsx
package.json
+1
-1
1 addition, 1 deletion
package.json
with
17 additions
and
10 deletions
assets/js/lib/server.jsx
+
16
−
9
View file @
8ff83265
import
Logger
from
'
./logger
'
;
import
Logger
from
"
./logger
"
;
import
Storage
from
"
./storage
"
;
export
default
class
Server
{
export
default
class
Server
{
static
getCookie
(
name
)
{
static
getCookie
(
name
)
{
...
@@ -17,7 +18,7 @@ export default class Server {
...
@@ -17,7 +18,7 @@ export default class Server {
return
cookieValue
;
return
cookieValue
;
}
}
static
_request
(
path
,
method
,
data
)
{
static
_request
(
path
,
method
,
data
,
useCache
=
false
)
{
let
url
=
"
/api
"
+
path
;
let
url
=
"
/api
"
+
path
;
let
csrftoken
=
this
.
getCookie
(
"
csrftoken
"
);
let
csrftoken
=
this
.
getCookie
(
"
csrftoken
"
);
...
@@ -34,24 +35,30 @@ export default class Server {
...
@@ -34,24 +35,30 @@ export default class Server {
};
};
let
request
=
fetch
(
url
,
requestData
);
let
request
=
fetch
(
url
,
requestData
);
r
et
urn
request
.
then
((
response
)
=>
{
l
et
promise
=
request
.
then
((
response
)
=>
{
// Logger.log("[Server] Calling", url, response);
// Logger.log("[Server] Calling", url, response);
if
(
response
.
status
<
200
||
response
.
status
>
399
)
{
if
(
response
.
status
<
200
||
response
.
status
>
399
)
{
Logger
.
log
(
response
);
throw
response
;
throw
response
;
}
}
if
(
response
.
status
===
204
)
{
if
(
response
.
status
===
204
)
{
return
response
;
return
response
;
}
}
return
response
.
json
();
return
response
.
json
();
}).
then
((
response
)
=>
{
// Logger.log("[Server] Response from", url, response);
return
response
;
});
});
return
useCache
?
promise
.
then
((
response
)
=>
{
Logger
.
log
(
"
[Server] Response from
"
,
url
,
response
);
Storage
.
set
(
path
,
response
);
return
response
;
})
:
promise
.
then
((
response
)
=>
{
Logger
.
log
(
"
[Server] Response from
"
,
url
,
response
);
return
response
;
})
}
}
static
get
(
path
)
{
static
get
(
path
,
useCache
=
true
)
{
return
this
.
_request
(
path
,
"
GET
"
,
null
);
return
(
useCache
&&
Storage
.
get
(
path
))
?
Promise
.
resolve
(
Storage
.
get
(
path
))
:
this
.
_request
(
path
,
"
GET
"
,
null
,
useCache
);
}
}
static
post
(
path
,
data
)
{
static
post
(
path
,
data
)
{
...
...
This diff is collapsed.
Click to expand it.
package.json
+
1
−
1
View file @
8ff83265
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
"scripts"
:
{
"scripts"
:
{
"build"
:
"webpack --config webpack.prod.config.js --progress --colors"
,
"build"
:
"webpack --config webpack.prod.config.js --progress --colors"
,
"build-production"
:
"webpack -p --config webpack.prod.config.js --progress --colors"
,
"build-production"
:
"webpack -p --config webpack.prod.config.js --progress --colors"
,
"webpack"
:
"webpack
-p
--progress --display-error-details --config webpack.config.js --watch"
,
"webpack"
:
"webpack --progress --display-error-details --config webpack.config.js --watch"
,
"watch"
:
"node server.js"
,
"watch"
:
"node server.js"
,
"karma"
:
"karma start"
"karma"
:
"karma start"
},
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment