backboneUtils.js

From disqus.com, 7 Months ago, written in JavaScript, viewed 3 times. This paste is a reply to confirmBlacklistUser.js from disqus.com - view diff
URL https://pastebin.freepbx.org/view/0291fa72 Embed
Download Paste or View Raw
  1. define('home/utils/backboneUtils',[
  2.     'jquery',
  3. ], function (
  4.     $
  5. ) {
  6.     'use strict';
  7.  
  8.     return {
  9.         memoizedFetch: function () {
  10.             if (this.fetchPromise)
  11.                 return this.fetchPromise;
  12.  
  13.             var self = this;
  14.             this.fetchPromise = this.constructor.__super__.fetch.apply(this, arguments).then(function () {
  15.                 self.fetchPromise = null;
  16.                 self.fetched = true;
  17.                 return arguments;
  18.             }, function (err) {
  19.                 self.fetchPromise = null;
  20.                 // Leave self.fetched as its current value, true if at least 1 successful fetch, undefined otherwise
  21.                 return err;
  22.             });
  23.  
  24.             return this.fetchPromise;
  25.         },
  26.  
  27.         getPromiseFor: function (model, attributeName) {
  28.             var attributeValue = $.Deferred();
  29.  
  30.             // Model.has() returns true if the value is non-null/undefined. Because "", false, {}, and 0 are
  31.             // valid values for many attributes, we should resolve the attribute here because they will
  32.             // likely never change.
  33.             if (model.has(attributeName)) {
  34.                 attributeValue.resolve(model.get(attributeName));
  35.             } else {
  36.                 model.once('change:' + attributeName, function (_model, value) {
  37.                     attributeValue.resolve(value);
  38.                 });
  39.             }
  40.  
  41.             return attributeValue.promise();
  42.         },
  43.     };
  44. });
  45.  
  46. // https://c.disquscdn.com/next/82c6de3/home/js/utils/backboneUtils.js

Replies to backboneUtils.js rss

Title Name Language When
UserProfile.js disqus.com javascript 7 Months ago.

Reply to "backboneUtils.js"

Here you can reply to the paste above