react-native-meteor
Advanced tools
Comparing version 0.2.0 to 0.3.0
48
index.js
@@ -48,4 +48,4 @@ var DDP = require("ddp.js"); | ||
if(typeof collectionName != 'string') { | ||
callback = params; | ||
params = collectionName; | ||
callback = params; | ||
collectionName = name; | ||
@@ -65,3 +65,4 @@ } | ||
ready: false, | ||
items: [] | ||
items: [], | ||
itemsSubs: [] | ||
}); | ||
@@ -71,3 +72,35 @@ | ||
}, | ||
itemSuscribe: function (name, collectionName, id, callback) { | ||
if(typeof callback == 'undefined') { | ||
callback = id; | ||
id = collectionName; | ||
collectionName = name; | ||
} | ||
var sub = subscriptions.find((subscription)=>{return name==subscription.name && collectionName == subscription.collectionName}); | ||
if(sub) { | ||
var subId = parseInt(Math.random()*100000000000, 10); | ||
sub.itemsSubs.push({ | ||
subId: subId, | ||
id: id, | ||
callback: callback | ||
}); | ||
return subId; | ||
} | ||
return false; | ||
}, | ||
itemUnsuscribe: function (name, collectionName, subId) { | ||
if(typeof subId == 'undefined') { | ||
subId = collectionName; | ||
collectionName = name; | ||
} | ||
var sub = subscriptions.find((subscription)=>{return name==subscription.name && collectionName == subscription.collectionName}); | ||
for(var i in sub.itemsSubs) { | ||
if(sub.itemsSubs[i].subId == subId) { | ||
sub.itemsSubs.splice(i, 1); | ||
} | ||
} | ||
}, | ||
connect: function (endpoint) { | ||
@@ -169,6 +202,13 @@ ddp = new DDP({ | ||
if(item.id==message.id) { | ||
return { | ||
var res = { | ||
...item, | ||
...message.fields | ||
}; | ||
} | ||
//NOTIFY ITEMS subs | ||
sub.itemsSubs.map(subItem=>{ | ||
if(subItem.id == res.id) { | ||
subItem.callback(res); | ||
} | ||
}); | ||
return res; | ||
} | ||
@@ -175,0 +215,0 @@ return item; |
{ | ||
"name": "react-native-meteor", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "DDP React-native Client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -96,2 +96,28 @@ [](https://badge.fury.io/gh/inProgress-team%2Freact-native-meteor) | ||
### itemSuscribe(name, collectionName, id, callback) | ||
Subscribes to an item in a collection (the collection need to be suscribed with same name and collection name parameter). Returns the subscriptionId. | ||
#### Arguments | ||
- `name` **string** *required* : name of the server subscription | ||
- `collectionName` **string** *optional* : name of the collection you suscribe (in case the subscription name is different than collection name) | ||
- `id` **array** *required* : id of the item to suscribe to | ||
- `callback` **function** *required* : callback called when there is a change to the item. Returns the element. | ||
### itemUnsubscribe(name, collectionName, subId) | ||
Unsubscribes to a item subscription. | ||
#### Arguments | ||
- `name` **string** *required* : name of the server subscription | ||
- `collectionName` **string** *optional* : name of the collection you suscribe (in case the subscription name is different than collection name) | ||
- `subId` **string** *required* : id of the subscription | ||
### on(eventName, callback) | ||
@@ -98,0 +124,0 @@ |
13475
222
166