Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
Commits
78d95278
Commit
78d95278
authored
5 years ago
by
Yusei Tahara
Committed by
Romain Courteaud
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_web_renderjs_ui] Update service worker code. Use lower case for non-global variables.
parent
c9d78743
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
30 deletions
+30
-30
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.js
...lateItem/web_page_module/rjs_gadget_erp5_serviceworker.js
+28
-28
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.xml
...ateItem/web_page_module/rjs_gadget_erp5_serviceworker.xml
+2
-2
No files found.
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.js
View file @
78d95278
...
@@ -243,13 +243,13 @@
...
@@ -243,13 +243,13 @@
client_id
=
event
.
clientId
.
toString
(),
client_id
=
event
.
clientId
.
toString
(),
// CACHE_MAP is a temprary data store.
// CACHE_MAP is a temprary data store.
// This should be kept until service worker stops.
// This should be kept until service worker stops.
CACHE_KEY
=
CACHE_MAP
[
client_id
],
cache_key
=
CACHE_MAP
[
client_id
],
ERP5JS_CACHE
;
erp5js_cache
;
url
.
hash
=
''
;
url
.
hash
=
''
;
console
.
log
(
"
Client Id =
"
+
client_id
);
console
.
log
(
"
Client Id =
"
+
client_id
);
if
(
CACHE_KEY
)
{
if
(
cache_key
)
{
console
.
log
(
"
CACHE_KEY from CACHE_MAP
"
+
CACHE_KEY
);
console
.
log
(
"
cache_key from CACHE_MAP
"
+
cache_key
);
}
}
if
(
!
client_id
)
{
if
(
!
client_id
)
{
...
@@ -257,9 +257,9 @@
...
@@ -257,9 +257,9 @@
// use the CACHE_NAME that is defined in this service worker.
// use the CACHE_NAME that is defined in this service worker.
// It means that even if there is a new Cache, but web browser
// It means that even if there is a new Cache, but web browser
// uses the Cache that was installed by this service worker.
// uses the Cache that was installed by this service worker.
CACHE_KEY
=
CACHE_NAME
;
cache_key
=
CACHE_NAME
;
CACHE_MAP
[
client_id
]
=
CACHE_KEY
;
CACHE_MAP
[
client_id
]
=
cache_key
;
console
.
log
(
"
CACHE_KEY from Service Worker
"
+
CACHE_KEY
);
console
.
log
(
"
cache_key from Service Worker
"
+
cache_key
);
}
}
if
((
event
.
request
.
method
!==
'
GET
'
)
||
if
((
event
.
request
.
method
!==
'
GET
'
)
||
(
required_url_list
.
indexOf
(
url
.
toString
())
===
-
1
))
{
(
required_url_list
.
indexOf
(
url
.
toString
())
===
-
1
))
{
...
@@ -270,50 +270,50 @@
...
@@ -270,50 +270,50 @@
return
event
.
respondWith
(
return
event
.
respondWith
(
Promise
.
resolve
()
Promise
.
resolve
()
.
then
(
function
()
{
.
then
(
function
()
{
if
(
!
CACHE_KEY
)
{
if
(
!
cache_key
)
{
// CLIENT_CACHE_MAPPING_NAME stores
CACHE_KEY
of each client.
// CLIENT_CACHE_MAPPING_NAME stores
cache_key
of each client.
return
caches
.
open
(
CLIENT_CACHE_MAPPING_NAME
)
return
caches
.
open
(
CLIENT_CACHE_MAPPING_NAME
)
.
then
(
function
(
erp5js_
cache
)
{
.
then
(
function
(
cache
)
{
// Service worker forget everything when it stops. So, when it started
// Service worker forget everything when it stops. So, when it started
// again, CACHE_MAP is empty, get the associated
CACHE_KEY
from the
// again, CACHE_MAP is empty, get the associated
cache_key
from the
// special Cache named CLIENT_CACHE_MAPPING_NAME.
// special Cache named CLIENT_CACHE_MAPPING_NAME.
ERP5JS_CACHE
=
erp5js_
cache
;
erp5js_cache
=
cache
;
return
erp5js_cache
.
match
(
client_id
)
return
erp5js_cache
.
match
(
client_id
)
.
then
(
function
(
response
)
{
.
then
(
function
(
response
)
{
if
(
response
)
{
if
(
response
)
{
// We use Cache Storage as a persistent database.
// We use Cache Storage as a persistent database.
CACHE_KEY
=
response
.
statusText
;
cache_key
=
response
.
statusText
;
CACHE_MAP
[
client_id
]
=
CACHE_KEY
;
CACHE_MAP
[
client_id
]
=
cache_key
;
console
.
log
(
"
CACHE_KEY from Cache Storage
"
+
CACHE_KEY
);
console
.
log
(
"
cache_key from Cache Storage
"
+
cache_key
);
}
}
})
})
;
})
})
;
}
}
})
})
.
then
(
function
()
{
.
then
(
function
()
{
if
(
!
CACHE_KEY
)
{
if
(
!
cache_key
)
{
// If associated
CACHE_KEY
is not found, it means this client is a new one.
// If associated
cache_key
is not found, it means this client is a new one.
// Let's find the latest Cache.
// Let's find the latest Cache.
return
caches
.
keys
()
return
caches
.
keys
()
.
then
(
function
(
keys
)
{
.
then
(
function
(
keys
)
{
keys
=
keys
.
filter
(
function
(
key
)
{
return
key
.
startsWith
(
prefix
);
});
keys
=
keys
.
filter
(
function
(
key
)
{
return
key
.
startsWith
(
prefix
);
});
console
.
log
(
"
KEYS =
"
+
keys
);
console
.
log
(
"
KEYS =
"
+
keys
);
if
(
keys
.
length
)
{
if
(
keys
.
length
)
{
CACHE_KEY
=
keys
.
sort
().
reverse
()[
0
];
cache_key
=
keys
.
sort
().
reverse
()[
0
];
CACHE_MAP
[
client_id
]
=
CACHE_KEY
;
CACHE_MAP
[
client_id
]
=
cache_key
;
}
else
{
}
else
{
CACHE_KEY
=
CACHE_NAME
;
cache_key
=
CACHE_NAME
;
CACHE_MAP
[
client_id
]
=
CACHE_NAME
;
CACHE_MAP
[
client_id
]
=
CACHE_NAME
;
}
}
// Save the associated
CACHE_KEY
in a persistent database because service
// Save the associated
cache_key
in a persistent database because service
// worker forget everything when it stops.
// worker forget everything when it stops.
ERP5JS_CACHE
.
put
(
client_id
,
new
Response
(
null
,
{
"
statusText
"
:
CACHE_KEY
}));
erp5js_cache
.
put
(
client_id
,
new
Response
(
null
,
{
"
statusText
"
:
cache_key
}));
})
})
;
}
}
})
})
.
then
(
function
()
{
.
then
(
function
()
{
// Finally we have the associated
CACHE_KEY
. Let's find a cached response.
// Finally we have the associated
cache_key
. Let's find a cached response.
return
caches
.
open
(
CACHE_KEY
);
return
caches
.
open
(
cache_key
);
})
})
.
then
(
function
(
cache
)
{
.
then
(
function
(
cache
)
{
// Don't give request object itself. Firefox's Cache Storage
// Don't give request object itself. Firefox's Cache Storage
...
@@ -328,7 +328,7 @@
...
@@ -328,7 +328,7 @@
}
}
// Not in cache - return the result from the live server
// Not in cache - return the result from the live server
// `fetch` is essentially a "fallback"
// `fetch` is essentially a "fallback"
console
.
log
(
"
MISS
"
+
CACHE_KEY
+
"
"
+
url
);
console
.
log
(
"
MISS
"
+
cache_key
+
"
"
+
url
);
return
fetch
(
event
.
request
);
return
fetch
(
event
.
request
);
})
})
);
);
...
...
This diff is collapsed.
Click to expand it.
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_serviceworker.xml
View file @
78d95278
...
@@ -228,7 +228,7 @@
...
@@ -228,7 +228,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<key>
<string>
serial
</string>
</key>
<value>
<string>
976.15
605.32654.49476
</string>
</value>
<value>
<string>
976.15
722.43793.37154
</string>
</value>
</item>
</item>
<item>
<item>
<key>
<string>
state
</string>
</key>
<key>
<string>
state
</string>
</key>
...
@@ -246,7 +246,7 @@
...
@@ -246,7 +246,7 @@
</tuple>
</tuple>
<state>
<state>
<tuple>
<tuple>
<float>
15599
24528.42
</float>
<float>
15599
31548.14
</float>
<string>
UTC
</string>
<string>
UTC
</string>
</tuple>
</tuple>
</state>
</state>
...
...
This diff is collapsed.
Click to expand it.
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