How to use the base/utils.forEach function in base

To help you get started, we’ve selected a few base examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vizabi / vizabi / src / models / hook.js View on Github external
setInterModelListeners() {
    const spaceRefs = this._parent.getSpace(this);

    //check what we want to hook this model to
    utils.forEach(spaceRefs, reference => {
      //hook with the closest prefix to this model
      this._space[reference] = this.getClosestModel(reference);
      //if hooks change, this should load again
      this._space[reference].on("dataConnectedChange", this.handleDataConnectedChange.bind(this));
      // tell the connected model to set a link with me
      this._space[reference].setLinkWith(this);
    });
    this.getClosestModel("locale").on("dataConnectedChange", this.handleDataConnectedChange.bind(this));
  },
github vizabi / vizabi / src / base / component.js View on Github external
translateStrings() {
    const t = this.getTranslationFunction();
    const strings = this.placeholder.querySelectorAll("[data-vzb-translate]");
    if (strings.length === 0) {
      return;
    }
    utils.forEach(strings, str => {
      if (!str || !str.getAttribute) {
        return;
      }
      str.innerHTML = t(str.getAttribute("data-vzb-translate"));
    });
  },
github vizabi / vizabi / src / components / dialogs / find / show.js View on Github external
applyShowChanges() {
    this.model.state.marker.clearSelected();

    const setObj = {};
    utils.forEach(this.previewShow, (showObj, entities) => {
      const $and = [];
      const $andKeys = [];
      utils.forEach(showObj, (entitiesArray, category) => {
        $andKeys.push(category);
        if (entitiesArray.length) {
          $and.push({ [category]: { $in: entitiesArray.slice(0) } });
        }
      });

      utils.forEach(this.model.state[entities].show.$and || [this.model.state[entities].show], show$and => {
        utils.forEach(show$and, (filter, key) => {
          if (!$andKeys.includes(key)) {
            $and.push(utils.deepClone(filter));
          }
        });
      });
github vizabi / vizabi / src / models / marker.js View on Github external
_getFirstDimension(opts) {
    const models = [];
    const _this = this;
    utils.forEach(this.space, name => {
      models.push(_this.getClosestModel(name));
    });

    opts = opts || {};

    let dim = false;
    utils.forEach(models, m => {
      if (opts.exceptType && m.getType() !== opts.exceptType) {
        dim = m.getDimension();
        return false;
      } else if (opts.type && m.getType() === opts.type) {
        dim = m.getDimension();
        return false;
      } else if (!opts.exceptType && !opts.type) {
        dim = m.getDimension();
        return false;
      }
    });
    return dim;
  },
github vizabi / vizabi / src / base / model.js View on Github external
afterPreload() {
    const submodels = this.getSubmodels();
    utils.forEach(submodels, s => {
      s.afterPreload();
    });
  },
github vizabi / vizabi / src / components / timeslider / timeslider.js View on Github external
Promise.all(proms).then(limits => {
      if (_setSelectedLimitsId != _this._setSelectedLimitsId) return;
      const first = limits.shift();
      let min = first.min;
      let max = first.max;
      utils.forEach(limits, limit => {
        if (min - limit.min > 0) min = limit.min;
        if (max - limit.max < 0) max = limit.max;
      });
      _this.model.time
        .set({
          startSelected: d3.max([min, new Date(_this.model.time.start)]),
          endSelected: d3.min([max, new Date(_this.model.time.end)])
        }, force, false  /*make change non-persistent for URL and history*/);
    });
  },
github vizabi / vizabi / src / base / datastorage.js View on Github external
_muteAllQueues(except) {
    utils.forEach(this._collectionPromises, (queries, dataId) => {
      utils.forEach(queries, (promise, whatId) => {
        if (promise.queue.isActive == true && promise.queue.whatId != except) {
          promise.queue.mute();
        }
      });
    });
  }
github vizabi / vizabi / src / models / marker.js View on Github external
hook.getFrames(steps, selected).then(response => {
                utils.forEach(response, (frame, t) => {
                  _this.partialResult[cachePath][t][currentHookState.name] = frame[currentHookState.which];
                });
                res();
              });
            }));
github vizabi / vizabi / src / models / marker.js View on Github external
_this.getFrame(nextFrameTime, nValues => {
          const fraction = (time - prevFrameTime) / (nextFrameTime - prevFrameTime);
          const dataBetweenFrames = {};

          //loop across the hooks
          utils.forEach(pValues, (values, hook) => {
            dataBetweenFrames[hook] = {};

            //loop across the entities
            utils.forEach(values, (val1, key) => {
              const val2 = nValues[hook][key];
              if (utils.isDate(val1)) {
                dataBetweenFrames[hook][key] = time;
              } else if (!utils.isNumber(val1)) {
                //we can be interpolating string values
                dataBetweenFrames[hook][key] = val1;
              } else {
                //interpolation between number and null should rerurn null, not a value in between (#1350)
                dataBetweenFrames[hook][key] = (val1 == null || val2 == null) ? null : val1 + ((val2 - val1) * fraction);
              }
            });
          });
github vizabi / vizabi / src / tools / agepyramid / agepyramid-component.js View on Github external
utils.forEach(timeKeys, time => {
        totals[time] = {};
        utils.forEach(sideKeysNF, side => {
          let ageSum = 0;
          const sideMaxLimits = [];
          utils.forEach(_this.ageKeys, age => {
            let stackSum = 0;
            utils.forEach(_this.stackKeys, stack => {
              if (limits[stack][side] && limits[stack][side][age] && limits[stack][side][age][time]) {
                stackSum += limits[stack][side][age][time].max;
                ageSum += stackSum;
              }
            });
            sideMaxLimits.push(stackSum);
          });
          totals[time][side] = ageSum;
          const maxSideLimit = Math.max(...sideMaxLimits);
          inpercentMaxLimits[side].push(maxSideLimit / ageSum);
          maxLimits[side].push(maxSideLimit);