Comments (16)
To use this module with requirejs you should build it with browserify and use the --standalone
option:
git clone https://github.com/nolanlawson/relational-pouch.git
cd relational-pouch
browserify lib/index.js --standalone RelationalPouchOrWhateverYouWantToCallIt
Sorry for not supporting AMD directly; it just seemed like too much of a hassle to support so many build systems... 😩
from relational-pouch.
Thanks Nolan for the quick response. Unfortunately I still have the same error with the browserifyed version.
I also tried
sudo browserify lib/index.js --standalone RelationalPouch | derequire > RelationalPouch.js
with no luck.
Any idea?
from relational-pouch.
I'm sorry, I really don't know enough about AMD or Require.js to help you out here. :/
Calling in reinforcements: @calvinmetcalf do you know why our current plugin situation is broken for AMD folks and what I should advise them to do?
from relational-pouch.
So there was another issue where someone wanted it built as UMD, and it seems to have been resolved there. Could you take a look and tell me if that works? pouchdb-community/pouchdb-all-dbs#12
from relational-pouch.
Just tried that with no luck. Is it okay that the plugin gets loaded before pochDB itself gets loaded?
mkdir -p dist && browserify lib/index.js --standalone PouchDBPluginRationalPouch -o dist/pouchdb.relational-pouch.js && npm run min
from relational-pouch.
No, PouchDB has to be loaded first.
from relational-pouch.
Maybe I have to configure requires differently then. Looking into that...
from relational-pouch.
It now definitely loads in the correct order. - But still the same error. Maybe @calvinmetcalf could have a look into this. :)
from relational-pouch.
your problem is that you need to manually register relationalPouch onto pouchdb, The plugin only auto registers if it is on the window object so do
define(function (require, exports, module){
var PouchDB = require('pouchdb');
PouchDB.plugin(require('relational-pouch'));
});
from relational-pouch.
Works perfectly. Thanks !! :)
from relational-pouch.
Am using requirejs and I can't understand the above snippet... :-/
Help please.
from relational-pouch.
@wishabhilash does this make sense ?
define(['pouchdb', 'relational-pouch'], function (PouchDB, relationalPouch){
PouchDB.plugin(relationalPouch);
});
from relational-pouch.
@calvinmetcalf Thanks for the code. However, I have no idea where to put it.
I have put in requirejs config path:
'pouchdb': path/to/pouchdb,
'pouchdb_find': path/to/pouchdb_find
In shim:
pouchdb_find: {
deps: ['pouchdb'],
exports: 'pouchdb_find',
}
The following are the things I tried:
- Created another file with the above code and called it in config require. pouchdb_find came out to be undefined.
- Tried it writing inside 'init' of shim. Same thing.
Kindly explain it in a bit a detail so that once and for all it be solved for everyone. I would also update these info on some blog so that people get the help.
Thank you. :)
from relational-pouch.
I've been told that the only way to get my plugins to run in RequireJS is to build them in the Browserify "standalone" style. Luckily wzrd.in will do that for you: http://wzrd.in/standalone/relational-pouch@latest
In this case, you would just need to use whatever RequireJS mechanism you would use for importing a "global" script into RequireJS, since both of them export globals window.PouchDB
for the first script, window.relationalPouch
for the second script.
from relational-pouch.
@wishabhilash this is my requireJS setup to load pouchDB
require.config ({
paths : {
'PouchDb' : 'bower_components/pouchdb/dist/pouchdb',
'database' : 'database'
}
});
database.js file:
(function ( define ) {
'use strict';
define( ['PouchDb'],
function ( PouchDb ) {
var Database = function ( ) {
var db = new PouchDb('local_database');
return {
allDocs: function ( options ) {
return db.allDocs( options );
},
get: function ( id ) {
return db.get( id );
},
save: function ( obj ) {
return db.put( obj );
},
delete: function ( obj ) {
return db.remove( obj );
},
bulk: function ( obj ){
return db.bulkDocs( obj );
}
};
};
return [ Database ];
}
);
}( define ));
from relational-pouch.
Hi all, it seems I might have forgotten to post my reply, so thanks to @brachycera to revive this thread again.
@brachycera I think your approach rather limits the full power of PouchDB. So to all the requirejs users the following snippet would help you to setup PouchDB for requirejs.
- Follow @nolanlawson comment above to browserify the PouchDB and the PouchDB plugins (if you need any).
- Refer to then in requirejs config file.
require.config ({
paths : {
pouchdb: './path/to/pouchdb.min',
pouchdb_find: './path/to/pouchdb.find.min',
pouchdb_erase: './path/to/pouchdb.erase.min',
}
});
- Create another file pouchdbPluginLoader.js and put the following content in it.
define(['pouchdb', 'pouchdb_find', 'pouchdb_erase'], function(PouchDB, pouchdb_find, pouchdb_erase){
PouchDB.plugin(pouchdb_find);
PouchDB.plugin(pouchdb_erase);
})
- Use the following construct in require functions to refer to plugin loader. (this needs to be called only once, so this can be called in the entry point require function, in rest of the define functions pouchdb, pouchdb_find and pouchdb_erase needs to be called as per convention)
require([
...
'./app/constructs/pouchPluginLoader',
], function(...){
...
})
I hope this helps all the requirejs users. :)
from relational-pouch.
Related Issues (20)
- Dead link in documentation HOT 1
- Heelp!!!! new post not adding to authors HOT 2
- Depreciate IE8 support HOT 1
- Delete all schema docs.
- Is db.rel.find() have an option for paging? HOT 12
- How to use 'pouchdb-validation' and 'relational-pouch'?
- How does the sync performance of this compare to vanilla pouchdb?
- Handling error while saving Relational data
- Handling ECONNRESET HOT 4
- don't save hasMany/queryInverse with many-to-many HOT 2
- find and delete by id not working
- find action, slow performance HOT 2
- db.rel.findHasMany is not working HOT 3
- [help] CouchDb 3.0 - Partitioned Databases HOT 5
- Delete successful but data has not removed HOT 2
- How to return _conflicts attribute HOT 1
- how to get sort data? HOT 1
- why pouchdb.rel.find() works only with integer id? HOT 6
- React Native app crashes when try to import
- Confused about "hasMany" relationship (see description below) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from relational-pouch.