0.6.1 • Published 9 years ago
ember-fetchjax v0.6.1
Ember-fetchjax
Ember Addon to use Fetch or AJAX.
The default behavior is to use Fetch when available, otherwise to use AJAX.
- Provides a set of utils to use in an Ember app, however the utils do
not require Ember, they are just JavaScript classes
- See the addon/utils directory
- No polyfill for
window.fetchorwindow.Promiserequired- If you want to use a polyfill see the bower projects
es6-promiseandfetch
- If you want to use a polyfill see the bower projects
- Setup a
fetchjax.fetchmethod to use AJAX or FetchFetchOrAjaxconstructor requires dependencies, e.g.jQuery.ajax- Instance defaults to native Fetch and Promise, unless you pass in
Ember.RSVP.Promise, or anotherfetchmethod
- See the
dummyapp and acceptance tests for example use
Usage
Example route that defaults to use Fetch, but falls back to AJAX:
import Ember from 'ember';
import FetchOrAjax from 'ember-fetchjax/utils/fetchjax';
const fetchjax = new FetchOrAjax({ajax: Ember.$.ajax});
export default Ember.Route.extend({
model() {
return fetchjax.fetch('/api/v1/posts', {method: 'GET'});
}
});Example route the forces the use of XHR:
import Ember from 'ember';
import FetchOrAjax from 'ember-fetchjax/utils/fetchjax';
const fetchjax = new FetchOrAjax({useAjax: true, ajax: Ember.$.ajax});
export default Ember.Route.extend({
model() {
return fetchjax.fetch('/api/v1/posts', {method: 'GET'});
}
});Installation
Install addon…
ember install ember-fetchjax
Install for local development…
git clone <repository-url>this repositorycd ember-fetchjaxnpm installbower install
Running
ember serve --proxy http://api.pixelhandler.com- Try with Fetch or AJAX http://localhost:4200/fetch.
- AJAX only http://localhost:4200/ajax.
Running Tests
npm test(Runsember try:eachto test your addon against multiple Ember versions)ember testember test --server
Building
ember build
For more information on using ember-cli, visit http://ember-cli.com/.