Skip to content

Instantly share code, notes, and snippets.

@ylixir
Created April 23, 2020 15:12
Show Gist options
  • Save ylixir/2269db3264b4e1909cf9d9dd9962335e to your computer and use it in GitHub Desktop.
Save ylixir/2269db3264b4e1909cf9d9dd9962335e to your computer and use it in GitHub Desktop.
notes on elm ffi hackery
D.decodeValue
(D.field "return" D.float)
(En.object [ ( "__elm-js-ffi", En.list En.float [ 1, 2 ] ) ])
//note passing in an object under flags might be better than monkey patching the Object object
Object.defineProperty(Object.prototype, `__elm-js-ffi`, {
set(args) {
this.return = add(...args);
}
});
function add(a, b) {
return a + b;
}
const setTimeoutOld = setTimeout;
globalThis.setTimeout = (callback, time, ...args) => {
if (time === -1) {
const
{ name
, args
} = JSInElm.nextTask;
JSInElm.tasks[name](...args)
.then(result => {
JSInElm.taskResults[name] = result;
callback();
});
} else {
return setTimeoutOld(callback, time, ...args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment