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