1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; }; }();
|
8 |
|
9 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
10 |
|
11 | var StyleKeeper = function () {
|
12 | function StyleKeeper(userAgent) {
|
13 | _classCallCheck(this, StyleKeeper);
|
14 |
|
15 | this._userAgent = userAgent;
|
16 | this._listeners = [];
|
17 | this._cssSet = {};
|
18 | }
|
19 |
|
20 | _createClass(StyleKeeper, [{
|
21 | key: 'subscribe',
|
22 | value: function subscribe(listener) {
|
23 | var _this = this;
|
24 |
|
25 | if (this._listeners.indexOf(listener) === -1) {
|
26 | this._listeners.push(listener);
|
27 | }
|
28 |
|
29 | return {
|
30 |
|
31 | remove: function remove() {
|
32 | var listenerIndex = _this._listeners.indexOf(listener);
|
33 | if (listenerIndex > -1) {
|
34 | _this._listeners.splice(listenerIndex, 1);
|
35 | }
|
36 | }
|
37 | };
|
38 | }
|
39 | }, {
|
40 | key: 'addCSS',
|
41 | value: function addCSS(css) {
|
42 | var _this2 = this;
|
43 |
|
44 | if (!this._cssSet[css]) {
|
45 | this._cssSet[css] = true;
|
46 | this._emitChange();
|
47 | }
|
48 |
|
49 | return {
|
50 |
|
51 | remove: function remove() {
|
52 | delete _this2._cssSet[css];
|
53 | _this2._emitChange();
|
54 | }
|
55 | };
|
56 | }
|
57 | }, {
|
58 | key: 'getCSS',
|
59 | value: function getCSS() {
|
60 | return Object.keys(this._cssSet).join('\n');
|
61 | }
|
62 | }, {
|
63 | key: '_emitChange',
|
64 | value: function _emitChange() {
|
65 | this._listeners.forEach(function (listener) {
|
66 | return listener();
|
67 | });
|
68 | }
|
69 | }]);
|
70 |
|
71 | return StyleKeeper;
|
72 | }();
|
73 |
|
74 | exports.default = StyleKeeper; |
\ | No newline at end of file |