Skip to content

Query params difference #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The methods are named after their React / Relay counterparts. Their functionalit
* Possible `options` are the `queryParams` and the `queries` definitions.
* [Example usage](https://github.com/RickWong/react-transmit/blob/c0266b061a2cfa7030500b932f3a88bf195e4465/src/example/Newsfeed.js#L50-L73)

#### `render(ReactClass, optionalProps, targetDOMNode) : void`
#### `render(ReactClass, optionalProps, targetDOMNode, completeCallback) : void`

* For isomorphic apps, client-side.
* Use it instead of `React.render()` when you're using Transmit's `renderToString()` on the server-side.
Expand All @@ -40,6 +40,10 @@ The methods are named after their React / Relay counterparts. Their functionalit
* This method is actually copied from [react-async](https://github.com/andreypopp/react-async). Thanks [@andreypopp](https://github.com/andreypopp)!
* [Example usage](https://github.com/RickWong/react-isomorphic-starterkit/blob/2bf29c747770e79de06e130af325e0bdfb216bc9/src/server.js#L52)

#### `setPromiseConstructor(PromiseConstructor) : void`

* Optional. Provide your preferred Promise implementation instead of using `global.Promise` by default.

## API: `Transmit.Container` (Higher-order component)

Transmit's `createContainer()` method describes a new React component, a so-called Higher-order component that wraps the original ReactClass. Like any React component you can pass props to it. Below are the Transmit-specific props. Your own props are just passed onto the original ReactClass.
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-transmit",
"description": "Relay-inspired library based on Promises instead of GraphQL.",
"version": "2.6.1",
"version": "2.6.3",
"license": "BSD-3",
"repository": {
"type": "git",
Expand All @@ -26,16 +26,16 @@
"ascii-json": "0.2.0"
},
"devDependencies": {
"babel-core": "5.2.13",
"babel-loader": "5.0.0",
"babel-runtime": "5.2.13",
"concurrently": "0.0.5",
"isomorphic-fetch": "2.0.2",
"json-loader": "0.5.1",
"react-hot-loader": "1.2.6",
"babel-core": "5.4.7",
"babel-loader": "5.1.3",
"babel-runtime": "5.4.7",
"concurrently": "0.1.1",
"isomorphic-fetch": "2.1.0",
"json-loader": "0.5.2",
"react-hot-loader": "1.2.7",
"react-inline-css": "1.1.1",
"webpack": "1.8.11",
"webpack-dev-server": "1.8.2"
"webpack": "1.9.10",
"webpack-dev-server": "1.9.0"
},
"engines": {
"node" : ">=0.10.32"
Expand Down
23 changes: 16 additions & 7 deletions src/lib/createContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
*/
"use strict";

var React = require("./react");
var assign = React.__spread;
var promiseProxy = require("./promiseProxy");
var React = require("./react");
var assign = React.__spread;
var shallowEqual = require('./shallowEqual');

/**
* @function createContainer
Expand Down Expand Up @@ -61,10 +63,10 @@ module.exports = function (Component, options) {
});

if (!promises.length) {
promises.push(Promise.resolve(true));
promises.push(promiseProxy.Promise.resolve(true));
}

return Promise.all(
return promiseProxy.Promise.all(
promises
).then(function (promisedQueries) {
var queryResults = {};
Expand All @@ -88,15 +90,22 @@ module.exports = function (Component, options) {
this.setQueryParams({});
}
else if (this.props.onQuery) {
this.props.onQuery.call(this, Promise.resolve({}));
this.props.onQuery.call(this, promiseProxy.Promise.resolve({}));
}
},
setQueryParams: function (nextParams, optionalQueryNames) {
setQueryParams: function (nextParams, optionalQueryNames, options) {
var _this = this;
options = arguments[2] || {};

var promise = new Promise(function (resolve, reject) {
var promise = new promiseProxy.Promise(function (resolve, reject) {
var props = _this.props || {};
var promise;
var allNextParams = {};
var paramsEquals;

assign(allNextParams, _this.currentParams, nextParams)
paramsEquals = shallowEqual(allNextParams, _this.currentParams)
if (options.checkEquals && paramsEquals && _this.hasQueryResults()) return

assign(_this.currentParams, nextParams);
promise = Container.getAllQueries(_this.currentParams, optionalQueryNames);
Expand Down
10 changes: 10 additions & 0 deletions src/lib/promiseProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @copyright © 2015, Rick Wong. All rights reserved.
*/
"use strict";

module.exports = {
Promise: global.Promise || function () {
throw new Error("Missing ES6 Promise implementation");
}
};
11 changes: 7 additions & 4 deletions src/lib/react-transmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"use strict";

module.exports = {
createContainer: require("./createContainer"),
render: require("./render"),
renderToString: require("./renderToString"),
injectIntoMarkup: require("./injectIntoMarkup")
createContainer: require("./createContainer"),
render: require("./render"),
renderToString: require("./renderToString"),
injectIntoMarkup: require("./injectIntoMarkup"),
setPromiseConstructor: function (PromiseConstructor) {
require("./promiseProxy").Promise = PromiseConstructor;
}
};
4 changes: 4 additions & 0 deletions src/lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ var assign = React.__spread;
module.exports = function (Component, props, targetDOMNode, callback) {
var myProps = assign({}, props, window.__reactTransmitPacket || {});

if (window.__reactTransmitPacket) {
delete window.__reactTransmitPacket;
}

React.render(React.createElement(Component, myProps), targetDOMNode, callback);
};
9 changes: 5 additions & 4 deletions src/lib/renderToString.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
*/
"use strict";

var React = require("./react");
var assign = React.__spread;
var promiseProxy = require("./promiseProxy");
var React = require("./react");
var assign = React.__spread;

/**
* @function renderToString
*/
module.exports = function (Component, props) {
props = props || {};

return new Promise(function (resolve, reject) {
return new promiseProxy.Promise(function (resolve, reject) {
var onQuery = function (promise) {
promise.then(function (queryResults) {
var myProps = assign({}, props, queryResults);
var reactString = React.renderToString(React.createElement(Component, myProps));

resolve({
reactString: reactString,
reactData: queryResults
reactData: queryResults
});
}).catch(function (error) {
reject(error);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/shallowEqual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

module.exports = require('react/lib/shallowEqual');