Skip to content

Commit

Permalink
2.1.0 (#30)
Browse files Browse the repository at this point in the history
* Update MFA companion package

* Replace code for depreciated componentWillMount() (#10)

* Allow other AsyncStorage packages to be used

* Allows for option to specify AsyncStorage package...
Either React Native Async Storage (Expo), with fallback using @react-native-community/async-storage if no AsyncStorage is provided for backwards compatibility.

* Remove commented code

* Fix package version

* Add "Custom Storage Adapter" to Installation

* Update AsyncStorage options

* Bump package version to 2.0.2 since no longer a breaking change

* Throw an error instead of console error if no AsyncStorage installed

* Remove dead code `setItem()`

* Temporary solution to depreciated componentWillUpdate...
Using the [`UNSAFE_componentWillUpdate()`](https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate) version to get throgh React v17.

* Moved code to a constructor to replace componentWillMount()...
depreciated code

Co-authored-by: Nathaniel Dsouza <[email protected]>

* Add useTracker function (#17)

* Bump dev package version

* 2.1.0-beta1

* Removing useTracker.js from dev since author has said it is not ready

* Remove useTracker

* Remove unnecessary code

* add useTracker and rewrite withTracker to use it (#31)

fixes #29

* Merge changes from master into dev (#32)

* Update MFA companion package (#27)

* Create manual.yml

* Merge updates from master into dev (#37)

* Update MFA companion package (#27)

* Create manual.yml

* Create stale.yml

* Update stale.yml

* Update index.js

* Add a semicolon

* Remove unused assignment to options (#34)

* Remove unused assignment to options

* Mark SHA256 insufficient as wontfix

* Remove unused variable self

* Remove unused variable serializedValue

* Remove unused state properties loading

* Bump package version

* Deprecate `Meteor.collection` (lowercase-C)

* Update Mongo Docs

* Update api.md

* Update Accounts Docs

* Update Tracker and Verbosity Docs

* Start adding table of contents

* Refactor to remove require cycle

* 2.1.0-beta3

* 2.1.0-beta4

* local: Automaticallly commit changes to storage after .insert, .update, or .remove

* Update User.js

* 2.1.0-beta5

* Refactor code to remove require cycles

* Bump Package Version to 2.1.0-rc1

* Delete shiftleft-analysis.yml

* Update package version for release

Co-authored-by: Polaris Web Technology <[email protected]>
Co-authored-by: Sandeep Jain <[email protected]>
Co-authored-by: EC2 Default User <[email protected]>
Co-authored-by: Kelly Copley <[email protected]>
  • Loading branch information
5 people authored Dec 18, 2020
1 parent 8f3e040 commit 579a117
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 278 deletions.
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

0 comments on commit 579a117

Please sign in to comment.