Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6064ccf
Update MFA companion package
Aug 7, 2020
7e6cf86
Replace code for depreciated componentWillMount() (#10)
PolarisWT Aug 7, 2020
faf2ea3
Add useTracker function (#17)
sandeepjain Aug 7, 2020
11288f6
Bump dev package version
Aug 7, 2020
03bcd28
2.1.0-beta1
Aug 9, 2020
528ffce
Removing useTracker.js from dev since author has said it is not ready
Aug 9, 2020
01593b2
Remove useTracker
Aug 9, 2020
8ed4659
Remove unnecessary code
Aug 9, 2020
63f1ae5
add useTracker and rewrite withTracker to use it (#31)
copleykj Aug 9, 2020
137445a
Merge changes from master into dev (#32)
Aug 9, 2020
21a7ff4
Merge updates from master into dev (#37)
Aug 28, 2020
ad4c794
Bump package version
Aug 31, 2020
facc113
Merge branch 'master' into dev
Sep 8, 2020
d15d39e
Deprecate `Meteor.collection` (lowercase-C)
Sep 16, 2020
1556a2e
Update Mongo Docs
Sep 16, 2020
87f7469
Update api.md
Sep 16, 2020
9c14294
Update Accounts Docs
Sep 16, 2020
78af2c6
Update Tracker and Verbosity Docs
Sep 16, 2020
826b139
Start adding table of contents
Sep 16, 2020
3bab573
Refactor to remove require cycle
Dec 11, 2020
8852e46
2.1.0-beta3
Dec 11, 2020
e914293
2.1.0-beta4
Dec 11, 2020
6c2e2fe
local: Automaticallly commit changes to storage after .insert, .updat…
Dec 11, 2020
3cf2443
Merge branch 'master' into dev
Dec 11, 2020
3039ba1
Update User.js
Dec 11, 2020
cfd8f8e
2.1.0-beta5
Dec 11, 2020
78e4db3
Refactor code to remove require cycles
Dec 11, 2020
65cda3e
Bump Package Version to 2.1.0-rc1
Dec 11, 2020
4310f0e
Delete shiftleft-analysis.yml
Dec 11, 2020
1e42049
Update package version for release
Dec 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .github/workflows/shiftleft-analysis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions companion-packages/meteorrn-local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ This package introduces the `Local.Collection`, which will mirror the specified

### Caveats
- This package (currently) works by creating a second local Mongo Collection. This means you are esentially keeping two copies of each document (that you store locally) in memory. This issue can be mitigated by keeping an "age" or "version" on all your documents, and only publishing documents that have been changed from local
- This package (currently) does not support the automatical removal/expiry of documents. Once a document has been inserted into the local database, it is there forever (unless you manually call `remove` on the Local.Collection)
- Performing `.insert`, `.update`, `.remove`, etc on a Local.Collection only makes those modifications to the in-memory minimongo. Those changes won't be sent to the server, and those changes (currently) dont trigger the saving procedure, so they will not be committed to the disk (unless a remote change is made afterwards)
- This package (currently) does not support the automatic removal/expiry of documents. Once a document has been inserted into the local database, it is there forever (unless you manually call `remove` on the Local.Collection)

### Usage:

Expand Down
18 changes: 18 additions & 0 deletions companion-packages/meteorrn-local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ const Local = {
});
};


LocalCol.insert = LocalCol.__insert;
LocalCol.update = LocalCol.__update;
LocalCol.remove = LocalCol.__remove;

LocalCol.insert = (...args) => {
LocalCol.__insert(...args);
storeLocalCol();
};
LocalCol.update = (...args) => {
LocalCol.__update(...args);
storeLocalCol();
};
LocalCol.remove = (...args) => {
LocalCol.__remove(...args);
storeLocalCol();
};

LocalCol.loadPromise = loadData();
LocalCol.save = storeLocalCol;

Expand Down
138 changes: 104 additions & 34 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## Meteor
# Meteor React Native Docs

Table of Contents
- [Meteor](#meteor)
- [Tracker](#tracker)

<h2 id="meteor">Meteor</h2>
`import Meteor from '@meteorrn/core';`


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

Expand Down Expand Up @@ -46,60 +53,123 @@ Returns true if attempting to login

### `Meteor.logoutOtherClients`

## withTracker
`import { withTracker } from '@meteorrn/core'`;

The `withTracker` component is used the same way as [`meteor/react-meteor-data`](https://guide.meteor.com/react.html#using-withTracker)

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

return {
myStuff
};
})(MyComponent);
```
<h2 id="tracker">Tracker</h2>
`import { withTracker, useTracker } from '@meteorrn/core'`;


#### `withTracker(trackerFunc)(Component)`
Creates a new Tracker

**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


#### `useTracker(trackerFunc)` => `React Hook`
Creates a new Tracker React Hook. Can only be used inside a function component. See React Docs for more info.

**Arguments:**
* trackerFunc - Function which will be re-run reactively when it's dependencies are updated.



## ReactiveDict
`import { ReactiveDict } from '@meteorrn/core'`

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
`import { Mongo } from '@meteorrn/core';`

#### `Mongo.Collection(collectionName, options)`
*collectionName*: Name of the remote collection, or pass `null` for a client-side collection
#### `new Mongo.Collection(collectionName, options)` => `Collection`
Creates and returns a *Collection*

**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)
**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


#### *`Cursor`*

***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

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


## Accounts
`import { Accounts } from '@meteorrn/core';`

* [Accounts.createUser](http://docs.meteor.com/#/full/accounts_createuser)
* [Accounts.changePassword](http://docs.meteor.com/#/full/accounts_forgotpassword)

#### `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)
* [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

## enableVerbose


## Verbosity
`import { enableVerbose } from '@meteorrn/core';`

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


````
enableVerbose()
````
#### `enableVerbose()`
Enables verbose mode
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@meteorrn/core",
"version": "2.0.15",
"version": "2.1.0",
"description": "Full Meteor Client for React Native",
"main": "src/Meteor.js",
"main": "src/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/TheRealNate/meteor-react-native.git"
Expand Down
54 changes: 27 additions & 27 deletions src/Meteor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import NetInfo from "@react-native-community/netinfo";

import { name as packageName } from '../package.json';

if(packageName !== "@meteorrn/core") {
Expand All @@ -16,36 +14,32 @@ import Mongo from './Mongo';
import { Collection, runObservers, localCollections } from './Collection';
import call from './Call';

import withTracker from './components/ReactMeteorData';
import withTracker from './components/withTracker';
import useTracker from './components/useTracker';

import ReactiveDict from './ReactiveDict';

import User from './user/User';
import Accounts from './user/Accounts';

let isVerbose = false;

module.exports = {
const Meteor = {
isVerbose,
enableVerbose() {
isVerbose = true;
},
Random,
Accounts,
Mongo,
Tracker: Trackr,
EJSON,
ReactiveDict,
Collection,
collection(name, options) {
console.error("Meteor.collection is deprecated. Use Mongo.Collection");
return new Collection(name, options);
collection() {
throw new Error("Meteor.collection is deprecated. Use Mongo.Collection");
},
withTracker,
useTracker,
getData() {
return Data;
},
...User,
status() {
return {
connected: Data.ddp ? Data.ddp.status == 'connected' : false,
Expand Down Expand Up @@ -84,7 +78,7 @@ module.exports = {
if((!endpoint.startsWith("ws") || !endpoint.endsWith("/websocket")) && !options.suppressUrlErrors) {
throw new Error(`Your url "${endpoint}" may be in the wrong format. It should start with "ws://" or "wss://" and end with "/websocket", e.g. "wss://myapp.meteor.com/websocket". To disable this warning, connect with option "suppressUrlErrors" as true, e.g. Meteor.connect("${endpoint}", {suppressUrlErrors:true});`);
}

if (!options.AsyncStorage) {
const AsyncStorage = require('@react-native-async-storage/async-storage').default;

Expand All @@ -103,12 +97,18 @@ module.exports = {
SocketConstructor: WebSocket,
...options,
});

NetInfo.addEventListener(({type, isConnected, isInternetReachable, isWifiEnabled}) => {
if (isConnected && Data.ddp.autoReconnect) {
Data.ddp.connect();
}
});

try {
const NetInfo = require("@react-native-community/netinfo").default;
NetInfo.addEventListener(({type, isConnected, isInternetReachable, isWifiEnabled}) => {
if (isConnected && Data.ddp.autoReconnect) {
Data.ddp.connect();
}
});
}
catch(e) {
console.warn("Warning: NetInfo not installed, so DDP will not automatically reconnect");
}

Data.ddp.on('connected', () => {
// Clear the collections of any stale data in case this is a reconnect
Expand Down Expand Up @@ -155,9 +155,9 @@ module.exports = {
_id: message.id,
...message.fields,
};

Data.db[message.collection].upsert(document);

runObservers("added", message.collection, document);
});

Expand Down Expand Up @@ -192,18 +192,18 @@ module.exports = {
...message.fields,
...unset,
};

const oldDocument = Data.db[message.collection].findOne({_id:message.id});

Data.db[message.collection].upsert(document);
runObservers("changed", message.collection, document, oldDocument);

runObservers("changed", message.collection, document, oldDocument);
}
});

Data.ddp.on('removed', message => {
if(Data.db[message.collection]) {
const oldDocument = Data.db[message.collection].findOne({_id:message.id});
const oldDocument = Data.db[message.collection].findOne({_id:message.id});
Data.db[message.collection].del(message.id);
runObservers("removed", message.collection, oldDocument);
}
Expand Down Expand Up @@ -350,4 +350,4 @@ module.exports = {
},
};

export default module.exports;
export default Meteor;
Loading