Skip to content

Commit

Permalink
Upgrade to 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaybhatia committed Mar 25, 2021
1 parent fe7cae0 commit dd33deb
Show file tree
Hide file tree
Showing 17 changed files with 2,362 additions and 1,344 deletions.
172 changes: 110 additions & 62 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
## Meteor
# Meteor React Native Docs

Table of Contents
- [Meteor](#meteor)
- [Tracker](#tracker)
- [Mongo](#mongo)
- [Accounts](#accounts)

<h2 id="meteor">Meteor</h2>

`import Meteor from '@ajaybhatia/react-native-meteor';`

### `Meteor.connect(url, options)`

### `Meteor.connect(url, options)`
Connect to the Meteor Server

**url**: The URL of your Meteor Server websocket. This should typically start with `ws://` (insecure, like `http://`) or `wss://` (secure, like `https://`), and have the path `/websocket`, e.g.: `wss://myapp.meteor.com/websocket`

**options**:

- autoConnect **boolean** [true] whether to establish the connection to the server upon instantiation. When false, one can manually establish the connection with the Meteor.ddp.connect method.
- autoReconnect **boolean** [true] whether to try to reconnect to the server when the socket connection closes, unless the closing was initiated by a call to the disconnect method.
- reconnectInterval **number** [10000] the interval in ms between reconnection attempts.
- AsyncStorage **object** your preferred AsyncStorage. Defaults to `'@react-native-community/async-storage'` as a peer dependency. You will likely want to use `{ AsyncStorage } from 'react-native'` if using Expo
* autoConnect **boolean** [true] whether to establish the connection to the server upon instantiation. When false, one can manually establish the connection with the Meteor.ddp.connect method.
* autoReconnect **boolean** [true] whether to try to reconnect to the server when the socket connection closes, unless the closing was initiated by a call to the disconnect method.
* reconnectInterval **number** [10000] the interval in ms between reconnection attempts.
* AsyncStorage **object** your preferred AsyncStorage. Defaults to `'@react-native-async-storage/async-storage'` as a peer dependency.

### `Meteor.disconnect()`

Disconnect from the Meteor server

### `Meteor.call(name, [arg1, arg2...], [asyncCallback])`

Perform a call to a method

### `Meteor.subscribe(name, [arg1, arg2, arg3])`

Subscribe to a collection

### `Meteor.user()`

Returns the logged in user

### `Meteor.users`

Access the meteor users collection

### `Meteor.userId()`

Returns the userId of the logged in user

### `Meteor.status()`

Gets the current connection status. Returns an object with the following properties:

**connected**: Boolean

**status**: "connected" || "disconnected"

### `Meteor.loggingIn()`

Returns true if attempting to login

### `Meteor.loginWithPassword`
Expand All @@ -57,78 +56,127 @@ Returns true if attempting to login

### `Meteor.logoutOtherClients`

## withTracker

`import { withTracker } from '@ajaybhatia/react-native-meteor'`;

The `withTracker` component is used the same way as [`meteor/react-meteor-data`](https://guide.meteor.com/react.html#using-withTracker)
<h2 id="tracker">Tracker</h2>

`import { withTracker, useTracker } from '@ajaybhatia/react-native-meteor'`;

```javascript
export default withTracker(() => {
let handle = Meteor.subscribe('mySubscription');
let loading = !handle.ready();
let myStuff = Stuff.find({}).fetch();

return {
myStuff,
};
})(MyComponent);
```
#### `withTracker(trackerFunc)(Component)`
Creates a new Tracker

## useTracker (Experimental)
**Arguments:**
* trackerFunc - Function which will be re-run reactively when it's dependencies are updated. Must return an object that is passed as properties to `Component`
* Component - React Component which will receive properties from trackerFunc

`import { useTracker } from '@ajaybhatia/react-native-meteor'`;

The `useTracker` component is used the same way as [`meteor/react-meteor-data`](https://github.com/meteor/react-packages/tree/master/packages/react-meteor-data#usetrackerreactivefn-deps-hook)
#### `useTracker(trackerFunc)` => `React Hook`
Creates a new Tracker React Hook. Can only be used inside a function component. See React Docs for more info.

```javascript
function Foo({ listId }) {
const currentUser = useTracker(() => Meteor.user(), []);
**Arguments:**
* trackerFunc - Function which will be re-run reactively when it's dependencies are updated.

const listLoading = useTracker(() => {
const handle = Meteor.subscribe('todoList', listId);
return !handle.ready();
}, [listId]);
const tasks = useTracker(() => Tasks.find({ listId }).fetch(), [listId]);

return (
...
);
}
```

## ReactiveDict

`import { ReactiveDict } from '@ajaybhatia/react-native-meteor'`

https://atmospherejs.com/meteor/reactive-dict
#### `new ReactiveDict()` => *`ReactiveDict`*
Creates a new reactive dictionary


#### *`ReactiveDict`*

***ReactiveDict* Methods:**
* .get(key) - Gets value of key (Reactive)
* .set(key, value) - Sets value of key


## Mongo

<h2 id="mongo">Mongo</h2>

`import { Mongo } from '@ajaybhatia/react-native-meteor';`

#### `Mongo.Collection(collectionName, options)`
#### `new Mongo.Collection(collectionName, options)` => `Collection`
Creates and returns a *Collection*

_collectionName_: Name of the remote collection, or pass `null` for a client-side collection
**Arguments**
* collectionName - Name of the remote collection, or pass `null` for a client-side collection


#### *`Collection`*

***Collection* Methods:**
* .insert(document) - Inserts document into collection
* .update(query, modifications) - Updates document in collection
* .remove(query) - Removes document from collection
* .find(query) => *`Cursor`* - Returns a Cursor
* .findOne(query) => Document - Retrieves first matching Document

**options**:

- [.insert(doc, callback)](http://docs.meteor.com/#/full/insert)
- [.update(id, modifier, [options], [callback])](http://docs.meteor.com/#/full/update)
- [.remove(id, callback(err, countRemoved))](http://docs.meteor.com/#/full/remove)
#### *`Cursor`*

#### _Cursor_.observe
***Cursor* Methods:**
* .obsrve() - Mirrors Meteor's observe behavior. Accepts object with the properties `added`, `changed`, and `removed`.
* .fetch() => `[Document]` - Retrieves an array of matching documents

Mirrors Meteor's observe behavior. Accepts object with the properties `added`, `changed`, and `removed`.

## Accounts

<h2 id="accounts">Accounts</h2>

`import { Accounts } from '@ajaybhatia/react-native-meteor';`

- [Accounts.createUser](http://docs.meteor.com/#/full/accounts_createuser)
- [Accounts.changePassword](http://docs.meteor.com/#/full/accounts_forgotpassword)
- [Accounts.forgotPassword](http://docs.meteor.com/#/full/accounts_changepassword)
- [Accounts.resetPassword](http://docs.meteor.com/#/full/accounts_resetpassword)
- [Accounts.onLogin](http://docs.meteor.com/#/full/accounts_onlogin)
- [Accounts.onLoginFailure](http://docs.meteor.com/#/full/accounts_onloginfailure)
- `Accounts._hashPassword` - SHA-256 hashes password, for use with methods that may require authentication

#### `Accounts.createUser(user, callback)`
Creates a user

**Arguments**
* user - The user object
* callback - Called with a single error object or null on success


#### `Accounts.changePassword(oldPassword, newPassword)`
Changes a user's password

**Arguments**
* oldPassword - The user's current password
* newPassword - The user's new password


#### `Accounts.onLogin(callback)`
Registers a callback to be called when user is logged in

**Arguments**
* callback


#### `Accounts.onLoginFailure(callback)`
Registers a callback to be called when login fails

**Arguments**
* callback


#### `Accounts._hashPassword(plaintext)` => `{algorithm:"sha-256", digest:"..."}`
Hashes a password using the sha-256 algorithm. Returns an object formatted for use in accounts calls. You can access the raw hashed string using the digest property.

**Arguments**
* plaintext - The plaintext string you want to hash

Other:

* [Accounts.forgotPassword](http://docs.meteor.com/#/full/accounts_changepassword)
* [Accounts.resetPassword](http://docs.meteor.com/#/full/accounts_resetpassword)



## Verbosity
`import { enableVerbose } from '@ajaybhatia/react-native-meteor';`

Verbose Mode logs detailed information from various places around MeteorRN. **Note:** this will expose login tokens and other private information to the console.


#### `enableVerbose()`
Enables verbose mode
4 changes: 2 additions & 2 deletions lib/ddp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class DDP extends EventEmitter {
this.reconnectInterval =
options.reconnectInterval || DEFAULT_RECONNECT_INTERVAL;

this.messageQueue = new Queue(message => {
this.messageQueue = new Queue((message) => {
if (this.status === 'connected') {
this.socket.send(message);
return true;
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class DDP extends EventEmitter {
}
});

this.socket.on('message:in', message => {
this.socket.on('message:in', (message) => {
if (message.msg === 'connected') {
this.status = 'connected';
this.messageQueue.process();
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let support = {};
// Populate the class2type map
_.each(
'Boolean Number String Function Array Date RegExp Object Error'.split(' '),
function(name, i) {
function (name, i) {
class2type['[object ' + name + ']'] = name.toLowerCase();
}
);
Expand Down
55 changes: 23 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@

{
"name": "@ajaybhatia/react-native-meteor",
"version": "2.0.4",
"version": "2.1.0",
"description": "Full Meteor Client for React Native",
"main": "src/Meteor.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --require test/setup --recursive"
},
"lint-staged": {
"*.{js,json,md}": [
"prettier --write",
"git add"
]
},
"main": "src/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/ajaybhatia/react-native-meteor.git"
Expand All @@ -25,40 +17,39 @@
"ios",
"android"
],
"author": "Ajay Bhatia",
"license": "MIT",
"bugs": {
"url": "https://github.com/ajaybhatia/react-native-meteor/issues"
},
"homepage": "https://github.com/ajaybhatia/react-native-meteor#readme",
"dependencies": {
"@babel/runtime": "^7.11.2",
"base-64": "^0.1.0",
"crypto-js": "^3.3.0",
"ejson": "^2.2.0",
"@ajaybhatia/minimongo-cache": "^0.1.3",
"prop-types": "^15.7.2",
"trackr": "^2.0.2",
"underscore": "^1.11.0",
"wolfy87-eventemitter": "^5.2.9"
"@babel/runtime": "^7.9.6",
"base-64": "^0.1.0",
"crypto-js": "^3.1.6",
"ejson": "^2.1.2",
"node-require-fallback": "^1.0.0",
"prop-types": "^15.5.10",
"underscore": "^1.8.3",
"wolfy87-eventemitter": "^4.3.0"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-preset-react-native": "^4.0.1",
"chai": "^4.2.0",
"husky": "^4.3.0",
"lint-staged": "^10.3.0",
"mocha": "^8.1.3",
"mock-socket": "^9.0.3",
"prettier": "2.1.1",
"sinon": "^9.0.3"
"babel-core": "^6.7.2",
"babel-preset-react-native": "^4.0.0",
"chai": "^3.5.0",
"husky": "^0.14.3",
"lint-staged": "^7.1.2",
"mocha": "^2.4.5",
"mock-socket": "^2.0.0",
"prettier": "1.12.1",
"sinon": "^1.17.3"
},
"optionalDependencies": {
"@react-native-community/async-storage": ">=1.12.0"
"@react-native-async-storage/async-storage": ">=1.8.1"
},
"peerDependencies": {
"react": "*",
"@react-native-community/netinfo": "*",
"react-native": ">=0.60.0"
"react": "*",
"react-native": ">= 0.60.0"
}
}
4 changes: 2 additions & 2 deletions src/Call.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Data from './Data';

export default function(eventName) {
export default function (eventName) {
const args = Array.prototype.slice.call(arguments, 1);
if (args.length && typeof args[args.length - 1] === 'function') {
var callback = args.pop();
let callback = args.pop();
}

const id = Data.ddp.method(eventName, args);
Expand Down
Loading

0 comments on commit dd33deb

Please sign in to comment.