BVB Source Codes

dat.gui Show common.js Source code

Return Download dat.gui: download common.js Source code - Download dat.gui Source code - Type:.js
  1. /**
  2.  * dat-gui JavaScript Controller Library
  3.  * http://code.google.com/p/dat-gui
  4.  *
  5.  * Copyright 2011 Data Arts Team, Google Creative Lab
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  * http://www.apache.org/licenses/LICENSE-2.0
  12.  */
  13.  
  14. const ARR_EACH = Array.prototype.forEach;
  15. const ARR_SLICE = Array.prototype.slice;
  16.  
  17. /**
  18.  * Band-aid methods for things that should be a lot easier in JavaScript.
  19.  * Implementation and structure inspired by underscore.js
  20.  * http://documentcloud.github.com/underscore/
  21.  */
  22.  
  23. const Common = {
  24.   BREAK: {},
  25.  
  26.   extend: function(target) {
  27.     this.each(ARR_SLICE.call(arguments, 1), function(obj) {
  28.       const keys = this.isObject(obj) ? Object.keys(obj) : [];
  29.       keys.forEach(function(key) {
  30.         if (!this.isUndefined(obj[key])) {
  31.           target[key] = obj[key];
  32.         }
  33.       }.bind(this));
  34.     }, this);
  35.  
  36.     return target;
  37.   },
  38.  
  39.   defaults: function(target) {
  40.     this.each(ARR_SLICE.call(arguments, 1), function(obj) {
  41.       const keys = this.isObject(obj) ? Object.keys(obj) : [];
  42.       keys.forEach(function(key) {
  43.         if (this.isUndefined(target[key])) {
  44.           target[key] = obj[key];
  45.         }
  46.       }.bind(this));
  47.     }, this);
  48.  
  49.     return target;
  50.   },
  51.  
  52.   compose: function() {
  53.     const toCall = ARR_SLICE.call(arguments);
  54.     return function() {
  55.       let args = ARR_SLICE.call(arguments);
  56.       for (let i = toCall.length - 1; i >= 0; i--) {
  57.         args = [toCall[i].apply(this, args)];
  58.       }
  59.       return args[0];
  60.     };
  61.   },
  62.  
  63.   each: function(obj, itr, scope) {
  64.     if (!obj) {
  65.       return;
  66.     }
  67.  
  68.     if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) {
  69.       obj.forEach(itr, scope);
  70.     } else if (obj.length === obj.length + 0) { // Is number but not NaN
  71.       let key;
  72.       let l;
  73.       for (key = 0, l = obj.length; key < l; key++) {
  74.         if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) {
  75.           return;
  76.         }
  77.       }
  78.     } else {
  79.       for (const key in obj) {
  80.         if (itr.call(scope, obj[key], key) === this.BREAK) {
  81.           return;
  82.         }
  83.       }
  84.     }
  85.   },
  86.  
  87.   defer: function(fnc) {
  88.     setTimeout(fnc, 0);
  89.   },
  90.  
  91.   // call the function immediately, but wait until threshold passes to allow it to be called again
  92.   debounce: function(func, threshold) {
  93.     let timeout;
  94.  
  95.     return function() {
  96.       const obj = this;
  97.       const args = arguments;
  98.       function delayed() {
  99.         timeout = null;
  100.       }
  101.  
  102.       const allowCall = !timeout;
  103.  
  104.       clearTimeout(timeout);
  105.       timeout = setTimeout(delayed, threshold);
  106.  
  107.       if (allowCall) {
  108.         func.apply(obj, args);
  109.       }
  110.     };
  111.   },
  112.  
  113.   toArray: function(obj) {
  114.     if (obj.toArray) return obj.toArray();
  115.     return ARR_SLICE.call(obj);
  116.   },
  117.  
  118.   isUndefined: function(obj) {
  119.     return obj === undefined;
  120.   },
  121.  
  122.   isNull: function(obj) {
  123.     return obj === null;
  124.   },
  125.  
  126.   isNaN: function(obj) {
  127.     return isNaN(obj);
  128.   },
  129.  
  130.   isArray: Array.isArray || function(obj) {
  131.     return obj.constructor === Array;
  132.   },
  133.  
  134.   isObject: function(obj) {
  135.     return obj === Object(obj);
  136.   },
  137.  
  138.   isNumber: function(obj) {
  139.     return obj === obj + 0;
  140.   },
  141.  
  142.   isString: function(obj) {
  143.     return obj === obj + '';
  144.   },
  145.  
  146.   isBoolean: function(obj) {
  147.     return obj === false || obj === true;
  148.   },
  149.  
  150.   isFunction: function(obj) {
  151.     return Object.prototype.toString.call(obj) === '[object Function]';
  152.   }
  153.  
  154. };
  155.  
  156. export default Common;
  157.  
downloadcommon.js Source code - Download dat.gui Source code
Related Source Codes/Software:
tmate - Instant Terminal Sharing ht... 2017-04-16
WNXHuntForCity - City find By Objective - C 2017-04-16
st2 - StackStorm (aka IFTTT for Ops) is event-driven aut... 2017-04-16
css-in-js - React: CSS in JS techniques comparison. 2017-04-16
android-viewflow - A horizontal view scroller library for Android 2017-04-16
capybara-webkit - A Capybara driver for headless WebKit to test Java... 2017-04-16
fullstackpython.com - Full Stack Python source with Pelican, Bootstrap a... 2017-04-16
naxsi - NAXSI is an open-source, high performance, low rul... 2017-04-16
ToGL - Direct3D to OpenGL abstraction layer 2017-04-16
LiveScript - LiveScript is a language which compiles to JavaScr... 2017-04-16
MaterialSearchView - Express it in the library to implement SearchView ... 2017-04-23
ptpython - A better Python REPL 2017-04-23
Laravel-4-Bootstrap-Starter-Site - Laravel 4 Starter Site is a basic blog application... 2017-04-23
official-images - Primary source of truth for the Docker "Official I... 2017-04-23
awesome-chrome-devtools - Awesome tooling and resources in the Chrome DevToo... 2017-04-23
EventStore - The open-source, functional database with Complex ... 2017-04-23
screencat - 2017-04-23
viz.js - A hack to put Graphviz on the web. ... 2017-04-23
JKeyboardPanelSwitch - For resolve the layout conflict when keybord & amp... 2017-04-23
mama2 - Mother plan - all firewood high flame 2017-04-23

 Back to top