Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
de259f45
Commit
de259f45
authored
5 years ago
by
Reiter, Christoph
Browse files
Options
Downloads
Patches
Plain Diff
Add icon request caching
We now only create one request per icon.
parent
675f70e3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/common/vpu-common-demo.js
+2
-1
2 additions, 1 deletion
packages/common/vpu-common-demo.js
packages/common/vpu-icon.js
+21
-2
21 additions, 2 deletions
packages/common/vpu-icon.js
with
23 additions
and
3 deletions
packages/common/vpu-common-demo.js
+
2
−
1
View file @
de259f45
...
@@ -95,7 +95,8 @@ class VpuCommonDemo extends VPULitElement {
...
@@ -95,7 +95,8 @@ class VpuCommonDemo extends VPULitElement {
<p style="font-size: 2em; color: orange">Foo <vpu-icon name="cloudnetwork"></vpu-icon> bar</p>
<p style="font-size: 2em; color: orange">Foo <vpu-icon name="cloudnetwork"></vpu-icon> bar</p>
<span style="background-color: #000"><a href="#" style=" color: #fff">foobar</a></span>
<span style="background-color: #000"><a href="#" style=" color: #fff">foobar</a></span>
<br>
<br>
<vpu-icon style="color: green; height: 50px; border: #000 solid 1px"></vpu-icon>
${(
new
Array
(
50
).
fill
(
0
)).
map
(
i
=>
html
`<vpu-icon style="color: green; width: 50px; height: 50px; border: #000 solid 1px"name="coffee-cup"></vpu-icon>`
)}
</div>
</div>
</div>
</div>
<div class="container">
<div class="container">
...
...
This diff is collapsed.
Click to expand it.
packages/common/vpu-icon.js
+
21
−
2
View file @
de259f45
...
@@ -41,6 +41,7 @@ export function getIconCSS(name) {
...
@@ -41,6 +41,7 @@ export function getIconCSS(name) {
async
function
getSVGTextElement
(
name
)
{
async
function
getSVGTextElement
(
name
)
{
const
iconURL
=
getIconSVGURL
(
name
);
const
iconURL
=
getIconSVGURL
(
name
);
const
response
=
await
fetch
(
iconURL
);
const
response
=
await
fetch
(
iconURL
);
if
(
!
response
.
ok
)
{
if
(
!
response
.
ok
)
{
return
unsafeHTML
(
errorIcon
);
return
unsafeHTML
(
errorIcon
);
...
@@ -53,10 +54,28 @@ async function getSVGTextElement(name) {
...
@@ -53,10 +54,28 @@ async function getSVGTextElement(name) {
return
unsafeHTML
(
text
);
return
unsafeHTML
(
text
);
}
}
const
iconCache
=
{};
/**
* Avoid lots of requests in case an icon is used multiple times on the same page.
*
* @param {string} name
*/
async
function
getSVGTextElementCached
(
name
)
{
if
(
iconCache
[
name
]
===
undefined
)
{
let
promise
=
getSVGTextElement
(
name
);
iconCache
[
name
]
=
promise
;
return
promise
;
}
else
{
return
iconCache
[
name
];
}
}
/**
/**
* For icon names see https://
materialdesign
icons.com
/
* For icon names see https://
line
icons.com
*/
*/
class
Icon
extends
LitElement
{
class
Icon
extends
LitElement
{
constructor
()
{
constructor
()
{
super
();
super
();
this
.
name
=
"
bolt
"
;
this
.
name
=
"
bolt
"
;
...
@@ -88,7 +107,7 @@ class Icon extends LitElement {
...
@@ -88,7 +107,7 @@ class Icon extends LitElement {
}
}
render
()
{
render
()
{
let
svg
=
getSVGTextElement
(
this
.
name
);
let
svg
=
getSVGTextElement
Cached
(
this
.
name
);
return
html
`
return
html
`
${
until
(
svg
)}
${
until
(
svg
)}
`
;
`
;
...
...
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