react-resolver
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -9,2 +9,7 @@ # React Resolver Changelog | ||
### v1.1.0 - (2015-04-13) | ||
- [Contexts](https://github.com/ericclemmons/react-resolver/pull/21) | ||
### v1.0.0 - (2015-04-13) | ||
@@ -11,0 +16,0 @@ |
@@ -145,8 +145,8 @@ "use strict"; | ||
var valueOf = container.props.resolve[prop]; | ||
var value = container.props.hasOwnProperty(prop) ? container.props[prop] : valueOf(container.props); | ||
var value = container.props.hasOwnProperty(prop) ? container.props[prop] : valueOf(container.props.props, container.props.context); | ||
return Promise.resolve(value).then(function (value) { | ||
state.values[prop] = value; | ||
return Promise.resolve(value).then(function (resolved) { | ||
state.values[prop] = resolved; | ||
return value; | ||
return resolved; | ||
}); | ||
@@ -185,4 +185,6 @@ }); | ||
return _React2["default"].createElement(_Container2["default"], _extends({ | ||
component: Component | ||
}, props, this.props)); | ||
component: Component, | ||
context: this.context, | ||
props: this.props | ||
}, props)); | ||
} | ||
@@ -194,2 +196,4 @@ }]); | ||
ComponentContainer.childContextTypes = props.childContextTypes; | ||
ComponentContainer.contextTypes = props.contextTypes; | ||
ComponentContainer.displayName = "" + Component.displayName + "Container"; | ||
@@ -196,0 +200,0 @@ |
{ | ||
"name": "react-resolver", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Isomorphic library to lazy-load data for React components", | ||
@@ -23,3 +23,3 @@ "main": "dist/index.js", | ||
"build": "babel --out-dir dist/ src/", | ||
"lint": "eslint src", | ||
"lint": "eslint src test", | ||
"prepublish": "npm run build", | ||
@@ -26,0 +26,0 @@ "test": "npm run build && mocha" |
@@ -90,3 +90,3 @@ # React Resolver  | ||
resolve: { | ||
users: function(props) { | ||
users: function(props, context) { | ||
return fetch(`/api/users?limit=${props.limit}`); | ||
@@ -99,3 +99,24 @@ } | ||
If you use [React Router][router] (or anything else) that uses | ||
`context`, you can get access to these values via: | ||
```javascript | ||
Resolver.createContainer(Users, { | ||
contextTypes: { | ||
router: React.PropTypes.func.isRequired | ||
}, | ||
resolve: { | ||
user: function(props, context) { | ||
const { login } = context.router.getCurrentParams(); | ||
return fetch(`/api/users/${login}`); | ||
} | ||
} | ||
}); | ||
``` | ||
_For a working example of this, check out [User.js](https://github.com/ericclemmons/react-resolver/blob/master/examples/stargazers/handlers/User.js) in the [demo][demo]._ | ||
### Client | ||
@@ -164,2 +185,3 @@ | ||
[license]: https://github.com/ericclemmons/react-resolver/blob/master/LICENSE | ||
[router]: https://github.com/rackt/react-router/ | ||
[twitter]: https://twitter.com/ericclemmons/ |
@@ -110,8 +110,11 @@ import React from "react"; | ||
const valueOf = container.props.resolve[prop]; | ||
const value = container.props.hasOwnProperty(prop) ? container.props[prop]: valueOf(container.props); | ||
const value = container.props.hasOwnProperty(prop) | ||
? container.props[prop] | ||
: valueOf(container.props.props, container.props.context) | ||
; | ||
return Promise.resolve(value).then((value) => { | ||
state.values[prop] = value; | ||
return Promise.resolve(value).then((resolved) => { | ||
state.values[prop] = resolved; | ||
return value; | ||
return resolved; | ||
}); | ||
@@ -136,4 +139,5 @@ }); | ||
component={Component} | ||
context={this.context} | ||
props={this.props} | ||
{...props} | ||
{...this.props} | ||
/> | ||
@@ -144,2 +148,4 @@ ); | ||
ComponentContainer.childContextTypes = props.childContextTypes; | ||
ComponentContainer.contextTypes = props.contextTypes; | ||
ComponentContainer.displayName = `${Component.displayName}Container`; | ||
@@ -146,0 +152,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
825532
725
185
0