0.1.2 • Published 7 years ago

ember-jsonp v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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 name
  • callbackName callback name
  • timeout timeout (ms)
  • uri or url request URL
  • context context for success/error handlers
  • success success handler
  • error error handler
  • pattern callbackName pattern,

allows URL like http://site.com/jsonp?callback={{callbackName}}

where {{callbackName}} -> pattern for replacing by service

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • npm test (Runs ember 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/.

0.1.2

7 years ago

0.1.1

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.1

7 years ago