
react-native-meteor
Meteor-like methods for React Native. Currently in v1.0.0-beta3 ! 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.
- to match with 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, { connectMeteor } from 'react-native-meteor';
@connectMeteor
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>
)
})}
}
}
connectMeteor
startMeteorSubscriptions
Inside this method, you can create subscriptions (see below) when component is mounted. It will automatically unsubscribe if the component is unmounted.
Example usage
your server side:
Meteor.publish('todos', function(selector, options){
var selector = selector || {};
var options = options || {};
return Todos.find(selector, options);
});
your react-native client code:
Meteor.subscribe('todos', {status: 'done'}, {limit: 10, sort: {createdAt: -1}});
NOTE
- Meteor subscribe parameter still not supporting EJSON, so you can't pass param value like date, boolean etc. For now it's only support object of string (JSON)
- Meteor subscribe parameter already support Publish Composite. If you are using this package, related published collections will be available too in subscriptions.
getMeteorData
Inside getMeteorData, you can access any Meteor reactive data source, which means :
API
Meteor.connect(endpoint)
Connect to a DDP server. You only have to do this once in your app.
Arguments
Meteor methods
NOTE
Meteor call parameter still not supporting EJSON, so you can't pass param value like date, boolean etc. For now it's only support object of string (JSON)
Meteor.ddp
Once connected to the ddp server, you can access every method available in ddp.js.
- Meteor.ddp.on('added')
- Meteor.ddp.on('changed')
- ...