Created
April 23, 2020 15:12
-
-
Save ylixir/2269db3264b4e1909cf9d9dd9962335e to your computer and use it in GitHub Desktop.
notes on elm ffi hackery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D.decodeValue | |
(D.field "return" D.float) | |
(En.object [ ( "__elm-js-ffi", En.list En.float [ 1, 2 ] ) ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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