Comments (5)
Why not do:
@resolve({
propA, function() { ... },
propB, function() { ... }
})
That's what's happening internally:
Line 10 in b5acd1c
💩 on me for not having this in the README or docs.
from react-resolver.
Misread it. You're right, there's not a way to return an object for multiple props from a single call.
I think this makes sense, especially for something like:
@resolve(function(props) {
return lookup(props.something).then(result => {
return {
user: result.data,user,
place: result.data.place,
});
})
This makes sense from a signature standpoint because the props aren't defined until the promise resolves. However, this is a problem because it means the resolver doesn't know if the props are pre-existing or not.
TBH, reducing duplicate in-flight requests should be handled via your request mechanism. Annoyingly, there are few implementations I found of this:
https://github.com/matthiasak/universal-utils/blob/master/src/fetch.js
Or my own:
export default class HttpActions extends Actions {
constructor(...args) {
super(...args);
this.requests = {};
}
get(url, params) {
const existing = this.cached(arguments);
if (existing) {
return existing;
}
const request = this.request("get", url, params);
return this.cache(request, arguments);
}
cache(request, signature) {
const key = JSON.stringify(Array.prototype.slice.call(signature));
this.requests[key] = request;
return request;
}
cached(signature) {
const key = JSON.stringify(Array.prototype.slice.call(signature));
return this.requests[key];
}
...
from react-resolver.
Another backwards-compatible API would be something like:
@resolve(["propA", "propB"], function(props) {
return promise(something).then((result) => [result.a, result.b]);
})
Because they're positional params, it's basically describing the required response signature should any of the props not exist.
Again, I feel this warrants mentioning...In my own side-projects using Redux (meh), co-locating data requirements via @resolve
to their immediate components makes sense & works, but it's difficult to solve the duplicate request issue with Redux & in-flight requests.
If I figure this out, it'll probably solve it for several people.
from react-resolver.
This all makes sense, @ericclemmons.
re: Caching
It is definitely a solution, but it feels a little brittle. Mostly because it adds cache invalidation to the mix.
re: backwards compatible API
I hacked something together that basically just allows you to use a hash as opposed to an array. But I see the value of taking your approach to it.
I'd love to help out and try to come up with an implementation for this last suggestion 😄
My current solution basically hijacks resolve.js
and checks if a complex has been returned from Resolver
and then just deconstructs it.
Would resolve.js
be the place to make this changes? Or does this sound more like something Resolver
should handle?
from react-resolver.
Why not do:
@resolve({ propA, function() { ... }, propB, function() { ... } })
small correction :
instead of ,
@resolve({
propA: function() { ... },
propB: function() { ... }
})
from react-resolver.
Related Issues (20)
- React.renderToStaticMarkup -> ReactDOMServer.renderToStaticMarkup HOT 2
- Can I use this without server rendering? HOT 3
- Add ability to cache resolved props HOT 9
- Using HOC breaks HMR
- Minimum universal react API HOT 1
- test
- Support variable? HOT 3
- Unhandled rejections server side HOT 1
- @context steals data from this.context HOT 6
- Allow factory to decide which props to re-use? HOT 5
- Documentation links are broken HOT 4
- Using same component on different routes HOT 3
- Using @client and @resolve on the same class causes @resolve to be called twice HOT 1
- Some way of manipulating data before passing it to component HOT 2
- Breakage with React 16: PropTypes no longer exported by React HOT 1
- "[email protected]" has incorrect peer dependency "react@^0.14.6 || ^15.0.0-0" HOT 5
- Need hydrate static method in the Resolver class for server side rendering HOT 2
- Fix compatibility with Babel 6
- Initial Data from Django using React Resolver HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-resolver.