GithubHelp home page GithubHelp logo

Comments (5)

tagomoris avatar tagomoris commented on July 17, 2024

success callback also receives null always at the 1st argument.
It's a good idea to remove the unused callback argument error, but my request to the idea is to make it optional, instead of just removing the error, for the compatibility of users' code.

from presto-client-node.

MasterOdin avatar MasterOdin commented on July 17, 2024

My only thought to make it optional would be a flag to the Client constructor to use or not use this behavior. I'm not sure there's a programmatic way to detect if an end user expects the error argument or not in their callback.

Would you be fine with the flag being opt out, so that new users don't need to worry about the null argument and existing users just need to toggle the flag on when upgrading, or for the flag to be opt in? My preference would be on making it opt out since:

  1. Ideally it'd be a flag could remove at some point in the future
  2. It makes it easier to make the TS types

For (2), if the behavior was opt in, then I'm not sure there's a way in TS to properly model this behavior that it renders it a lot less useful to me personally that I'd probably not bother with a PR to do this, and would then just leave it at the current status quo.

from presto-client-node.

tagomoris avatar tagomoris commented on July 17, 2024

callback.length returns the number of arguments. So the callback caller can handle the difference of callback function arguments.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length

from presto-client-node.

MasterOdin avatar MasterOdin commented on July 17, 2024

This would only work in the case where a callback only has two arguments (just columns) or that they always defined all arguments, which is almost certainly not true. JS does not care if you pass more arguments to a function than it allows for, e.g.:

const callback = () => {};
callback(1, 2, 3, 4, 5);

is perfectly valid JS.

As a further example, my current usage of the library looks like this:

client.execute({
    query: statement,
    state: (_, query_id) => {
        // save query_id for later use
    },
    columns: (_, columns) => {
        // save columns for later use
    },
    data: (_, data) => {
        // buffer data until we hit success
    },
    error: (error) => {
        // raise an error
    },
    success: () => {
        // process our buffered data, return to caller
    }
});

So in this case, the callback data.length === 2, and it's not possible to tell in a user transparent way that I want the library to provide me the old style of callback ((error, data)) or the new style ((data, columns)).

from presto-client-node.

tagomoris avatar tagomoris commented on July 17, 2024

Oh, wow, I missed the case to have fewer arguments than documents intentionally.
If we have a flag to skip error argument, it must be opt-in (its default value must be false) at first to not break compatibility of existing users' code.
My other idea is to have a set of callbacks with different names for fewer arguments.

from presto-client-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.