ember-jsonp
v0.1.2
Published
JSONP data load service
Downloads
3
Maintainers
Readme
ember-jsonp
This README outlines the details of collaborating on this Ember addon.
This is service addon, named jsonp
, providing ember-ajax
-like UX with JSONP data without jQuery
DEMO
https://lifeart.github.io/ember-jsonp/demo/
Usage Example
ember install ember-jsonp
this.get('jsonp').request(URL,context,success,error,options);
<<OR>>
this.get('jsonp').request(URL,options).then(success).catch(error);
<<OR>>
this.get('jsonp').request({url,paramName}).then(success).catch(error);
<<OR>>
this.get('jsonp').request({
url: "http://site.com?method=jsonp&callback={{callbackName}}",
pattern: "{{callbackName}}"
}).then(success).catch(error);
jsonp: service(),
init() {
this.set('searchTag', 'emberconf');
},
items: computed(function () {
return [];
}),
searchTag: '',
getFlickerURI() {
let encodedTag = encodeURIComponent(this.get('searchTag'));
return `//api.flickr.com/services/feeds/photos_public.gne?tags=${encodedTag}&format=json`;
},
searchTagDidChange: on('init', observer('searchTag', function() {
let url = this.getFlickerURI();
this.get('jsonp').request(url,this,(result)=>{
this.set('items',result.items);
},(error)=>{
console.log(error);
},{
paramName: 'jsoncallback'
});
}))
ember-jsonp
generates random JSONP callback, with timeout and success/error handlers;
Options
paramName
callback parameter namecallbackName
callback nametimeout
timeout (ms)uri
orurl
request URLcontext
context for success/error handlerssuccess
success handlererror
error handlerpattern
callbackName pattern,
allows URL like http://site.com/jsonp?callback={{callbackName}}
where {{callbackName}}
-> pattern for replacing by service
Installation
git clone
this repositorynpm install
bower install
Running
ember serve
- Visit your app at http://localhost:4200.
Running Tests
npm test
(Runsember try:testall
to test your addon against multiple Ember versions)ember test
ember test --server
Building
ember build
For more information on using ember-cli, visit http://ember-cli.com/.