All files / lib/util UID.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 1/1
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                                        1x 1x 1x               1x 4133x   2x 2x 2x 4133x   4131x 4131x 4133x 1x  
/*
 * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
 * http://paperjs.org/
 *
 * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
 * http://juerglehni.com/ & https://puckey.studio/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * All rights reserved.
 */
 
// TODO: remove eslint-disable comment and deal with errors over time
/* eslint-disable */
 
/**
 * @name UID
 * @namespace
 * @private
 */
export const UID = {
  _id: 1,
  _pools: {},
 
  /**
   * Returns the next unique id.
   * @method get
   * @return {Number} the next unique id
   * @static
   **/
  get: function (name) {
    if (name) {
      // Use one UID pool per given constructor
      var pool = this._pools[name];
      if (!pool) pool = this._pools[name] = { _id: 1 };
      return pool._id++;
    } else {
      // Use the global UID pool:
      return this._id++;
    }
  },
};