treojs / treo

Consistent API to IndexedDB
http://treojs.com
MIT License
258 stars 18 forks source link

Using Promise by default #27

Open adriengibrat opened 9 years ago

adriengibrat commented 9 years ago

Hello,

I realize this is a big API breaking shift, but now promise are implemented in most browsers (but IE) and io.js, I'd expect to use it for everithing that's async.

The promise plugin is nice, but it has some drawbacks:

If it was the other way around, Treo just have to use decorated Promise or nodify all methods (nodify does not require to know function arity).

If you like the Idea, I'll be glad to send a PR. If not, I'd like to make it live as a fork.

alekseykulikov commented 9 years ago

Hello Adrien,

For me treo@1.0.0 should has 3 main features: modularity, normal polyfill and promises by default. I've been experimenting with Promises+IndexedDB in free-time and faced some problems, that block future development:

I would like to get your help, and first steps is to pass idv-request test suite in all browsers and make sure, that we don't require 250kb bluebird to make it work properly.

What do you think?

adriengibrat commented 9 years ago

Hello,

  • browsers have different Promise implementation, and for now only Chrome handles them right. The problem with micro tasks and IndexedDB transactions.
  • default browsers c++ implementation 2-5x slower

Ok, we need is to use a Promise A+ implementation with proper microtask (any implementation using https://github.com/kriskowal/asap should work fine)

And i'ts not really a polyfill we need... I'm thinking about using 'Promise.race' to decide to use native implementation or a polyfill. If there is a bring your own Promise version, the doc need strong warning about issues with slow Promise.

I would like to get your help, and first steps is to pass idv-request test suite in all browsers and make sure, that we don't require 250kb bluebird to make it work properly.

The test suite does pass with proper polyfill I guess. I really like this bare bone implementation of Promise A+.

I'm gonna test all this with https://ci.testling.com/ to automate test in multiple browsers...

If i got it right, you're in the process of splitting treo in smaller independant projects, so what's the plan for the curent treojs repo? Making PR on this repo may not be the best way to move forward?

alekseykulikov commented 9 years ago

Thank you, that's a very good points.

I'm thinking about using 'Promise.race'

I think, it would be better to leave this decision to developers. So by default treo uses available global promise implementation and allows to set specific library using treo.Promise, similar to idb-request .Promise property.

The test suite does pass with proper polyfill I guess. I really like this bare bone implementation of Promise A+.

I personally, also like then/promise, but as I tested, it fails even using asap. Need to discover why. The situation with tests:

I suppose, there're might be issues with my tests.

Making PR on this repo may not be the best way to move forward?

You are right. Let's try to make idb-request work in all supported browsers, and it will be easy to upgrade treo using it.

I'm gonna test all this with https://ci.testling.com/ to automate test in multiple browsers...

I'm not an expert, but it might be testling or zuul.

wclr commented 8 years ago

Aslo, if I have for example Promise polifill already loaded with other library (in my case System.js loader), hot to use it with treo, without loading installed treo's promise library dependency?

alekseykulikov commented 8 years ago

hey @whitecolor just wait a bit for treo@1, it will relay on Promise globally and use them by default. Or try treo@0.6.0-rc2, but it's quite experimental.

wclr commented 8 years ago

Ok, thanks, will be waiting!