1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore'], function (_) {
- /**
- * Get the difference between 2 array of obejcts based on the search key.
- * @param aObject1 array of object 1
- * @param aObject2 array of object 2
- * @param searchkey used to identify entries
- * @return an array of object from aObject1 but doesn't present the same value in aObject2.
- * e.g.
- * aObject1 = [
- * {'displayValue': 'a', 'useValue': 'a'},
- * {'displayValue': 'b', 'useValue': 'b'},
- * {'displayValue': 'c', 'useValue': 'c'},
- * {'displayValue': 'd', 'useValue': 'd'}
- * ];
- * aObject2 = [
- * {'displayValue': 'a', 'useValue': 'a'},
- * {'displayValue': 'b', 'useValue': 'b'},
- * {'displayValue': 'c', 'useValue': 'c'}
- * ]
- *
- * The result will be [{'displayValue': 'd', 'useValue': 'd'}]
- */
- _.objDifference = function (aObject1, aObject2, searchkey) {
- return aObject1.filter(function (current1) {
- return aObject2.filter(function (current2) {
- return current1[searchkey] === current2[searchkey];
- }).length === 0;
- });
- };
- /* implementation of debounce that calls the provided function a maximum of once per 'time' ms
- * 'fn' will be called immediately and then after 'time' of not getting called.
- *
- * if wrappedFn is called once, fn is called once immediately.
- * if wrappedFn is called more once in rapid succession (each call within 'time' ms of the last, fn is called twice:
- * once immediately.
- * a second time 'time' ms after the last invocation.
- *
- * this differs from the standard underscore version in the fact that fn is called first.
- */
- _.doubleDebounce = function (fn, time) {
- var timeout = null;
- var lastCall = 0;
- var later = function later(args) {
- timeout = null;
- lastCall = Date.now();
- fn(args);
- };
- var wrappedFn = function wrappedFn(args) {
- // more than 'time' since last call and nothing scheduled, so just call fn
- if (Date.now() - lastCall > time && !timeout) {
- lastCall = Date.now();
- fn(args);
- } else {
- // less than 'time' since last call or 'later' is already scheduled.
- // push the callback to the future.
- clearTimeout(timeout);
- timeout = setTimeout(later, time, args);
- }
- };
- wrappedFn.cancel = function () {
- return clearTimeout(timeout);
- };
- return wrappedFn;
- };
- });
- //# sourceMappingURL=UnderscoreExt.js.map
|