Probably

 --> IDBDatabase idb = Js.uncheckedCast(idbr.result);

would work too.

The point is is uncheckedCast is (AFAIU) considered dangerous.

There are two other casts that perform run-time checks but they have a 1) 
performance penalty and 2) some times throw exceptions not due to a bug but 
because the casting is invalid based on the type definitions GWT compiler knows 
about.

Here is the first type:
   a) Java cast         --> MyObject x = (MyObject) yourObject;
   b) Js checked cast   --> MyObject x = Js.cast(yourObject);
and of course
   c) Js unchecked cast --> MyObject x = Js.uncheckedCast(yourObject);

I think (not sure) that a) and b) are the same at least on development mode. 
Not so sure what they are doing in production mode.

My 2 cents of limited understanding...

   Vassilis



On 10/6/19 7:00 AM, Shawn Asamoto-Brown wrote:
OK, this works --> IDBDatabase idb = Js.<IDBDatabase> 
uncheckedCast(idbr.result);

                @SuppressWarnings({ "unchecked" })
        public  static  void initIndexedDb(){

                IDBFactory idbf=  IndexedDbGlobal.indexedDB;
                IDBOpenDBRequest idbr=  idbf.open(INDEXEDDB_NAME);
                
                idbr.onsuccess=  new  OnsuccessFn()  {

                        @Override
                        public  Object  onInvoke(elemental2.dom.Event  p0)  {

                                // fails w java.lang.ClassCastException
                                // IDBDatabase idb = (IDBDatabase) idbr.result;
                                // IDBDatabase idb = Js.<IDBDatabase> cast(db);

                                //this works
                                IDBDatabase idb=  Js.<IDBDatabase >  
uncheckedCast(idbr.result);

                                DOMStringList  dsl=  idb.objectStoreNames;

                                dsl.asList().forEach(s->  {
                                        Log.info("FOUND DB "  +  s);
                                });

                                return  idbr.result;
                        }
                };

                idbr.onerror=  new  OnerrorFn()  {

                        @Override
                        public  Object  onInvoke(elemental2.dom.Event  p0)  {
                                Log.error("OnerrorFn "  +  p0.type);
                                return  null;
                        }
                };
        }


On Sat, Oct 5, 2019 at 10:47 PM Shawn <[email protected] 
<mailto:[email protected]>> wrote:

    Meant to add that I am sure indexeddb is supported in all the browsers I am 
using.

    Here is the code again ... sorry about the previous formatting.

    IDBFactory idbf = IndexedDbGlobal./indexedDB/;

    IDBOpenDBRequest idbr = idbf.open(*/INDEXEDDB_NAME/*);

    idbr*.*onsuccess = new OnsuccessFn() {


    /@Override/

    public Object onInvoke(elemental2.dom.Event p0) {

                                             //error is next

    idb = (IDBDatabase)idbr.result;


    DOMStringList dsl = idb.objectStoreNames;


    dsl.asList().forEach(s -> {

    Log./error/("FOUND DB " + s);

    });

    return idbr.result;

    }

    };


    On Chrome desktop, I find the indexeddb I created in handwritten js code.  
I don't get why there is a ClassCastException in some browsers.  Is 
elemental2-indexeddb or gxt 2.9 (HEAD) not supported everywhere?

-- You received this message because you are subscribed to the Google Groups "GWT Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected] 
<mailto:[email protected]>.
    To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/cbc724a1-5b8b-4478-8119-02af3d279c2b%40googlegroups.com
 
<https://groups.google.com/d/msgid/google-web-toolkit/cbc724a1-5b8b-4478-8119-02af3d279c2b%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 
[email protected] 
<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/CAEQ-_W11k9ze2bQnnB9K_fiGhna1f8AkmO25pLKYqmbA9vy1OQ%40mail.gmail.com
 
<https://groups.google.com/d/msgid/google-web-toolkit/CAEQ-_W11k9ze2bQnnB9K_fiGhna1f8AkmO25pLKYqmbA9vy1OQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/f9e0cdc4-c280-5443-747b-2353363d4663%40gmail.com.

Reply via email to