Skip to content

inProgress-team/react-native-meteor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Théo mathieu
Mar 2, 2016
6fee122 · Mar 2, 2016

History

41 Commits
Mar 2, 2016
Mar 2, 2016
Mar 2, 2016
Oct 29, 2015
Nov 4, 2015
Mar 2, 2016
Oct 29, 2015
Mar 2, 2016
Mar 2, 2016

Repository files navigation

GitHub version npm version Dependency Status devDependency Status MIT bitHound Score

react-native-meteor

Meteor-like methods for React Native. Currently in v1.0.0-beta1 ! For old docs, see v0.6.2 documentation (classic ddp interface).

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 react-native and help react-native developers.
  • Use the EXACT SAME METHODS as Meteor documentation used with React.

Install

npm i --save react-native-meteor

!! See detailed installation guide

Example usage

import { View, Text, Component } from 'react-native';
import Meteor, { MeteorMixin } from 'react-native-meteor';
import reactMixin from 'react-mixin';

/*
* Uses decorators (see detailed installation to activate it)
* Or use :

  class Todos extends Component {
    ...
  }
  reactMixin(Todos.prototype, MeteorMixin);
  export default Todos;

*/

@reactMixin.decorate(MeteorMixin)
export default class App extends Component {
  componentWillMount() {
    const url = 'http://192.168.X.X:3000/websocket';
    Meteor.connect(url);
  }
  startMeteorSubscriptions() {
    Meteor.subscribe('todos');
  }
  getMeteorData() {
    return {
      todos: Meteor.collection('todos').find()
    };
  }
  render() {
    const { todos } = this.data;

    {todos.map(todo=>{
      return (
        <View key={todo._id}>
          <Text>{todo.title}</Text>
        </View>
      )
    })}

  }
}

MeteorMixin

startMeteorSubscriptions

Subscribe to subscriptions when component is mounted. It automatically unsubscribes if the component is unmounted.

getMeteorData

Inside getMeteorData, you can access any Meteor reactive data source, that means :

API

Meteor.connect(endpoint)

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

Arguments

  • url string required

Meteor methods