jfspencer / cordova-plugin-couchbase-lite

Couchbase Lite Cordova plugin that provides a standard cordova API
MIT License
1 stars 2 forks source link

Using with Ionic 3 Angular / Typescript Project #11

Open clariontools opened 7 years ago

clariontools commented 7 years ago

I wasn't expecting this plugin would be a simple plugin add for an Ionic 3 Angular / Typescript project. This may not even be on your radar, but it was something that I am currently evaluating. The current couchbaselabs/Couchbase-Lite-PhoneGap-Plugin is a bit weak by itself with Ionic 3. However, nraboy created couchbaselabs/cordova-couchbase which provides a JavaScript / TypeScript wrapper for the official phonegap plugin. I think it would be fairly easy to create a similar JS / TypeScript wrapper for the cordova-plugin-couchbase-lite plugin using what nraboy did as a starting point. My question is if this is a good approach or do you already have something similar that I just couldn't find?

If this is a good way to go please let me know and give me a little guidance on how this would differ or be implemented compared to nraboy's couchbaselabs/cordova-couchbase wrapper?

clariontools commented 7 years ago

If you want to take a look at the couchbaselabs/cordova-couchbase wrapper, it is here:

https://github.com/couchbaselabs/cordova-couchbase

jfspencer commented 7 years ago

@clariontools I wasn't aware of nraboy's Couchbase-Lite-PhonGap-Plugin wrapper. He is wrapping over the standard REST API, so outside of his external API shape the wrapper guts would be completely different for this project. I wrote a simple wrapper for the main project I use this plugin with. I have added a basic version of it to the repo here it depends on a global instance of lodash fyi, but that is easily changed to an import which would be more standard. the cbl.ts is setup to wrap around a single database, so usage would be

const wrapper = new cbl();
wrapper.init('dbName','syncUrl');
wrapper.sync(); //returns promise containing success or failure message
wrapper.getDoc('id'); //returns promise containing doc
clariontools commented 7 years ago

Thanks I got pretty far with that, but need more time to integrate properly with Ionic 3.

jfspencer commented 7 years ago

Cool let me know how I can help

jfspencer commented 7 years ago

It occurred to me that to properly support ionic3 the Promise/RxJS/Lodash wrapping should all happen inside the Typescript wrapper (instead of the cordova www api) so the library dependencies could be imported and injected normally instead of relying on global variables. Eventually the typescript wrapper should be merged into ionic-native itself

clariontools commented 7 years ago

That is a good point and while I really wanted to see how this would perform with Ionic 3, I started to realize that I do not have the time to do a proper integration atm. Since Ionic is quite a popular development framework, I suspect there would be a lot of interest in your approach. Maybe you could get nraboy to write a blog post about (and possibly contribute to) it since he has written many others over the past few years?