OpenFn / core

The central job processing module used in OpenFn v1.

Home Page:https://www.openfn.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow 'chained functions' in top level call expressions

stuartc opened this issue · comments

If you try and create an expression like this:

get(
  "http://localhost:9292?flip=left"
).then(console.log.bind(console))

Turns into:

(function() {
  return execute(get(
    "http://localhost:9292?flip=left"
  ).then(console.log.bind(console)))(state);
})();

The compiler attaches the ...(state) callExpression onto the .then instead of the operation. This makes sense given how everything was originally designed - however it would be really nice not to have to use alterState in order to do this.

What we really want is the compiler to know that (in this case), get is an operation that needs to be called with state and add the call expression to that instead:

(function() {
  return execute(get(
    "http://localhost:9292?flip=left"
  )(state).then(console.log.bind(console)));    // <== callExpression on Operation instead
})();