by _wo6a · 11y ago · 0 comments
First, for the framework-level handling of fetching all data before rendering, where the data needed by each component is defined in each component, just copy how it's done in react-router's async-data example [1], modified to expect a hash of promises as in [2].
The promises return Backbone-Relational models [3]. You can model arbitrary relations using Backbone-Relational, although many-to-many is apparently kind of hacky (but just needs work to be seamless). It supports parsing REST API responses with nested models and collections as related models. A REST API generator like Flask-Restless [4] creates these responses with a single efficient query.
You have the flexibility to either sync all models before rendering, or render any component without all data already being fetched, and have it automatically re-render when loaded.
Components subscribe and unsubscribe to model events at the proper points in the component lifecycle using react-backbone-component.[5] I missed this and wrote my own version [6] before I found it, but mine is cleaner, slightly more featureful, and presents a simpler API.
Anyway, this requires some work to pull together, but I think it presents a viable alternative that:
- uses existing libraries that do one thing well and allows as much departure from each elements of the architecture as you want
- works with react-router, which is the shit
- works with your existing REST API
Relay looks wonderful, but it's possible to build the abstractions that do pretty much the same thing that support existing REST APIs.
[1] https://github.com/rackt/react-router/blob/master/examples/a...
[2] https://github.com/rackt/react-router/wiki/Announcements
[3] http://backbonerelational.org/
[4] https://flask-restless.readthedocs.org/en/latest/
No comments yet.