Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CSS keyframes via sentinel-js instead of MutationObserver #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"license": "MIT",
"dependencies": {
"fengari": "fengari-lua/fengari",
"fengari-interop": "fengari-lua/fengari-interop"
"fengari-interop": "fengari-lua/fengari-interop",
"sentinel-js": "^0.0.4"
},
"devDependencies": {
"babel-core": "^6.26.0",
Expand Down
17 changes: 4 additions & 13 deletions src/fengari-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const lua = fengari.lua;
const lauxlib = fengari.lauxlib;
const lualib = fengari.lualib;
const interop = require('fengari-interop');
const sentinel = require('sentinel-js');

const L = lauxlib.luaL_newstate();

Expand Down Expand Up @@ -143,22 +144,12 @@ const try_tag = function(tag) {
}
};

/* watch for new script tags added to document */
(new MutationObserver(function(records, observer) {
for (let i=0; i<records.length; i++) {
let record = records[i];
for (let j=0; j<record.addedNodes.length; j++) {
try_tag(record.addedNodes[j]);
}
}
})).observe(document, {
childList: true,
subtree: true
});

/* the query selector here is slightly liberal,
more checks occur in try_tag */
const selector = 'script[type^="application/lua"] script[type^="text/lua"]';

/* watch for new script tags added to document */
sentinel.on(selector, try_tag);

/* try to run existing script tags */
Array.prototype.forEach.call(document.querySelectorAll(selector), try_tag);
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,10 @@ safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@~5.1.0,
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"

sentinel-js@^0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/sentinel-js/-/sentinel-js-0.0.4.tgz#44a699b968bf9ecf258ca7e1891de18d62158a0a"

set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down