Giter Club home page Giter Club logo

react-native-couchbase-lite-1's Introduction

react-native-couchbase-lite

Couchbase Lite binding for react-native on both iOS and Android.

Installation

$ npm install react-native-couchbase-lite --save

iOS

  • XCode CouchbaseLite project dependency set up: Drag the ReactCBLite Xcode project as a dependency project into your React Native Xcode project.

  • XCode ReactCBLite library dependency set up: Add ReactCBLite.a (from Workspace location) to the required Libraries and Frameworks.

  • From the Link Binary With Libraries section in the Build Phases of the top-level project, add the following frameworks in your Xcode project (they are dependencies for Couchbase Lite)

    • libsqlite3.0.tbd
    • libz.tbd
    • Security.framework
    • CFNetwork.framework
    • SystemConfiguration.framework
  • Download the Couchbase Lite iOS SDK from here and drag CouchbaseLite.framework, CouchbaseLiteListener.framework, CBLRegisterJSViewCompiler.h and libCBLJSViewCompiler.a in the Xcode project.

iOS (Cocoapods)

  • Install both npm modules:
$ npm install react-native
$ npm install react-native-couchbase-lite
  • In the Podfile, add dependencies:
pod 'React', :path => './node_modules/react-native'
pod 'ReactNativeCouchbaseLite', :path => './node_modules/react-native-couchbase-lite'
  • Install the Cocoapods dependencies:
$ pod install
  • So far so good! Next, you must install CBLRegisterJSViewCompiler.h and libCBLJSViewCompiler.a. You can download both components from here. Drag CBLRegisterJSViewCompiler.h into the couchbase-lite-ios Pod:

  • Add the libCBLJSViewCompiler.a static library:

Android

  • Add dependency to android/settings.gradle
...
include ':react-native-couchbase-lite'
project(':react-native-couchbase-lite').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-couchbase-lite/android')
  • Add android/build.gradle
allprojects {
    repositories {
        mavenLocal()
        jcenter()

        // add couchbase url
        maven {
            url "http://files.couchbase.com/maven2/"
        }
    }
}
  • Add android/app/build.gradle
apply plugin: 'com.android.application'

android {
    ...

    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.facebook.react:react-native:0.12.+'

    // Add this line:
    compile project(':react-native-couchbase-lite')
}
  • Register module in MainActivity.java

    import me.fraserxu.rncouchbaselite.*;  // <--- import
    
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mReactRootView = new ReactRootView(this);
    
            mReactInstanceManager = ReactInstanceManager.builder()
                    .setApplication(getApplication())
                    .setBundleAssetName("index.android.bundle")
                    .setJSMainModuleName("index.android")
                    .addPackage(new ReactCBLiteManager())  // <------- here
                    .addPackage(new MainReactPackage())
                    .setUseDeveloperSupport(BuildConfig.DEBUG)
                    .setInitialLifecycleState(LifecycleState.RESUMED)
                    .build();
    
            mReactRootView.startReactApplication(mReactInstanceManager, "MyApp", null);
    
            setContentView(mReactRootView);
        }
    

Usage

In your app entry, init and start the Couchbase Lite Listener

import {manager, ReactCBLite} from 'react-native-couchbase-lite'
// init the Listener with a port and login credentials
ReactCBLite.init(5984, 'admin', 'password', e => {})

// instantiate a new database
var database = new manager('http://admin:password@localhost:5984/', 'myapp');
database.createDatabase()
  .then((res) => {
    database.getAllDocuments()
      .then((res) => {
        this.setState({
          dataSource: this.state.dataSource.cloneWithRows(res.rows)
        });
      });

See the example project for a more in-depth use case.

Available commands

promise database.createDatabase();
promise database.createDesignDocument(string designDocumentName, object designDocumentViews);
promise database.createDocument(object json);
promise database.modifyDocuments(object json);
promise database.updateDocument(object json, string documentRevision);
promise database.getDesignDocument(string designDocumentName);
promise database.queryView(string designDocumentName, string viewName);
promise database.deleteDocument(string documentId, string documentRevision);
promise database.getAllDocuments();
promise database.getDocument();
promise database.replicate(string source, string target, boolean continuous);
void    database.listen();

LICENSE

MIT

react-native-couchbase-lite-1's People

Contributors

adamski avatar fraserxu avatar iwater avatar jamesnocentini avatar

Watchers

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