ep

ember-prefetch

An Ember.js addon that enables parallel data requests.

Showing:

Popularity

Downloads/wk

14

GitHub Stars

61

Maintenance

Last Commit

2yrs ago

Contributors

18

Package

Dependencies

2

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Ember Prefetch Build Status npm version

This addon provides an implementation of the prefetch hook from Ember RFC #97.

  • yarn add ember-prefetch
  • alternate: npm install [--save|--save-dev] ember-prefetch

Usage

Route#prefetch

The prefetch hook is used largely the same as the model hook. It takes the same parameters (params and transition) and is not called if an object has been passed to the transition. However, the prefetch hook of all routes involved in a transition are invoked at the beginning of that transition. This enables child routes to settle faster because their network requests are made in parallel with their parents'.

App.PostRoute = Ember.Route.extend({
  prefetch(params) {
    return Ember.$.get(`/api/posts/${params.id}`);
  },
});

App.PostCommentsRoute = Ember.Route.extend({
  prefetch(params, transition) {
    return Ember.$.get(`/api/posts/${this.paramsFor('post').id}/comments`);
  },
});

The default functionality of the model hook will pick up whatever is returned from the prefetch hook. A route that defines a prefetch hook is not required to define a model hook.

Route#prefetched

The prefetched method provides access to routes' prefetched data. prefetched always returns a promise, but ES7 async function syntax simplifies working with promises.

App.PostCommentsRoute = Ember.Route.extend({
  async prefetch(params, transition) {
    return {
      // getting a parent route's data; the syntax is akin to `paramsFor`
      OP: (await this.prefetched('post')).author,
      comments: await Ember.$.get(`/api/posts/${this.paramsFor('post').id}/comments`),
    };
  },
});

Contributing

Make sure you have Yarn installed. (How do I install Yarn?)

  • git clone this repository
  • yarn install

Running Tests

  • ember test
  • ember test --server

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial