-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
When closure is detected what about pre-processing using a combination of copying params/var decelerations to a state object (when those refs are used via closure) in the function and update all refs to point to this state.
And converting all declared functions in the closure to automatically invoked curried functions that apply the state ref via closure.
I believe this would fix any issues related to function scoping rules including referencing of primitive datatypes since the automatically invoked curried functions would be applied with object refs and would keep that reference even if the parent scope re-assigned a new object ref to the state object variable
Basically a statement like this
function someMethod(min, b) {
const val = b.find(s => s.min < min)
...
return someCondition ? someMethod(val.min, someStatementOf(val)) : val.min
}would convert to something like this
function someMethod(min, b) {
var _b, _min
...
while(true){
// at start of each iteration assign _state to a new object with updated values
// this allows for automatically invoked curried functions that were applied in a previous iteration to
// keep ref to that object while the next iteration scope can work cleanly on the new object with
// updated values
const _state = {
min,
}
const val = b.find((state => s => s.min < state['min'])(_state))
if(someCondition){
_min = val.min
_b = someStatementOf(val)
b = _b
min = _min
continue;
}
else {
return val.min
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels