GithubHelp home page GithubHelp logo

Comments (16)

nolanlawson avatar nolanlawson commented on July 3, 2024

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.

Iomegan avatar Iomegan commented on July 3, 2024

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.

nolanlawson avatar nolanlawson commented on July 3, 2024

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.

nolanlawson avatar nolanlawson commented on July 3, 2024

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.

Iomegan avatar Iomegan commented on July 3, 2024

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.

nolanlawson avatar nolanlawson commented on July 3, 2024

No, PouchDB has to be loaded first.

from relational-pouch.

Iomegan avatar Iomegan commented on July 3, 2024

Maybe I have to configure requires differently then. Looking into that...

from relational-pouch.

Iomegan avatar Iomegan commented on July 3, 2024

It now definitely loads in the correct order. - But still the same error. Maybe @calvinmetcalf could have a look into this. :)

from relational-pouch.

calvinmetcalf avatar calvinmetcalf commented on July 3, 2024

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.

Iomegan avatar Iomegan commented on July 3, 2024

Works perfectly. Thanks !! :)

from relational-pouch.

wishabhilash avatar wishabhilash commented on July 3, 2024

Am using requirejs and I can't understand the above snippet... :-/

Help please.

from relational-pouch.

calvinmetcalf avatar calvinmetcalf commented on July 3, 2024

@wishabhilash does this make sense ?

define(['pouchdb', 'relational-pouch'], function (PouchDB, relationalPouch){
    PouchDB.plugin(relationalPouch);
});

from relational-pouch.

wishabhilash avatar wishabhilash commented on July 3, 2024

@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.

nolanlawson avatar nolanlawson commented on July 3, 2024

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.

brachycera avatar brachycera commented on July 3, 2024

@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.

wishabhilash avatar wishabhilash commented on July 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.