Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ApiRequestMixin = function(url, success, error) {
  2.     return {
  3.         apiRequest: {
  4.             ids: [],
  5.             success: success,
  6.             error: error
  7.         },
  8.        
  9.         componentDidMount: function() {
  10.             var requestId = api.request(url, {
  11.                 success: this.apiRequest.success.bind(this),
  12.                 error: this.apiRequest.error.bind(this)
  13.             });
  14.            
  15.             this.apiRequest.ids.push(requestId);
  16.         },
  17.        
  18.         componentWillUnmount: function() {
  19.             api.cancelRequests(this.apiRequest.ids);
  20.         },
  21.     }
  22. }
  23.  
  24. React.createClass({
  25.     mixins: [
  26.         ApiRequestMixin('http://...',
  27.             function() {
  28.                 success...
  29.             },
  30.             function() {
  31.                 error...
  32.             }
  33.     ],
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement