fordth / jinqJs

jinqJs provides a simple way to perform SQL like queries on javaScript arrays, collections and web services using LINQ expressions.
Other
93 stars 29 forks source link

Removal of the Web Service feature #24

Open mcoakley opened 7 years ago

mcoakley commented 7 years ago

As I'm working through the testing of the system and moving towards more flexibility with the testing as well as full coverage I'm looking hard at the Web Service feature within jinqJs. While in simple cases I can see the need for the service - in production applications I would imagine it wouldn't be used much if at all. The reason I'm saying this is because more often all service calls will be abstracted away in order to provide consistent handling. This means that using the jinqJs web service function would create an outlier within the code base of an application. Additionally, the current implementations of the web service calls do not implement graceful handling of error conditions - therefore the implementations need to be augmented to handle these cases. At that point, the implementation of those methods becomes opinionated and may preclude the entire library from being used within an application.

I believe it would be cleaner to remove the functionality and simply require that users provide valid data to the library for the library to manipulate.

mcoakley commented 7 years ago

As I'm writing more tests for coverage I realized that I could make the Web Server feature a plugin by changing the calling structure of the plugins based upon a "plugin type". This won't break any existing code for plugins and will allow someone to write a web service type plugin as robust as they would like it.

I've refactored the _from method to allow this and have made some other simplifications but I have a question...

_from = function () {
      var collection = null;
      var callback = null;
      var collectionsLen = collections.length;

      if (arguments.length === 0) {
        return this;
      }

      if (arguments.length === 2 && isFunction(arguments[1])) {
        collection = arguments[0];
        callback = arguments[1];

        if (isString(collection)) {
          throw new Error("Web service calls no longer directly supported. " +
            "Use the fromWebService plugin for this type of call.");
        }

        collections.push(collection);
      } else {
        for (var index = 0; index < arguments.length; index++) {
          if (arguments[index] === null || 
            arguments[index].length === 0 ||
            isFunction(arguments[index]) // We don't support async here
          ) {
            continue;
          }

          collections.push(arguments[index]);
        }
      }

      if (collections.length > collectionsLen) {
        collections.func = "from";
        result = flattenCollection(collections);
      }

      return (isFunction(callback) ? callback : this);
    }

It appears that there is still a possibility of calling a callback but I'm not sure of the calling structure or why it would be used. NOTE that this is in line with the original code there is a case where you can call the _from method with 2 parameters and the first parameter isn't a string but the second parameter is a function which would mean that a callback will be called at the end. Can you let me know why this would be the case and how it would be used?

fordth commented 7 years ago

Hey Mike, I am so sorry for getting back to you. I understand your point and that sounds good to me. Thanks for the update!!!

Tom

On Mon, Nov 14, 2016 at 1:19 PM, Mike Coakley notifications@github.com wrote:

As I'm working through the testing of the system and moving towards more flexibility with the testing as well as full coverage I'm looking hard at the Web Service feature within jinqJs. While in simple cases I can see the need for the service - in production applications I would imagine it wouldn't be used much if at all. The reason I'm saying this is because more often all service calls will be abstracted away in order to provide consistent handling. This means that using the jinqJs web service function would create an outlier within the code base of an application. Additionally, the current implementations of the web service calls do not implement graceful handling of error conditions - therefore the implementations need to be augmented to handle these cases. At that point, the implementation of those methods becomes opinionated and may preclude the entire library from being used within an application.

I believe it would be cleaner to remove the functionality and simply require that users provide valid data to the library for the library to manipulate.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fordth/jinqJs/issues/24, or mute the thread https://github.com/notifications/unsubscribe-auth/AJoGAHVngHYqp5pgDhdVQUYZpyPrpmvlks5q-KYmgaJpZM4Kxoxg .

fordth commented 7 years ago

Nice, brilliant! I like that idea actually even better! (Disregard my other email, I read that before this one)

On Tue, Dec 6, 2016 at 1:42 PM, Mike Coakley notifications@github.com wrote:

As I'm writing more tests for coverage I realized that I could make the Web Server feature a plugin by changing the calling structure of the plugins based upon a "plugin type". This won't break any existing code for plugins and will allow someone to write a web service type plugin as robust as they would like it.

I've refactored the _from method to allow this and have made some other simplifications but I have a question...

` _from = function () { var collection = null; var callback = null; var collectionsLen = collections.length;

if (arguments.length === 0) { return this; }

if (arguments.length === 2 && isFunction(arguments[1])) { collection = arguments[0]; callback = arguments[1];

if (isString(collection)) {
  throw new Error("Web service calls no longer directly supported. " +
    "Use the fromWebService plugin for this type of call.");
}

collections.push(collection);

} else { for (var index = 0; index < arguments.length; index++) { if (arguments[index] === null || arguments[index].length === 0 || isFunction(arguments[index]) // We don't support async here ) { continue; }

  collections.push(arguments[index]);
}

}

if (collections.length > collectionsLen) { collections.func = "from"; result = flattenCollection(collections); }

return (isFunction(callback) ? callback : this); }

`

It appears that there is still a possibility of calling a callback but I'm not sure of the calling structure or why it would be used. NOTE that this is in line with the original code there is a case where you can call the _from method with 2 parameters and the first parameter isn't a string but the second parameter is a function which would mean that a callback will be called at the end. Can you let me know why this would be the case and how it would be used?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fordth/jinqJs/issues/24#issuecomment-265234737, or mute the thread https://github.com/notifications/unsubscribe-auth/AJoGAH7v4KK0uxYAUxeCHQTrM6tzQbQlks5rFayFgaJpZM4Kxoxg .

fordth commented 7 years ago

You might want to include the fix on Issue #25 Here is a sample of the issue https://jsfiddle.net/rongxike/r7Lc22ta/

mcoakley commented 7 years ago

I've added a regression test and the fix for issue #25.