can we store function using shortstop?
ohpyupi opened this issue · 4 comments
ohpyupi commented
can we store function using shortstop?
I am curious if that is possible.
tlivings commented
As in create a protocol handler that makes a value the result of invoking a function? Or just sets the value to a function?
In any case, yes.
ohpyupi commented
const shortstop = require('shortstop');
const functionResolver = (func) => new Function(`return ${func}`)();
const json = {
"greeting": "function:(firstName, lastName) => { console.log('Hello ' + firstName + ' ' + lastName) }"
};
const resolver = shortstop.create();
resolver.use('function', functionResolver);
resolver.resolve(json, (err, data) => {
if (err) return console.error(err);
data.greeting('Jack', 'Domino');
});
Hi @tlivings thanks for your comment. I've tried to make my own implementation in the above example.
Do you think it could be a workable solution to my question?
tlivings commented
IMO why not just export the function and use the require
protocol handler to pull it in?
Are you wanting to inline code in the config?