GithubHelp home page GithubHelp logo

csinowski / parsereact Goto Github PK

View Code? Open in Web Editor NEW

This project forked from parse-community/parsereact

0.0 1.0 0.0 129 KB

Seamlessly bring Parse data into your React applications.

Home Page: https://parse.com

License: Other

CSS 4.02% HTML 0.20% JavaScript 95.78%

parsereact's Introduction

Parse + React

Seamlessly bringing Parse data into your React applications.

Overview

Parse + React is an interface layer on top of the Parse JS SDK that provides simple access to the Parse API from React. It lets React components subscribe to Parse queries, and allows data mutations to be dispatched in a Flux-style manner. In the background, these subscriptions are managed in a way that lets these components automatically update as objects are created and modified, allowing user interfaces to be snappy and responsive.

Example

To add Parse data to a component, it simply needs to subscribe to a standard Parse Query. This is done through an implementation of the newly-proposed observe() API for React. The ParseReact Mixin allows a version of this new lifecycle method to be used today with Parse Queries.

var CommentBlock = React.createClass({
  mixins: [ParseReact.Mixin], // Enable query subscriptions

  observe: function() {
    // Subscribe to all Comment objects, ordered by creation date
    // The results will be available at this.data.comments
    return {
      comments: (new Parse.Query('Comment')).ascending('createdAt')
    };
  },

  render: function() {
    // Render the text of each comment as a list item
    return (
      <ul>
        {this.data.comments.map(function(c) {
          return <li>{c.text}</li>;
        })}
      </ul>
    );
  }
});

Whenever this component mounts, it will issue the query and the results will be attached to this.data.comments. Each time the query is re-issued, or objects are modified locally that match the query, it will update itself to reflect these changes.

Mutations are dispatched in the manner of Flux Actions, allowing updates to be synchronized between many different components without requiring views to talk to each other. All of the standard Parse data mutations are supported, and you can read more about them in the Data Mutation guide.

// Create a new Comment object with some initial data
ParseReact.Mutation.Create('Comment', {
  text: 'Parse <3 React'
}).dispatch();

Getting Started

You can download Parse + React from within this Github repo. It's also available on our CDN (minified), and on npm.

If you're not familiar with React, we recommend you first walk through their tutorials before adding Parse data to your React applications.

Parse + React adds new functionality when React and the Parse JS SDK are used together, and it requires that those libraries be in place before it is initialized. The easiest way to do this is to load them on your page before loading the Parse + React library:

<html>
  <head>
    <script src="http://fb.me/react-0.13.1.min.js"></script>
    <script src="https://www.parsecdn.com/js/parse-latest.js"></script>
    <!-- Now include parse-react.js -->
    <script src="https://www.parsecdn.com/js/parse-react.js"></script>
    
    ...

If you're using a tool like Webpack or Browserify to enable Common JS require statements, there are two approaches you can take. The first is to simply require Parse and React in every module that requires Parse + React:

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

// ...

However if this gets repetitive, you can add them to the global scope once in your app's entry point, and never require them again:

var React = window.React = require('react');
var Parse = window.Parse = require('parse').Parse;
// In every module, you can load Parse + React without worrying about dependencies
var ParseReact = require('parse-react');

Now that you've included all of the necessary libraries, you're ready to start subscribing to Parse data and mutating it.

Contributing

See the CONTRIBUTING file for information on how to help out.

License

Copyright (c) 2015, Parse, LLC. All rights reserved.

You are hereby granted a non-exclusive, worldwide, royalty-free license to use, copy, modify, and distribute this software in source code or binary form for use in connection with the web services and APIs provided by Parse.

As with any software that integrates with the Parse platform, your use of this software is subject to the Parse Terms of Service [https://www.parse.com/about/terms]. This copyright notice shall be included in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

parsereact's People

Contributors

andrewimm avatar stanleyw avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.