0.1.2 • Published 9 years ago
ember-jsonp v0.1.2
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
paramNamecallback parameter namecallbackNamecallback nametimeouttimeout (ms)uriorurlrequest URLcontextcontext for success/error handlerssuccesssuccess handlererrorerror handlerpatterncallbackName pattern,
allows URL like http://site.com/jsonp?callback={{callbackName}}
where {{callbackName}} -> pattern for replacing by service
Installation
git clonethis repositorynpm installbower install
Running
ember serve- Visit your app at http://localhost:4200.
Running Tests
npm test(Runsember try:testallto 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/.