storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export sqlitePlugin object

axemclion opened this issue · comments

The www folder currently assigns sqlitePlugin object to root here. root is assigned to this, which happens to be window in case of Cordova, and so the plugin currently works.
However, cordova plugins require a module.exports so that the clobbers specified in plugin.xml works.
Suggested solution - add module.exports = root.sqlitePlugin at the end of the function here.

This error surfaced, when this plugin was used in ReactNative (example) using the react-native-plugin-adapter.

Tracked in this issue - axemclion/react-native-cordova-plugin#4

If you are ok, I can send in a pull request for this.

Thanks @axemclion. I still have to think about this a little. While a pull request is always welcome, your description with the Suggestion solution above is clear enough. Assuming I do include this I will be sure to give you the credit for the fix (along with the change to the CoffeeScript version to keep it up-to-date).

Also, I really like your react-native-cordova-plugin project and wish I had found it earlier. I will add a link to README.md when I get a chance. I suggest that you do not close axemclion/react-native-cordova-plugin#4 until we get this fixed.

The one thing I have against this change is that there are a couple of cases where I will need to support using SQLitePlugin.js outside of the Cordova framework. One example that I am working on is using the plugin from a web worker, where I really cannot use cordova.js and have to build another Javascript-native communication system.

I am planning to make a separate version to support some other extra features and am thinking about including the suggested solution there instead.

@brodybits I think that one solution could be to have all the core logic in one file, say SQLitePlugin.js, and then have adapters, once for webworkers, another for Cordova, etc. This way most of the logic will still be shared, and cordova specific parts are simply moved to a specific file.

@axemclion I would like to hold off on this for now. It would need some tweaking to work in a web worker, and also the suggested solution did not really work for me. There is now https://github.com/andpor/react-native-sqlite-storage that ports this project to React Native and I will recommend this in axemclion/react-native-cordova-plugin#4.

I am thinking to follow the advice in http://blog.vjeux.com/2011/javascript/javascript-one-line-global-export.html when I get around to this unless I find a better idea.