Skip to content

Commit

Permalink
Remove polyfill.io
Browse files Browse the repository at this point in the history
Prepare for releasing a hotfix: https://oisaur.com/@renchap/112679062235365025
  • Loading branch information
DmitrySharabin committed Jun 28, 2024
1 parent cf64cf5 commit 26a6020
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
9 changes: 3 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,9 @@ This file is the entry point of Mavo and all of Mavo's components are utilized h
* `attributes` object is an array of all attributes. It is incomplete as more are in separate JS files and are pushed later to this object.

### How Mavo Picks Up `mv-app` Elements
1. Fetches polyfills needed ([polyfill.io](https://polyfill.io/v2/docs/)); syntax-level features cannot be polyfilled.
* Mavo has a list (IntersectionObserver, Symbol) that needs to be polyfilled.
2. Adds/pushes dependencies after the polyfills are loaded.
3. Loads Mavo plugins using `_.Plugins.load()` defined in plugins.js.
4. `_.inited` Promise resolves after page (`$.ready`) and dependencies are ready.
5. `_.init()` gets all elements with an `mv-app` attribute that matches the `$$` selector (using `selectors` object).
1. Loads Mavo plugins using `_.Plugins.load()` defined in plugins.js.
2. `_.inited` Promise resolves after page (`$.ready`) and dependencies are ready.
3. `_.init()` gets all elements with an `mv-app` attribute that matches the `$$` selector (using `selectors` object).
1. Filters array of `mv-app` elements (use `Mavo.get` to see if there’s another mv-app associated with this element).
2. Maps each element to a new Mavo instance & return this array.

Expand Down
29 changes: 1 addition & 28 deletions src/mavo.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,22 +812,6 @@ let _ = self.Mavo = $.Class(class Mavo {
$.ready().then(() => _.Plugins.load()),
]

// Only naive tests here (no false positives, but false negatives are ok).
// polyfill.io will do more proper checking
static polyfillsNeeded = {
"blissfuljs": Array.from && document.documentElement.closest && self.URL && "searchParams" in URL.prototype,
"Intl.~locale.en": self.Intl,
"IntersectionObserver": self.IntersectionObserver,
"Symbol": self.Symbol,
"Element.prototype.remove": Element.prototype.remove,
"Element.prototype.before": Element.prototype.before,
"Element.prototype.after": Element.prototype.after,
"Element.prototype.prepend": Element.prototype.prepend,
"Array.prototype.flat": Array.prototype.flat,
"Array.prototype.flatMap": Array.prototype.flatMap,
}
static polyfills = []

static init (container = document) {
let mavos = Array.isArray(arguments[0])? arguments[0] : $$(_.selectors.init, container);

Expand Down Expand Up @@ -986,7 +970,7 @@ let _ = self.Mavo = $.Class(class Mavo {
});

// Define symbols
// These are lazy to give the Symbol polyfill a chance to load if needed
// TODO: These should not be lazy anymore?
["toNode", "isProxy", "route", "parent", "property", "mavo", "groupedBy", "as"].forEach(symbol => {
$.lazy(_, symbol, () => Symbol(symbol));
});
Expand Down Expand Up @@ -1018,23 +1002,12 @@ s.output = "[property=output], .mv-output";

}

$.each(_.polyfillsNeeded, (id, supported) => {
if (!supported) {
_.polyfills.push(id);
}
});

_.ready = _.thenAll(_.dependencies);
_.inited = _.promise();

// Init mavo. Async to give other scripts a chance to modify stuff.
await _.defer();

if (_.polyfills.length > 0) {
var polyfillURL = "https://cdn.polyfill.io/v2/polyfill.min.js?unknown=polyfill&features=" + _.polyfills.map(a => a + "|gated").join(",");
_.dependencies.push($.include(polyfillURL));
}

await $.ready();

/***********************
Expand Down

0 comments on commit 26a6020

Please sign in to comment.