No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

87 líneas
2.6 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6. var _warning = require('warning');
  7. var _warning2 = _interopRequireDefault(_warning);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  9. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10. /**
  11. * SheetsManager is like a WeakMap which is designed to count StyleSheet
  12. * instances and attach/detach automatically.
  13. */
  14. var SheetsManager = function () {
  15. function SheetsManager() {
  16. _classCallCheck(this, SheetsManager);
  17. this.sheets = [];
  18. this.refs = [];
  19. this.keys = [];
  20. }
  21. _createClass(SheetsManager, [{
  22. key: 'get',
  23. value: function get(key) {
  24. var index = this.keys.indexOf(key);
  25. return this.sheets[index];
  26. }
  27. }, {
  28. key: 'add',
  29. value: function add(key, sheet) {
  30. var sheets = this.sheets,
  31. refs = this.refs,
  32. keys = this.keys;
  33. var index = sheets.indexOf(sheet);
  34. if (index !== -1) return index;
  35. sheets.push(sheet);
  36. refs.push(0);
  37. keys.push(key);
  38. return sheets.length - 1;
  39. }
  40. }, {
  41. key: 'manage',
  42. value: function manage(key) {
  43. var index = this.keys.indexOf(key);
  44. var sheet = this.sheets[index];
  45. if (this.refs[index] === 0) sheet.attach();
  46. this.refs[index]++;
  47. if (!this.keys[index]) this.keys.splice(index, 0, key);
  48. return sheet;
  49. }
  50. }, {
  51. key: 'unmanage',
  52. value: function unmanage(key) {
  53. var index = this.keys.indexOf(key);
  54. if (index === -1) {
  55. // eslint-ignore-next-line no-console
  56. (0, _warning2['default'])(false, "SheetsManager: can't find sheet to unmanage");
  57. return;
  58. }
  59. if (this.refs[index] > 0) {
  60. this.refs[index]--;
  61. if (this.refs[index] === 0) this.sheets[index].detach();
  62. }
  63. }
  64. }, {
  65. key: 'size',
  66. get: function get() {
  67. return this.keys.length;
  68. }
  69. }]);
  70. return SheetsManager;
  71. }();
  72. exports['default'] = SheetsManager;