This repository was archived by the owner on Mar 15, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +27
-16
lines changed
Expand file tree Collapse file tree 7 files changed +27
-16
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ Inspired by: [Building the Facebook Newsfeed with Relay](http://facebook.github.
1010
1111## Features
1212
13- - Official Relay-inspired API and syntax.
14- - Write declarative queries right in components as Promises.
13+ - Implements the official Relay API methods.
14+ - HOC: Higher-order component syntax just like Relay.
15+ - Write declarative queries as Promises.
1516- Isomorphic architecture supports server-side rendering.
1617- Works with React 0.12 and 0.13, and React Native!
1718
@@ -24,18 +25,23 @@ Inspired by: [Building the Facebook Newsfeed with Relay](http://facebook.github.
2425## Usage
2526
2627```` js
27- import React from " react" ;
28+ import React from " react" ;
2829import Transmit from " react-transmit" ;
2930
30- const Newsfeed = React .createClass (... );
31+ // Simpl React component.
32+ const Newsfeed = React .createClass ({
33+ render () {
34+ return this .props .stories .map ((story ) => < li> {story .content }< / li> );
35+ }
36+ });
3137
38+ // Higher-order Transmit component that will contain the above React component.
3239export default Transmit .createContainer (Newsfeed, {
3340 queryParams: {
3441 count: 10
3542 },
3643 queries: {
3744 stories (queryParams ) {
38- // All Transmit queries return a Promise.
3945 return Promise .all ([
4046 Story .getQuery (" story" )
4147 ]);
Original file line number Diff line number Diff line change 11{
22 "name" : " react-transmit" ,
33 "description" : " Relay-inspired library based on Promises instead of GraphQL." ,
4- "version" : " 2.5.0 " ,
4+ "version" : " 2.5.1 " ,
55 "license" : " BSD-3" ,
66 "repository" : {
77 "type" : " git" ,
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ const Like = React.createClass({
2323} ) ;
2424
2525/**
26- * Higher-Order Transmit component that will contain the above React component.
26+ * Higher-order Transmit component that will contain the above React component.
2727 */
2828export default Transmit . createContainer ( Like , {
2929 /**
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ const Main = React.createClass({
1717 </ InlineCss >
1818 ) ;
1919 } ,
20+ /**
21+ * This part is optional. It allows you to capture the query results.
22+ */
2023 onQuery ( promise ) {
2124 promise . then ( ( queryResults ) => {
2225 console . log ( "Main.onQuery: " , queryResults ) ;
Original file line number Diff line number Diff line change @@ -37,15 +37,15 @@ const Newsfeed = React.createClass({
3737 nextStoryId : this . props . queryParams . nextStoryId + 1
3838 } ) . then ( ( queryResults ) => {
3939 /**
40- * This part is optional. It allows you to capture the quert results.
40+ * This part is optional. It allows you to capture the query results.
4141 */
4242 console . log ( "Newsfeed.setQueryParams: " , queryResults ) ;
4343 } ) ;
4444 }
4545} ) ;
4646
4747/**
48- * Higher-Order Transmit component that will contain the above React component.
48+ * Higher-order Transmit component that will contain the above React component.
4949 */
5050export default Transmit . createContainer ( Newsfeed , {
5151 /**
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ const Story = React.createClass({
3838} ) ;
3939
4040/**
41- * Higher-Order Transmit component that will contain the above React component.
41+ * Higher-order Transmit component that will contain the above React component.
4242 */
4343export default Transmit . createContainer ( Story , {
4444 /**
Original file line number Diff line number Diff line change @@ -73,17 +73,13 @@ module.exports = function (Component, options) {
7373 this . currentParams = assign ( { } , Container . queryParams , externalQueryParams ) ;
7474
7575 if ( ! this . hasQueryResults ( ) ) {
76- var promise = this . setQueryParams ( { } ) ;
77-
78- if ( this . props . onQuery ) {
79- this . props . onQuery . call ( this , promise ) ;
80- }
76+ this . setQueryParams ( { } ) ;
8177 }
8278 } ,
8379 setQueryParams : function ( nextParams , optionalQueryName ) {
8480 var _this = this ;
8581
86- return new Promise ( function ( resolve , reject ) {
82+ var promise = new Promise ( function ( resolve , reject ) {
8783 var props = _this . props || { } ;
8884 var promise ;
8985
@@ -119,6 +115,12 @@ module.exports = function (Component, options) {
119115
120116 resolve ( promise ) ;
121117 } ) ;
118+
119+ if ( this . props . onQuery ) {
120+ this . props . onQuery . call ( this , promise ) ;
121+ }
122+
123+ return promise ;
122124 } ,
123125 /**
124126 * @returns {boolean } true if all queries have results.
You can’t perform that action at this time.
0 commit comments