Skip to content

Commit 579a117

Browse files
Nathaniel DsouzaPolarisWTsandeepjainEC2 Default Usercopleykj
authored
2.1.0 (#30)
* 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 <nate@kidzideaz.xyz> * 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 <PolarisWT@users.noreply.github.com> Co-authored-by: Sandeep Jain <sandeepjain@users.noreply.github.com> Co-authored-by: EC2 Default User <ec2-user@ip-172-31-90-84.ec2.internal> Co-authored-by: Kelly Copley <copleykj@gmail.com>
1 parent 8f3e040 commit 579a117

File tree

11 files changed

+211
-278
lines changed

11 files changed

+211
-278
lines changed

companion-packages/meteorrn-local/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ This package introduces the `Local.Collection`, which will mirror the specified
66

77
### Caveats
88
- 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
9-
- 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)
10-
- 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)
9+
- 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)
1110

1211
### Usage:
1312

companion-packages/meteorrn-local/index.js

+18
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ const Local = {
9393
});
9494
};
9595

96+
97+
LocalCol.insert = LocalCol.__insert;
98+
LocalCol.update = LocalCol.__update;
99+
LocalCol.remove = LocalCol.__remove;
100+
101+
LocalCol.insert = (...args) => {
102+
LocalCol.__insert(...args);
103+
storeLocalCol();
104+
};
105+
LocalCol.update = (...args) => {
106+
LocalCol.__update(...args);
107+
storeLocalCol();
108+
};
109+
LocalCol.remove = (...args) => {
110+
LocalCol.__remove(...args);
111+
storeLocalCol();
112+
};
113+
96114
LocalCol.loadPromise = loadData();
97115
LocalCol.save = storeLocalCol;
98116

docs/api.md

