react-native-meteor
Advanced tools
Comparing version 0.1.2 to 0.2.0
62
index.js
@@ -8,4 +8,31 @@ var DDP = require("ddp.js"); | ||
var loginWithEmailId, | ||
loginWithEmailCb; | ||
var loginWithTokenId, | ||
loginWithTokenCb; | ||
var methods = []; | ||
module.exports = { | ||
on: queue.on, | ||
loginWithToken: function (token, callback) { | ||
loginWithTokenCb = callback; | ||
loginWithTokenId = ddp.method("login", [{ resume: token }]); | ||
}, | ||
loginWithEmail: function (email, password, callback) { | ||
loginWithEmailCb = callback; | ||
loginWithEmailId = ddp.method("login", [{ | ||
user: { | ||
email: email | ||
}, | ||
password: password | ||
}]); | ||
}, | ||
method: function (event, param, callback) { | ||
var id = ddp.method(event, param); | ||
methods.push({ | ||
id: id, | ||
callback: callback | ||
}); | ||
}, | ||
unsuscribe: function (id) { | ||
@@ -56,3 +83,37 @@ ddp.unsub(id); | ||
ddp.on("result", function (message) { | ||
if (message.id === loginWithEmailId && typeof loginWithEmailCb == 'function') { | ||
if(message.error) { | ||
return loginWithEmailCb(message.error); | ||
} | ||
loginWithEmailCb(null, message.result); | ||
return; | ||
} | ||
if (message.id === loginWithTokenId && typeof loginWithTokenCb == 'function') { | ||
if(message.error) { | ||
return loginWithTokenCb(message.error); | ||
} | ||
loginWithTokenCb(null, message.result); | ||
return; | ||
} | ||
var index; | ||
for(var i in methods) { | ||
var method = methods[i]; | ||
if(message.id === method.id) { | ||
if(typeof method.callback == 'function') { | ||
if(message.error) { | ||
return method.callback(message.error); | ||
} | ||
method.callback(null, message.result); | ||
} | ||
//DELETE | ||
index = i; | ||
} | ||
} | ||
if(index) { | ||
methods.splice(index, 1); | ||
} | ||
}); | ||
ddp.on("added", function (message) { | ||
@@ -72,3 +133,2 @@ subscriptions = subscriptions.map(function (sub) { | ||
ddp.on("ready", function (message) { | ||
console.log('ready'); | ||
subscriptions = subscriptions.map(function (sub) { | ||
@@ -75,0 +135,0 @@ if(sub.id == message.subs[0]) { |
{ | ||
"name": "react-native-meteor", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "DDP React-native Client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -107,4 +107,34 @@ [](https://badge.fury.io/gh/inProgress-team%2Freact-native-meteor) | ||
### method(name, [args], callback) | ||
Call a method on the server | ||
#### Arguments | ||
- `name` **string** *required* | ||
- `args` **array** *required* | ||
- `callback` **method** | ||
### loginWithEmail(email, password, callback) | ||
Login to meteor server | ||
#### Arguments | ||
- `email` **string** *required* | ||
- `password` **string** *required* | ||
- `callback(err, result)` **method** | ||
### loginWithToken(token, callback) | ||
Login to meteor server via a token | ||
#### Arguments | ||
- `token` **string** *required* | ||
- `callback(err, result)` **method** | ||
#### Warning | ||
You can only do one subscription on a same collection at one time |
11270
184
140