Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Update demos and docs to work with 1.6, break out a special RN build
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewimm committed Sep 12, 2015
1 parent 8ada322 commit 1f19ff2
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 186 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,23 @@ in your dependencies.

```js
var React = require('react');
var Parse = require('parse').Parse;
var Parse = require('parse');
var ParseReact = require('parse-react');

// ...
```

As of version 1.6, the Parse JS SDK has a different build for React Native.
If you're using Parse+React on React Native, you'll need to require the
`'parse-react/react-native'` package instead.

```js
// For React Native apps
var React = require('react-native');
var Parse = require('parse/react-native');
var ParseReact = require('parse-react/react-native');
```

Now that you've included all of the necessary libraries, you're ready to start
[subscribing to Parse data](/docs/Subscriptions.md) and
[mutating it](/docs/DataMutations.md).
Expand Down
1 change: 0 additions & 1 deletion class.js

This file was deleted.

4 changes: 2 additions & 2 deletions demos/AnyBudget/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

var React = require('react');
var Parse = require('parse').Parse;
var Parse = require('parse');

// Insert your app's keys here:
Parse.initialize('APPLICATION_ID', 'JAVASCRIPT_KEY');
Expand All @@ -31,4 +31,4 @@ var LoginWrapper = require('./LoginWrapper.react.js');
React.render(
<LoginWrapper />,
document.getElementById('app')
);
);
6 changes: 3 additions & 3 deletions demos/AnyBudget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"main": "js/app.js",
"dependencies": {
"react": "^0.13.0",
"parse": "^1.4.0",
"parse-react": "^0.1.3"
"parse": "^1.6.0",
"parse-react": "^0.5.0"
},
"devDependencies": {
"browserify": "^6.2.0",
Expand All @@ -19,4 +19,4 @@
"reactify"
]
}
}
}
2 changes: 1 addition & 1 deletion demos/todo/js/TodoList.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var Parse = require('parse').Parse;
// ParseReact sits on top of your Parse singleton
var ParseReact = require('parse-react');
var React = require('react');
var ParseComponent = require('parse-react/class')
var ParseComponent = ParseReact.Component(React);

var TodoItem = require('./TodoItem.react.js');
var TodoCreator = require('./TodoCreator.react.js');
Expand Down
2 changes: 1 addition & 1 deletion demos/todo/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

var React = require('react');
var Parse = require('parse').Parse;
var Parse = require('parse');

// Insert your app's keys here:
Parse.initialize('APPLICATION_ID', 'JAVASCRIPT_KEY');
Expand Down
4 changes: 2 additions & 2 deletions demos/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"main": "js/app.js",
"dependencies": {
"react": "^0.13.0",
"parse": "^1.4.0",
"parse-react": "^0.3.0"
"parse": "^1.6.0",
"parse-react": "^0.5.0"
},
"devDependencies": {
"babelify": "^6.0.2",
Expand Down
18 changes: 11 additions & 7 deletions docs/api/ES6.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

If you're writing an application with ES6 classes, it's not possible to
integrate the Parse + React Mixin. In those cases, you can extend
`ParseComponent`: a subclass of `React.Component` that allows the observation of
Parse Queries and Local Subscriptions.
`ParseReact.Component`: a subclass of `React.Component` that allows the
observation of Parse Queries and Local Subscriptions.

By default, `ParseComponent` will not be loaded into your application. You can
include it by requiring the `'parse-react/class'` subpackage.
Because `ParseReact.Component` depends on your `React` singleton, you need to
pass your instance of React to it. The class returned from calling
`ParseReact.Component()` will extend `React.Component`, and can be used anywhere
a standard Component can be used.

```js
var ParseComponent = require('parse-react/class');
var React = require('react');
var ParseReact = require('parse-react');
var ParseComponent = ParseReact.Component(React);

class MyComponent extends ParseComponent {
constructor() {
Expand All @@ -33,5 +37,5 @@ class MyComponent extends ParseComponent {
```

All of the methods available from `ParseReact.Mixin` are also available on
`ParseComponent`. A list of these supported methods is available in [the Mixin
documentation](/docs/api/Mixin.md).
`ParseReact.Component`. A list of these supported methods is available in [the
Mixin documentation](/docs/api/Mixin.md).
12 changes: 8 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
var insert = require('gulp-insert');
var replace = require('gulp-replace');
var path = require('path');

var pkg = require('./package.json');

var BUILD = process.env.REACT_NATIVE ? 'react-native' : 'browser';

function versionHeader() {
return (
'/*\n' +
Expand Down Expand Up @@ -53,10 +56,11 @@ function fullHeader() {

// Compile ES6 + Flow source into ES5 code for the npm package
gulp.task('lib', function() {
return gulp.src('./src/*.js')
.pipe(babel())
.pipe(replace(/@flow/g, ''))
.pipe(gulp.dest('./lib'));
var stream = gulp.src('./src/*.js').pipe(babel());
if (process.env.REACT_NATIVE) {
stream = stream.pipe(replace(/require\('parse'\)/g, "require('parse/react-native')"));
}
return stream.pipe(gulp.dest(path.join('lib', BUILD)));
});

// Build the concatentated and compressed files for CDN and download
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/ParseReact.js');
module.exports = require('./lib/browser/ParseReact.js');
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"vinyl-source-stream": "~1.0.0"
},
"scripts": {
"test": "NODE_ENV=test jest",
"prepublish": "gulp"
"test": "NODE_ENV=test jest"
},
"jest": {
"rootDir": "src",
Expand Down
1 change: 1 addition & 0 deletions react-native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/react-native/ParseReact.js');
10 changes: 6 additions & 4 deletions src/LocalSubscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ var currentUser = {
ObjectStore.storeObject(flatten(Parse.User.current()));
}
callbacks.onNext(ObjectStore.getLatest(id));
} else if (Parse.Storage.async) {
} else if (Parse.Storage.async()) {
// It's possible we haven't loaded the user from disk yet
Parse.User._currentAsync().then((user) => {
Parse.User.currentAsync().then((user) => {
if (user !== null) {
id = new Id('_User', user.id);
if (!ObjectStore.getLatest(id)) {
ObjectStore.storeObject(flatten(user));
}
callbacks.onNext(ObjectStore.getLatest(id));
} else {
callbacks.onNext(null);
}
});
callbacks.onNext(null);
callbacks.onNext(undefined);
}
return {
dispose: () => {
Expand All @@ -84,7 +86,7 @@ var currentUser = {
current.set(attr, changes[attr]);
}
}
Parse.User._saveCurrentUser(current);
Parse.CoreManager.getUserController().setCurrentUser(current);
}
for (var oid in this.subscribers) {
var latest = null;
Expand Down
2 changes: 1 addition & 1 deletion src/MutationExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function encode(data: any, seen?: Array<any>): any {
objectId: id
};
}
if (data instanceof Parse.GeoPoint) {
if (data instanceof Parse.GeoPoint || data instanceof Parse.ACL) {
return data.toJSON();
}
if (data instanceof Parse.File) {
Expand Down
Loading

0 comments on commit 1f19ff2

Please sign in to comment.