Reactive compilable and executable scripts on client and server with mongodb.
meteor add shuttler:scripts
- Update
source
value - Server observe
changed
compilesource
intoscript
If the compilation was an error, information about it will be in the error
field.
if (Meteor.isClient) {
Shuttler.Scripts.find().observe({
changed(newDocument, oldDocument) {
console.log(newDocument);
(function(abc){
eval(newDocument.script);
})({ cde: 123 });
}
});
Shuttler.Scripts.insert({ source: '(()=>{console.log(abc)})()', type: 'js' });
}
// After time:
// {"_id":"iyAsxHdZ5Skmqo5BA","source":"(()=>{console.log(abc)})()","type":"js","script":"(function () {↵ console.log(abc);↵})();"}
// { cde: 123 }
SimpleSchema
{ type: Function.call(collection, userId, doc, fieldNames?, modifier?, options?) }
Here you can add your own types for compilation.
Out of box types support:
js
Meteor Babel version of JavaScriptjsx
React.js version of Meteor Babel JavaScript
()
It will make any collection storage script.
Boolean = true
Allows you to check the collection as scripts storage.
var document = Shuttler.Scripts.findOne();
if (Shuttler.collection(document.Collection()).isScripts) {
console.log('Is a script!');
}
Boolean
Allows you to check the document as a script.
var document = Shuttler.Scripts.findOne();
if (document.isScript) {
console.log('Is a script!');
}
module = { exports: {} }
require
/import
some script and return module exports.
var document = Shuttler.Scripts.findOne();
// document.source = "export default 123";
var module = document.eval();
module.exports.default; // 123
.eval
- fix big bug
jsx
type
isScript
andisScripts