ujjwalguptaofficial / JsStore

Simplifying IndexedDB with SQL like syntax and promises
http://jsstore.net/
MIT License
858 stars 110 forks source link

Object doesn't support property or method 'findIndex' in ie while using jsstore #75

Closed kamalakkanni closed 6 years ago

kamalakkanni commented 6 years ago

Hi,

Object doesn't support property or method 'findIndex' in ie while using jsstore. [https://github.com/ujjwalguptaofficial/JsStore/issues/45] This issue is not yet fixed.pls help me to fix it.

Thanks and Regards Kamalakkanni.V

ujjwalguptaofficial commented 6 years ago

Could you add below code globally ?

if (!Array.prototype.findIndex) {
    Object.defineProperty(Array.prototype, 'findIndex', {
      value: function(predicate) {
       // 1. Let O be ? ToObject(this value).
        if (this == null) {
          throw new TypeError('"this" is null or not defined');
        }

        var o = Object(this);

        // 2. Let len be ? ToLength(? Get(O, "length")).
        var len = o.length >>> 0;

        // 3. If IsCallable(predicate) is false, throw a TypeError exception.
        if (typeof predicate !== 'function') {
          throw new TypeError('predicate must be a function');
        }

        // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
        var thisArg = arguments[1];

        // 5. Let k be 0.
        var k = 0;

        // 6. Repeat, while k < len
        while (k < len) {
          // a. Let Pk be ! ToString(k).
          // b. Let kValue be ? Get(O, Pk).
          // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
          // d. If testResult is true, return k.
          var kValue = o[k];
          if (predicate.call(thisArg, kValue, k, o)) {
            return k;
          }
          // e. Increase k by 1.
          k++;
        }

        // 7. Return -1.
        return -1;
      },
      configurable: true,
      writable: true
    });
  }

if you are getting confused about how to add it - just add it in index.html file under script section. Let me know what's the result.

kamalakkanni commented 6 years ago

Thanks,But I got same error

ujjwalguptaofficial commented 6 years ago

could you run this in console of ie where you are getting this error.

var array1 = [5, 12, 8, 130, 44];

function findFirstLargeNumber(element) {
  return element > 13;
}

console.log(array1.findIndex(findFirstLargeNumber));

let me know whats you are getting.

kamalakkanni commented 6 years ago

I am getting below output undefined 3

ujjwalguptaofficial commented 6 years ago

it means that findIndex is working. In this case - you are including the findIndex script after the jsstore. Please make sure that you are including the findIndex script before jsstore initialize.

kamalakkanni commented 6 years ago

You mean

`

     <script>
      if (!Array.prototype.findIndex) {
     Object.defineProperty(Array.prototype, 'findIndex', {
     value: function(predicate) {
   // 1. Let O be ? ToObject(this value).
    if (this == null) {
      throw new TypeError('"this" is null or not defined');
    }

    var o = Object(this);

    // 2. Let len be ? ToLength(? Get(O, "length")).
    var len = o.length >>> 0;

    // 3. If IsCallable(predicate) is false, throw a TypeError exception.
    if (typeof predicate !== 'function') {
      throw new TypeError('predicate must be a function');
    }

    // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
    var thisArg = arguments[1];

    // 5. Let k be 0.
    var k = 0;

    // 6. Repeat, while k < len
    while (k < len) {
      // a. Let Pk be ! ToString(k).
      // b. Let kValue be ? Get(O, Pk).
      // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
      // d. If testResult is true, return k.
      var kValue = o[k];
      if (predicate.call(thisArg, kValue, k, o)) {
        return k;
      }
      // e. Increase k by 1.
      k++;
    }

    // 7. Return -1.
    return -1;
  },
  configurable: true,
  writable: true
});

}

`
ujjwalguptaofficial commented 6 years ago

yes

kamalakkanni commented 6 years ago

but not working.same error

ujjwalguptaofficial commented 6 years ago

could you confirm if its the same error. I mean is it saying - findIndex or just find ? Please read the whole error message. Better paste the screenshot here.

kamalakkanni commented 6 years ago

TypeError: Object doesn't support property or method 'findIndex'

ujjwalguptaofficial commented 6 years ago

ok. add this before the findIndex.

// https://tc39.github.io/ecma262/#sec-array.prototype.find
if (!Array.prototype.find) {
    Object.defineProperty(Array.prototype, 'find', {
      value: function(predicate) {
       // 1. Let O be ? ToObject(this value).
        if (this == null) {
          throw new TypeError('"this" is null or not defined');
        }

        var o = Object(this);

        // 2. Let len be ? ToLength(? Get(O, "length")).
        var len = o.length >>> 0;

        // 3. If IsCallable(predicate) is false, throw a TypeError exception.
        if (typeof predicate !== 'function') {
          throw new TypeError('predicate must be a function');
        }

        // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
        var thisArg = arguments[1];

        // 5. Let k be 0.
        var k = 0;

        // 6. Repeat, while k < len
        while (k < len) {
          // a. Let Pk be ! ToString(k).
          // b. Let kValue be ? Get(O, Pk).
          // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
          // d. If testResult is true, return kValue.
          var kValue = o[k];
          if (predicate.call(thisArg, kValue, k, o)) {
            return kValue;
          }
          // e. Increase k by 1.
          k++;
        }

        // 7. Return undefined.
        return undefined;
      },
      configurable: true,
      writable: true
    });
  }

let me know

ujjwalguptaofficial commented 6 years ago

Ok, I would create a demo which will support the ie. This will help you to see what's going wrong. I will upload the demo by tomorrow.

Thanks

kamalakkanni commented 6 years ago

not yet solved.ok thanks

kamalakkanni commented 6 years ago

Hi,any update on this

ujjwalguptaofficial commented 6 years ago

Hi

Yes I am working on this. I am creating separate build for ie support. This may take some time, not sure how much.

On Tue 18 Sep, 2018, 7:43 PM kamalakkanni, notifications@github.com wrote:

Hi,any update on this

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ujjwalguptaofficial/JsStore/issues/75#issuecomment-422409187, or mute the thread https://github.com/notifications/unsubscribe-auth/AKbo9x9pFBQwu_PPT9p1AWz9xma0gMtCks5ucP-MgaJpZM4WlV-4 .

kamalakkanni commented 6 years ago

Hi,this is just remainder.If u finished means,pls let me know

ujjwalguptaofficial commented 6 years ago

yep i m working on it.

ujjwalguptaofficial commented 6 years ago

Hi @kamalakkanni - I have created the build for ie. There is separate file for ie support which contains inbuilt polyfill. Here is the example - https://github.com/ujjwalguptaofficial/JsStore/tree/master/examples/webpack%20with%20ie%20support

So basically you need to use - jsstore.worker.ie.js instead of jsstore.worker.js . You can use minified version or dev version, its upto you.

Hope this will help you.

ujjwalguptaofficial commented 6 years ago

@kamalakkanni - just found, its not stable. Please ignore the above suggestion. I need to work more on this.

ujjwalguptaofficial commented 6 years ago

@kamalakkanni - issue is resolved. Please install latest verson - 2.4.3. For supporting in ie - you need to use the file : jsstore.worker.ie.min.js . its a special build for working in ie through webworker.

Here is the example for more help - https://github.com/ujjwalguptaofficial/JsStore/tree/master/examples/webpack%20with%20ie%20support

Please let me know if everything is working for you.

kamalakkanni commented 6 years ago

Thank you so much.its working fine now