Giter Site home page Giter Site logo

pouchdb-svelte's Introduction

pouchdb-svelte

PouchDB-Svelte is a PouchDB adaptation for Svelte Rollup.

Usage

npm i pouchdb-svelte
npm i -D rollup-plugin-node-polyfills

Svelte

//  rollup.config.js

import nodePolyfills from 'rollup-plugin-node-polyfills';

export default {
    plugins: [
        nodePolyfills(),
        ...
    ]
}
import PouchDB from 'pouchdb-svelte';

const testDB = new PouchDB('test');

Sapper

//  rollup.config.js

import nodePolyfills from 'rollup-plugin-node-polyfills';

export default {
    client: {
        plugins: [
            nodePolyfills(),
            ...
        ]
    }
}

//not in the server nor in the serviceworker
import PouchDB from 'pouchdb-svelte';

(() => {
    if(typeof process !== 'undefined') return; // stops the Sapper SSR 
    const testDB = new PouchDB('test');
})();

Notes:

  • You can put this script in any .svelte file in your app.
  • It is really important to block Sapper SSR in this script. Because SSR will try to run pouchdb-svelte (pouchdb-browser) and attempt to create the LevelDB database on the server. This is not a good thing for two reasons:
  1. The LevelDB adapter is not present in the pouchdb-browser vanilla.
  2. If you want to run a LevelDB database on your server (polka / express), it is better to use pouchdb or pouchdb-node.

You could use pouchdb-svelte for the Front and pouchdb for the Back.


Why don't use onMount ?

Example: We have two .svelte files.

  • parent.svelte
  • Child.svelte

Child.svelte is a component of parent.svelte.
In these two files there is an onMount function.

The svelte runtime will trigger Child.svelte onMount at the first time, then parent.svelte onMount at the second time.
This is a problem if you create a pouchdb instance in parent.svelte and if you want to use it in Child.svelte.

With pouchdb-svelte you don't have to use onMount and so you can create a single instance that can be passed to components.

API PouchDB

For full API documentation and guides on PouchDB, see PouchDB.com.

pouchdb-svelte's People

Contributors

axel-recolet avatar

Watchers

James Cloos avatar

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.