react-native-meteor
Advanced tools
Comparing version 1.0.0-beta16 to 1.0.0-beta17
{ | ||
"name": "react-native-meteor", | ||
"version": "1.0.0-beta16", | ||
"version": "1.0.0-beta17", | ||
"description": "DDP React-native Client", | ||
@@ -5,0 +5,0 @@ "main": "src/Meteor.js", |
@@ -15,3 +15,3 @@ [](https://badge.fury.io/gh/inProgress-team%2Freact-native-meteor) | ||
Meteor-like methods for React Native. **Currently in v1.0.0-beta16** ! For old docs, see [v0.6.2 documentation](https://github.com/inProgress-team/react-native-meteor/tree/0.6.2) (classic ddp interface). | ||
Meteor-like methods for React Native. **Currently in v1.0.0-beta17** ! For old docs, see [v0.6.2 documentation](https://github.com/inProgress-team/react-native-meteor/tree/0.6.2) (classic ddp interface). | ||
@@ -111,4 +111,3 @@ ## What is it for ? | ||
* [.insert(doc, callback)](http://docs.meteor.com/#/full/insert) | ||
* [.update(id, modifier, [options], [callback])](http://docs.meteor.com/#/full/update) (not implemented yet) | ||
* [.upsert(id, modifier, [options], [callback])](http://docs.meteor.com/#/full/upsert) (not implemented yet) | ||
* [.update(id, modifier, [options], [callback])](http://docs.meteor.com/#/full/update) | ||
* [.remove(id, callback(err, countRemoved))](http://docs.meteor.com/#/full/remove) | ||
@@ -158,5 +157,6 @@ * Meteor.FSCollection(collectionName) : Helper for [Meteor-CollectionFS](https://github.com/CollectionFS/Meteor-CollectionFS). Full documentation [here](https://github.com/inProgress-team/react-native-meteor/blob/master/docs/FSCollection.md) | ||
* [Meteor.call](http://docs.meteor.com/#/full/meteor_call) | ||
* [Meteor.loginWithPassword](http://docs.meteor.com/#/full/meteor_loginwithpassword) (Please note that user is auto-resigned in - like in Meteor Web applications - thanks to React Native AsyncStorage.) | ||
* [Meteor.logout](http://docs.meteor.com/#/full/meteor_logout) | ||
* [Meteor.call](http://docs.meteor.com/#/full/meteor_call) | ||
* [Meteor.logoutOtherClients](http://docs.meteor.com/#/full/meteor_logoutotherclients) | ||
@@ -163,0 +163,0 @@ ## Meteor.Accounts |
@@ -6,6 +6,6 @@ import Data from './Data'; | ||
const Meteor = this; | ||
if(!Data.db[name]) { Data.db.addCollection(name) } | ||
return { | ||
find(selector, options) { | ||
if(!Data.db || !Data.db[name]) return []; | ||
if(typeof selector == 'string') return this.find({_id: selector}, options); | ||
@@ -16,3 +16,2 @@ return Data.db[name].find(selector, options) | ||
findOne(selector, options) { | ||
if(!Data.db || !Data.db[name]) return null; | ||
if(typeof selector == 'string') return this.findOne({_id: selector}, options); | ||
@@ -23,9 +22,21 @@ return Data.db[name] && Data.db[name].findOne(selector, options) | ||
insert(item, callback = ()=>{}) { | ||
if(!Data.db[name]) { Data.db.addCollection(name) } | ||
const id = Random.id(); | ||
const itemSaved = Data.db[name].upsert({...item, _id: id}); | ||
let id; | ||
if('_id' in item) { | ||
if(!item._id || typeof item._id != 'string') { | ||
return callback("Meteor requires document _id fields to be non-empty strings"); | ||
} | ||
id = item._id; | ||
} else { | ||
id = item._id = Random.id(); | ||
} | ||
if(Data.db[name].get(id)) return callback({error: 409, reason: "Duplicate key _id with value "+id}); | ||
Data.db[name].upsert(item); | ||
Meteor.waitDdpConnected(()=>{ | ||
Meteor.call('/'+name+'/insert', itemSaved, err => { | ||
Meteor.call('/'+name+'/insert', item, err => { | ||
if(err) { | ||
@@ -44,10 +55,3 @@ Data.db[name].del(id); | ||
update(id, modifier, options={}, callback=()=>{}) { | ||
if(typeof options == 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
console.info('Update not impletemented yet'); | ||
}, | ||
upsert(id, modifier, options={}, callback=()=>{}) { | ||
if(typeof options == 'function') { | ||
@@ -58,3 +62,13 @@ callback = options; | ||
console.info('Upsert not impletemented yet'); | ||
if(!Data.db[name].get(id)) return callback({error: 409, reason: "Item not found in collection "+name+" with id "+id}); | ||
Meteor.waitDdpConnected(()=>{ | ||
Meteor.call('/'+name+'/update', {_id: id}, modifier, err => { | ||
if(err) { | ||
return callback(err); | ||
} | ||
callback(null, id); | ||
}); | ||
}); | ||
}, | ||
@@ -61,0 +75,0 @@ remove(id, callback = ()=>{}) { |
@@ -71,5 +71,4 @@ import Collection from './Collection'; | ||
update: Collection(collectionName).update, | ||
upsert: Collection(collectionName).upsert, | ||
remove: Collection(collectionName).remove | ||
}; | ||
} |
@@ -48,2 +48,13 @@ import { AsyncStorage } from 'react-native'; | ||
}, | ||
logoutOtherClients(callback = ()=>{}) { | ||
this.call('getNewToken', (err, res) => { | ||
if(err) return callback(err); | ||
this._handleLoginCallback(err, res); | ||
this.call('removeOtherTokens', err=>{ | ||
callback(err); | ||
}) | ||
}); | ||
}, | ||
_startLoggingIn() { | ||
@@ -50,0 +61,0 @@ this._isLoggingIn = true; |
42646
995