ujjwalguptaofficial / JsStore

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

Runtime Error Instance() is not a constructor #24

Closed uvotguy closed 6 years ago

uvotguy commented 6 years ago

Hello,

I'm building a Vue.js app and trying to use JsStore as my persistence mechanism. I define a TypeScript class like this:

import * as JsStore from 'jsstore'
export class testDb {
    myConnection: JsStore.Instance
    constructor() {
      this.myConnection  = new JsStore.Instance('testDatabase');
    }
  }

When I try to instantiate my class like this:

var myDb = new testDb();

I get the following error:

Uncaught TypeError: WEBPACK_IMPORTED_MODULE_0_jsstore.Instance is not a constructor

Been banging my head over this. Any help would be appreciated.

Scott

ujjwalguptaofficial commented 6 years ago

Hi

Are you writing the code in typescript ?

ujjwalguptaofficial commented 6 years ago

Btw - check out this : https://gist.github.com/ujjwalguptaofficial/d0289a52e1dc5175a157975b0c5fc1e5.

Hope this will help you. Let me know if its not.

uvotguy commented 6 years ago

Yes. I'm writing my code in TypeScript. I'll have a look at your post. Thank you!

uvotguy commented 6 years ago

This did not work. Stuck :-/

ujjwalguptaofficial commented 6 years ago

ok, are you getting the same error or something else ?

uvotguy commented 6 years ago

Same error.

ujjwalguptaofficial commented 6 years ago

oho ok. Can you look into this article - http://ujjwalguptaofficial.blogspot.in/2017/10/angular4-crud-operation-in-indexeddb.html and do as it says.

This is for angular but you will be able to understand how to make it work.

uvotguy commented 6 years ago

Will do. This is an Angular.js project. I'm using Vue.js (node). Are you suggesting I try creating an Angular project like this, or are you suggesting I start a new Vue project and implement this code?

ujjwalguptaofficial commented 6 years ago

I am suggesting that go through the article. You will get the concept of how to use it. Since you are using Typescript and article is also in ts, it will be helpful.

By the way - the whole concept will be to declare a var JsStore and use the code and include the jsstore file directly in index.html.

if you want to get intillisense support, import one one class like -

import {Instance} from 'JsStore' and use it as typing. See below screenshot for more help.

image

Basically in order to execute in web worker, there should not be any code which have dom or any other code which can not be excuted inside web worker. So if you will compile jsstore code with your others code, it wont be executed in web worker.

Thanks

ujjwalguptaofficial commented 6 years ago

Are you getting issue any more ?

ujjwalguptaofficial commented 6 years ago

Hi @uvotguy - please close this issue if you are not getting issue any more otherwise let me know - I will create a demo for you.

Thanks

ujjwalguptaofficial commented 6 years ago

@uvotguy - we have solved the problem in jsstore v2 - now you can write using es6, build with weback, also you can use in typescript, angular etc.

See examples in examples folder for more info and how to do this. Let me know if something is not working for you.

Thanks