Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
b42bdd80
Commit
b42bdd80
authored
7 years ago
by
Nolan Lawson
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Extract polyfill loading into single module (#3421)
parent
76fa9d24
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/javascript/mastodon/load_polyfills.js
+36
-0
36 additions, 0 deletions
app/javascript/mastodon/load_polyfills.js
app/javascript/packs/application.js
+4
-30
4 additions, 30 deletions
app/javascript/packs/application.js
app/javascript/packs/public.js
+4
-9
4 additions, 9 deletions
app/javascript/packs/public.js
with
44 additions
and
39 deletions
app/javascript/mastodon/load_polyfills.js
0 → 100644
+
36
−
0
View file @
b42bdd80
// Convenience function to load polyfills and return a promise when it's done.
// If there are no polyfills, then this is just Promise.resolve() which means
// it will execute in the same tick of the event loop (i.e. near-instant).
function
importBasePolyfills
()
{
return
import
(
/* webpackChunkName: "base_polyfills" */
'
./base_polyfills
'
);
}
function
importExtraPolyfills
()
{
return
import
(
/* webpackChunkName: "extra_polyfills" */
'
./extra_polyfills
'
);
}
function
loadPolyfills
()
{
const
needsBasePolyfills
=
!
(
window
.
Intl
&&
Object
.
assign
&&
Number
.
isNaN
&&
window
.
Symbol
&&
Array
.
prototype
.
includes
);
// Latest version of Firefox and Safari do not have IntersectionObserver.
// Edge does not have requestIdleCallback.
// This avoids shipping them all the polyfills.
const
needsExtraPolyfills
=
!
(
window
.
IntersectionObserver
&&
window
.
requestIdleCallback
);
return
Promise
.
all
([
needsBasePolyfills
&&
importBasePolyfills
(),
needsExtraPolyfills
&&
importExtraPolyfills
(),
]);
}
export
default
loadPolyfills
;
This diff is collapsed.
Click to expand it.
app/javascript/packs/application.js
+
4
−
30
View file @
b42bdd80
import
main
from
'
../mastodon/main
'
;
import
loadPolyfills
from
'
../mastodon/load_polyfills
'
;
const
needsBasePolyfills
=
!
(
window
.
Intl
&&
Object
.
assign
&&
Number
.
isNaN
&&
window
.
Symbol
&&
Array
.
prototype
.
includes
);
const
needsExtraPolyfills
=
!
(
window
.
IntersectionObserver
&&
window
.
requestIdleCallback
);
// Latest version of Firefox and Safari do not have IntersectionObserver.
// Edge does not have requestIdleCallback.
// This avoids shipping them all the polyfills.
if
(
needsBasePolyfills
)
{
Promise
.
all
([
import
(
/* webpackChunkName: "base_polyfills" */
'
../mastodon/base_polyfills
'
),
import
(
/* webpackChunkName: "extra_polyfills" */
'
../mastodon/extra_polyfills
'
),
]).
then
(
main
).
catch
(
e
=>
{
console
.
error
(
e
);
// eslint-disable-line no-console
});
}
else
if
(
needsExtraPolyfills
)
{
import
(
/* webpackChunkName: "extra_polyfills" */
'
../mastodon/extra_polyfills
'
).
then
(
main
).
catch
(
e
=>
{
console
.
error
(
e
);
// eslint-disable-line no-console
});
}
else
{
main
();
}
loadPolyfills
().
then
(
main
).
catch
(
e
=>
{
console
.
error
(
e
);
// eslint-disable-line no-console
});
This diff is collapsed.
Click to expand it.
app/javascript/packs/public.js
+
4
−
9
View file @
b42bdd80
...
...
@@ -3,6 +3,7 @@ import { getLocale } from 'mastodon/locales';
import
{
length
}
from
'
stringz
'
;
import
IntlRelativeFormat
from
'
intl-relativeformat
'
;
import
{
delegate
}
from
'
rails-ujs
'
;
import
loadPolyfills
from
'
../mastodon/load_polyfills
'
;
require
.
context
(
'
../images/
'
,
true
);
...
...
@@ -85,12 +86,6 @@ function main() {
});
}
if
(
!
window
.
Intl
)
{
import
(
/* webpackChunkName: "base_polyfills" */
'
mastodon/base_polyfills
'
).
then
(()
=>
{
main
();
}).
catch
(
error
=>
{
console
.
log
(
error
);
// eslint-disable-line no-console
});
}
else
{
main
();
}
loadPolyfills
().
then
(
main
).
catch
(
error
=>
{
console
.
log
(
error
);
// eslint-disable-line no-console
});
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