daominhsangvn / web-meteor

Meteor Reactivity for your React application, inspired by react-native-meteor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

web-meteor

Meteor Reactivity for your Web application :)

What is it for ?

The purpose of this library is :

  • to set up and maintain a ddp connection with a ddp server, freeing the developer from having to do it on their own.
  • be fully compatible with web and help web developers.
  • to match with Meteor documentation used with Web.

Install

npm i --save git+https://github.com/daominhsangvn/web-meteor.git

Example usage

import Meteor from 'web-meteor';

Meteor.connect('ws://192.168.X.X:3000/websocket'); //do this only once

Reactive variables

These variables can be used inside getMeteorData or createContainer. They will be populated into your component if they change.

Additionals collection methods

These methods (except update) work offline. That means that elements are correctly updated offline, and when you reconnect to ddp, Meteor calls are taken care of.

API

Meteor Collections

Meteor.subscribe

Meteor.subscribe() returns an handle. If the component which called subscribe is unmounted, the subscription is automatically canceled.

Meteor.collection(collectionName, options)

You need pass the cursoredFind option when you get your collection if you want to use cursor-like method:

Meteor.collection("collectionName", { cursoredFind: true })

Or you can simply use find() to get an array of documents. The option default to false for backward compatibility. Cursor methods are available to share code more easily between a web app and a standard Meteor app.

Meteor DDP connection

Meteor.connect(endpoint, options)

Connect to a DDP server. You only have to do this once in your app.

Arguments

  • url string required
  • options object Available options are :
    • autoConnect boolean [true] whether to establish the connection to the server upon instantiation. When false, one can manually establish the connection with the Meteor.ddp.connect method.
    • autoReconnect boolean [true] whether to try to reconnect to the server when the socket connection closes, unless the closing was initiated by a call to the disconnect method.
    • reconnectInterval number [10000] the interval in ms between reconnection attempts.

Meteor.disconnect()

Disconnect from the DDP server.

Meteor methods

Availables packages

Meteor.Accounts

`import { Accounts } from 'web-meteor';``

Meteor.ddp

Once connected to the ddp server, you can access every method available in ddp.js.

  • Meteor.ddp.on('connected')
  • Meteor.ddp.on('added')
  • Meteor.ddp.on('changed')
  • ...

Author

Want to help ?

Pull Requests and issues reported are welcome! :)

About

Meteor Reactivity for your React application, inspired by react-native-meteor.

License:Apache License 2.0


Languages

Language:JavaScript 100.0%