Skip to content

Instantly share code, notes, and snippets.

@obenland
Last active September 27, 2017 19:19
Show Gist options
  • Save obenland/f9ebc90b91dab71970e6cc265b791415 to your computer and use it in GitHub Desktop.
Save obenland/f9ebc90b91dab71970e6cc265b791415 to your computer and use it in GitHub Desktop.
var fetchGifs = _.debounce( function fetchGifs( search ) {
if ( attributes.fetching ) {
return;
}
props.setAttributes( {
fetching: true,
} );
$.getJSON( 'https://api.giphy.com/v1/gifs/search?api_key=Fswo3IBHt0TViFMN6zYgbYzSEb3sLx7I&limit=10&offset=0&rating=G&lang=en&q=' + encodeURI( search ) )
.success( function fetchSuccess( data ) {
props.setAttributes( {
fetching: false,
matches: data.data,
} );
} )
.fail( function fetchFail() {
props.setAttributes( { fetching: false } );
} );
}, 1000 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment