amok-loader's People
amok-loader's Issues
Need a better require
The default webpack require essentially looks like the following
(function(modules) {
var cache = {};
function require(id) {
if(cache[id]) {
return cache[id].exports;
}
var module = cache[id] = {
exports: {},
id: id,
loaded: false
};
modules[id].call(module.exports, module, module.exports, require);
module.loaded = true;
return module.exports;
}
require.modules = modules;
require.cache = cache;
})([
function module_0(module, exports, require) {
},
function module_1(module, exports, require) {
},
]);
The issue with this, is that you can't add new modules on the fly, despite modules being added to the arguments, it is doing just that, adding to the arguments.
So to allow new modules being included on the fly, we need to change the pattern here very slightly to have the modules returned from a function.
(function() {
var cache = {};
function modules() {
return [
function module_0(module, exports, require) {
},
function module_1(module, exports, require) {
},
]
};
function require(id) {
if(cache[id]) {
return cache[id].exports;
}
var module = cache[id] = {
exports: {},
id: id,
loaded: false
};
modules()[id].call(module.exports, module, module.exports, require);
module.loaded = true;
return module.exports;
}
require.modules = modules;
require.cache = cache;
})();
This way, all the modules defined in a bundle can be hot.
Do not evaluate
So, it occurred to me that the hole I've been digging is a dead end, which was evaluating code based on AST nodes after a little bit of code molding.
The problem is that, evaluated code can't be reached in the debugger, they are not apart of the source after all. That meant that after evaluation they would not be live like other functions when using amok. Also breakpoints won't work as expected, etc.
Another thing is that it was getting incredibly slow, partly to me adding the entire AST tree and source code as properties of the module, which would be exponential.
However, since functions are kept up to date via setScriptSource
, all we really need to do is stick our module code into some re-occurring function and we effectively have re-evaluation.
window.addEventListener('patch', function(event) {
console.log('my module');
});
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.