+104-34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
## Meteor
1+
# Meteor React Native Docs
2+
3+
Table of Contents
4+
- [Meteor](#meteor)
5+
- [Tracker](#tracker)
6+
7+
<h2 id="meteor">Meteor</h2>
28
`import Meteor from '@meteorrn/core';`
39

10+
411
### `Meteor.connect(url, options)`
512
Connect to the Meteor Server
613

@@ -46,60 +53,123 @@ Returns true if attempting to login
4653

4754
### `Meteor.logoutOtherClients`
4855

49-
## withTracker
50-
`import { withTracker } from '@meteorrn/core'`;
5156

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

54-
```javascript
55-
export default withTracker(() => {
56-
let handle = Meteor.subscribe("mySubscription");
57-
let loading = !handle.ready();
58-
let myStuff = Stuff.find({}).fetch();
59-
60-
return {
61-
myStuff
62-
};
63-
})(MyComponent);
64-
```
58+
<h2 id="tracker">Tracker</h2>
59+
`import { withTracker, useTracker } from '@meteorrn/core'`;
60+
61+
62+
#### `withTracker(trackerFunc)(Component)`
63+
Creates a new Tracker
64+
65+
**Arguments:**
66+
* 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`
67+
* Component - React Component which will receive properties from trackerFunc
68+
69+
70+
#### `useTracker(trackerFunc)` => `React Hook`
71+
Creates a new Tracker React Hook. Can only be used inside a function component. See React Docs for more info.
72+
73+
**Arguments:**
74+
* trackerFunc - Function which will be re-run reactively when it's dependencies are updated.
75+
76+
6577

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

69-
https://atmospherejs.com/meteor/reactive-dict
81+
#### `new ReactiveDict()` => *`ReactiveDict`*
82+
Creates a new reactive dictionary
83+
84+
85+
#### *`ReactiveDict`*
86+
87+
***ReactiveDict* Methods:**
88+
* .get(key) - Gets value of key (Reactive)
89+
* .set(key, value) - Sets value of key
90+
7091

7192

7293
## Mongo
7394
`import { Mongo } from '@meteorrn/core';`
7495

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

78-
**options**:
79-
* [.insert(doc, callback)](http://docs.meteor.com/#/full/insert)
80-
* [.update(id, modifier, [options], [callback])](http://docs.meteor.com/#/full/update)
81-
* [.remove(id, callback(err, countRemoved))](http://docs.meteor.com/#/full/remove)
99+
**Arguments**
100+
* collectionName - Name of the remote collection, or pass `null` for a client-side collection
101+
102+
103+
#### *`Collection`*
104+
105+
***Collection* Methods:**
106+
* .insert(document) - Inserts document into collection
107+
* .update(query, modifications) - Updates document in collection
108+
* .remove(query) - Removes document from collection
109+
* .find(query) => *`Cursor`* - Returns a Cursor
110+
* .findOne(query) => Document - Retrieves first matching Document
111+
112+
113+
#### *`Cursor`*
114+
115+
***Cursor* Methods:**
116+
* .obsrve() - Mirrors Meteor's observe behavior. Accepts object with the properties `added`, `changed`, and `removed`.
117+
* .fetch() => `[Document]` - Retrieves an array of matching documents
82118

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

86120

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

90-
* [Accounts.createUser](http://docs.meteor.com/#/full/accounts_createuser)
91-
* [Accounts.changePassword](http://docs.meteor.com/#/full/accounts_forgotpassword)
124+
125+
#### `Accounts.createUser(user, callback)`
126+
Creates a user
127+
128+
**Arguments**
129+
* user - The user object
130+
* callback - Called with a single error object or null on success
131+
132+
133+
#### `Accounts.changePassword(oldPassword, newPassword)`
134+
Changes a user's password
135+
136+
**Arguments**
137+
* oldPassword - The user's current password
138+
* newPassword - The user's new password
139+
140+
141+
#### `Accounts.onLogin(callback)`
142+
Registers a callback to be called when user is logged in
143+
144+
**Arguments**
145+
* callback
146+
147+
148+
#### `Accounts.onLoginFailure(callback)`
149+
Registers a callback to be called when login fails
150+
151+
**Arguments**
152+
* callback
153+
154+
155+
#### `Accounts._hashPassword(plaintext)` => `{algorithm:"sha-256", digest:"..."}`
156+
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.
157+
158+
**Arguments**
159+
* plaintext - The plaintext string you want to hash
160+
161+
Other:
162+
92163
* [Accounts.forgotPassword](http://docs.meteor.com/#/full/accounts_changepassword)
93164
* [Accounts.resetPassword](http://docs.meteor.com/#/full/accounts_resetpassword)
94-
* [Accounts.onLogin](http://docs.meteor.com/#/full/accounts_onlogin)
95-
* [Accounts.onLoginFailure](http://docs.meteor.com/#/full/accounts_onloginfailure)
96-
* `Accounts._hashPassword` - SHA-256 hashes password, for use with methods that may require authentication
97165

98-
## enableVerbose
166+
167+
168+
## Verbosity
99169
`import { enableVerbose } from '@meteorrn/core';`
100170

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

103-
````
104-
enableVerbose()
105-
````
174+
#### `enableVerbose()`
175+
Enables verbose mode

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@meteorrn/core",
3-
"version": "2.0.15",
3+
"version": "2.1.0",
44
"description": "Full Meteor Client for React Native",
5-
"main": "src/Meteor.js",
5+
"main": "src/index.js",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/TheRealNate/meteor-react-native.git"

src/Meteor.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import NetInfo from "@react-native-community/netinfo";
2-
31
import { name as packageName } from '../package.json';
42

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

19-
import withTracker from './components/ReactMeteorData';
17+
import withTracker from './components/withTracker';
18+
import useTracker from './components/useTracker';
2019

2120
import ReactiveDict from './ReactiveDict';
2221

23-
import User from './user/User';
24-
import Accounts from './user/Accounts';
25-
2622
let isVerbose = false;
2723

28-
module.exports = {
24+
const Meteor = {
2925
isVerbose,
3026
enableVerbose() {
3127
isVerbose = true;
3228
},
3329
Random,
34-
Accounts,
3530
Mongo,
3631
Tracker: Trackr,
3732
EJSON,
3833
ReactiveDict,
3934
Collection,
40-
collection(name, options) {
41-
console.error("Meteor.collection is deprecated. Use Mongo.Collection");
42-
return new Collection(name, options);
35+
collection() {
36+
throw new Error("Meteor.collection is deprecated. Use Mongo.Collection");
4337
},
4438
withTracker,
39+
useTracker,
4540
getData() {
4641
return Data;
4742
},
48-
...User,
4943
status() {
5044
return {
5145
connected: Data.ddp ? Data.ddp.status == 'connected' : false,
@@ -84,7 +78,7 @@ module.exports = {
8478
if((!endpoint.startsWith("ws") || !endpoint.endsWith("/websocket")) && !options.suppressUrlErrors) {
8579
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});`);
8680
}
87-
81+
8882
if (!options.AsyncStorage) {
8983
const AsyncStorage = require('@react-native-async-storage/async-storage').default;
9084

@@ -103,12 +97,18 @@ module.exports = {
10397
SocketConstructor: WebSocket,
10498
...options,
10599
});
106-
107-
NetInfo.addEventListener(({type, isConnected, isInternetReachable, isWifiEnabled}) => {
108-
if (isConnected && Data.ddp.autoReconnect) {
109-
Data.ddp.connect();
110-
}
111-
});
100+
101+
try {
102+
const NetInfo = require("@react-native-community/netinfo").default;
103+
NetInfo.addEventListener(({type, isConnected, isInternetReachable, isWifiEnabled}) => {
104+
if (isConnected && Data.ddp.autoReconnect) {
105+
Data.ddp.connect();
106+
}
107+
});
108+
}
109+
catch(e) {
110+
console.warn("Warning: NetInfo not installed, so DDP will not automatically reconnect");
111+
}
112112

113113
Data.ddp.on('connected', () => {
114114
// Clear the collections of any stale data in case this is a reconnect
@@ -155,9 +155,9 @@ module.exports = {
155155
_id: message.id,
156156
...message.fields,
157157
};
158-
158+
159159
Data.db[message.collection].upsert(document);
160-
160+
161161
runObservers("added", message.collection, document);
162162
});
163163

@@ -192,18 +192,18 @@ module.exports = {
192192
...message.fields,
193193
...unset,
194194
};
195-
195+
196196
const oldDocument = Data.db[message.collection].findOne({_id:message.id});
197-
197+
198198
Data.db[message.collection].upsert(document);
199-
200-
runObservers("changed", message.collection, document, oldDocument);
199+
200+
runObservers("changed", message.collection, document, oldDocument);
201201
}
202202
});
203203

204204
Data.ddp.on('removed', message => {
205205
if(Data.db[message.collection]) {
206-
const oldDocument = Data.db[message.collection].findOne({_id:message.id});
206+
const oldDocument = Data.db[message.collection].findOne({_id:message.id});
207207
Data.db[message.collection].del(message.id);
208208
runObservers("removed", message.collection, oldDocument);
209209
}
@@ -350,4 +350,4 @@ module.exports = {
350350
},
351351
};
352352

353-
export default module.exports;
353+
export default Meteor;

0 commit comments

Comments
 (0)