Skip to content

Conversation

@l15k4
Copy link
Contributor

@l15k4 l15k4 commented Dec 5, 2014

IDBTransaction#onabort signature is incorrect, throws :
TypeError: Attempted to assign to readonly property.
in runtime.

Please merge it soon, currently there is no way to even call tx.abort()... The call itself throws an error even without having tx.onabort callback registered, thank you

@l15k4
Copy link
Contributor Author

l15k4 commented Dec 5, 2014

I also found a problem with :
IDBTransaction#READ_ONLY
IDBTransaction#VERSION_CHANGE
IDBTransaction#READ_WRITE

returning java.util.String because it is sometimes missing in browser engines so you can't do :

val value = (IDBTransaction.READ_WRITE : UndefOr[String]).getOrElse("readwrite")

but hardcode :

val value = "readonly" 

which is a detail, I decided we should wait instead of introducing js.Any return type

@sjrd
Copy link
Member

sjrd commented Dec 5, 2014

The spec does not agree with you:
https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBDatabase-onabort
says onabort is an EventHandler, which is specified here:
http://www.w3.org/TR/html5/webappapis.html#eventhandler
as a function taking one argument (the event) and returning anything.

@sjrd
Copy link
Member

sjrd commented Dec 5, 2014

currently there is no way to even call tx.abort()... The call itself throws an error even without having tx.onabort callback registered, thank you

That can't be the fault of the definition of onabort anyway. If you don't use onabort, then it cannot influence anything. It might be that the definition of abort is wrong, though.

@l15k4
Copy link
Contributor Author

l15k4 commented Dec 5, 2014

Well, I was looking at mozilla.org, they work with Function0...

I'll investigate...

@l15k4
Copy link
Contributor Author

l15k4 commented Dec 5, 2014

Sorry I meant Function0 all the time...

@l15k4 l15k4 changed the title IDBTransaction onabort is Function1 IDBTransaction onabort is Function0 Dec 5, 2014
@sjrd
Copy link
Member

sjrd commented Dec 5, 2014

The example on https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase.onabort uses a function that does not take any param, which effectively ignores the event parameter. That does not mean that the param is not passed. By making it a js.Function0, you prevent people from using this param. With a js.Function1, all you have to do is ignore it:

db.onabort = { (e: Any) => // don't use `e` here }
@l15k4
Copy link
Contributor Author

l15k4 commented Dec 5, 2014

I see, I didn't know that this "ignore parameter" thingy is possible. The parameter must be of type js.Any for doing that? Why isn't it :

var onabort: js.Function1[Event, _] = ??? 

Well the fact that they allow you doing :
IDBDatabase.onabort
as well as :
IDBTransaction.onabort

Is really awful, I just have to be always assuming that it is the same at a certain point in time... It's like this across the entire API

@sjrd
Copy link
Member

sjrd commented Dec 5, 2014

It should indeed be js.Function1[Event, _].

@l15k4
Copy link
Contributor Author

l15k4 commented Dec 5, 2014

Oki, I'll fix the commit and make it Event and then try it out. It currently really doesn't let me call tx/db.onabort nomatter what the signature is, throwing :

TypeError: Attempted to assign to readonly property. 

on a simple example. I'll figure that out and push the correction. Thank you

@sjrd
Copy link
Member

sjrd commented Dec 5, 2014

Maybe experimenting with js.Dynamic might be easier before you figure out the right signature?

@l15k4
Copy link
Contributor Author

l15k4 commented Dec 5, 2014

I got it, it's the classic IDB-API-monster-screw-up problem that one doesn't know when a certain state is populated or not, for instance :

 val req = window.indexedDB.open(dbName) val tx = req.transaction // this request doesn't contain transaction, returns null

but

val req = window.indexedDB.deleteDatabase(name) val tx = req.transaction // this request does contain transaction

You simply have to always assume or investigate whether something is populated or is not, across the entire API... Or wheter to use req.onsuccess or tx.oncomplete ... brrr :-)

@l15k4 l15k4 force-pushed the IDBTransaction-onabort branch from 4c33558 to ea309aa Compare December 5, 2014 18:30
@l15k4 l15k4 changed the title IDBTransaction onabort is Function0 IndexedDb onabort callback functions have parameter of type Event Dec 6, 2014
@l15k4
Copy link
Contributor Author

l15k4 commented Dec 6, 2014

Btw I own IndexedDb apology for the "IDB-API-monster-screw-up" statement. It's just a classical scala vs javascript thing :-) Those transactions are implemented well from javascript developer point of view... It's not a trivial thing at all, the spec is quite big.

@sjrd
Copy link
Member

sjrd commented Dec 6, 2014

LGTM

sjrd added a commit that referenced this pull request Dec 6, 2014
IndexedDb onabort callback functions have parameter of type Event
@sjrd sjrd merged commit 43a684e into scala-js:master Dec 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants