@hellotext/hellotext 1.6.7 → 1.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "1.6.7",
3
+ "version": "1.6.8",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.js",
package/lib/api.js DELETED
@@ -1,73 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
- exports.default = void 0
7
- var _sessions = _interopRequireDefault(require('./api/sessions'))
8
- var _businesses = _interopRequireDefault(require('./api/businesses'))
9
- var _events = _interopRequireDefault(require('./api/events'))
10
- function _interopRequireDefault(obj) {
11
- return obj && obj.__esModule ? obj : { default: obj }
12
- }
13
- function _classCallCheck(instance, Constructor) {
14
- if (!(instance instanceof Constructor)) {
15
- throw new TypeError('Cannot call a class as a function')
16
- }
17
- }
18
- function _defineProperties(target, props) {
19
- for (var i = 0; i < props.length; i++) {
20
- var descriptor = props[i]
21
- descriptor.enumerable = descriptor.enumerable || false
22
- descriptor.configurable = true
23
- if ('value' in descriptor) descriptor.writable = true
24
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor)
25
- }
26
- }
27
- function _createClass(Constructor, protoProps, staticProps) {
28
- if (protoProps) _defineProperties(Constructor.prototype, protoProps)
29
- if (staticProps) _defineProperties(Constructor, staticProps)
30
- Object.defineProperty(Constructor, 'prototype', { writable: false })
31
- return Constructor
32
- }
33
- function _toPropertyKey(arg) {
34
- var key = _toPrimitive(arg, 'string')
35
- return typeof key === 'symbol' ? key : String(key)
36
- }
37
- function _toPrimitive(input, hint) {
38
- if (typeof input !== 'object' || input === null) return input
39
- var prim = input[Symbol.toPrimitive]
40
- if (prim !== undefined) {
41
- var res = prim.call(input, hint || 'default')
42
- if (typeof res !== 'object') return res
43
- throw new TypeError('@@toPrimitive must return a primitive value.')
44
- }
45
- return (hint === 'string' ? String : Number)(input)
46
- }
47
- var API = /*#__PURE__*/ (function () {
48
- function API() {
49
- _classCallCheck(this, API)
50
- }
51
- _createClass(API, null, [
52
- {
53
- key: 'sessions',
54
- value: function sessions(businessId) {
55
- return new _sessions.default(businessId)
56
- },
57
- },
58
- {
59
- key: 'businesses',
60
- get: function get() {
61
- return _businesses.default
62
- },
63
- },
64
- {
65
- key: 'events',
66
- get: function get() {
67
- return _events.default
68
- },
69
- },
70
- ])
71
- return API
72
- })()
73
- exports.default = API
@@ -1,97 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
- exports.InputBuilder = void 0
7
- var _hellotext = _interopRequireDefault(require('../hellotext'))
8
- function _interopRequireDefault(obj) {
9
- return obj && obj.__esModule ? obj : { default: obj }
10
- }
11
- function _classCallCheck(instance, Constructor) {
12
- if (!(instance instanceof Constructor)) {
13
- throw new TypeError('Cannot call a class as a function')
14
- }
15
- }
16
- function _defineProperties(target, props) {
17
- for (var i = 0; i < props.length; i++) {
18
- var descriptor = props[i]
19
- descriptor.enumerable = descriptor.enumerable || false
20
- descriptor.configurable = true
21
- if ('value' in descriptor) descriptor.writable = true
22
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor)
23
- }
24
- }
25
- function _createClass(Constructor, protoProps, staticProps) {
26
- if (protoProps) _defineProperties(Constructor.prototype, protoProps)
27
- if (staticProps) _defineProperties(Constructor, staticProps)
28
- Object.defineProperty(Constructor, 'prototype', { writable: false })
29
- return Constructor
30
- }
31
- function _toPropertyKey(arg) {
32
- var key = _toPrimitive(arg, 'string')
33
- return typeof key === 'symbol' ? key : String(key)
34
- }
35
- function _toPrimitive(input, hint) {
36
- if (typeof input !== 'object' || input === null) return input
37
- var prim = input[Symbol.toPrimitive]
38
- if (prim !== undefined) {
39
- var res = prim.call(input, hint || 'default')
40
- if (typeof res !== 'object') return res
41
- throw new TypeError('@@toPrimitive must return a primitive value.')
42
- }
43
- return (hint === 'string' ? String : Number)(input)
44
- }
45
- var InputBuilder = /*#__PURE__*/ (function () {
46
- function InputBuilder() {
47
- _classCallCheck(this, InputBuilder)
48
- }
49
- _createClass(InputBuilder, null, [
50
- {
51
- key: 'build',
52
- value: function build(data) {
53
- var article = document.createElement('article')
54
- var label = document.createElement('label')
55
- var input = document.createElement('input')
56
- label.innerText = data.label
57
- input.type = data.type
58
- input.required = data.required
59
- input.placeholder = data.placeholder
60
- if (['first_name', 'last_name'].includes(data.kind)) {
61
- input.type = 'text'
62
- input.id = input.name = data.kind
63
- label.setAttribute('for', data.kind)
64
- } else {
65
- input.type = data.type
66
- if (data.type === 'email') {
67
- input.id = input.name = 'email'
68
- label.setAttribute('for', 'email')
69
- } else if (input.type === 'tel') {
70
- input.id = input.name = 'phone'
71
- label.setAttribute('for', 'phone')
72
- input.value = '+'.concat(_hellotext.default.business.country.prefix)
73
- input.setAttribute(
74
- 'data-default-value',
75
- '+'.concat(_hellotext.default.business.country.prefix),
76
- )
77
- } else {
78
- input.name = input.id = 'property_by_id['.concat(data.property, ']')
79
- label.setAttribute('for', 'property_by_id['.concat(data.property, ']'))
80
- }
81
- }
82
- var main = document.createElement('main')
83
- main.appendChild(label)
84
- main.appendChild(input)
85
- article.appendChild(main)
86
- article.setAttribute('data-hellotext--form-target', 'inputContainer')
87
- input.setAttribute('data-hellotext--form-target', 'input')
88
- var errorContainer = document.createElement('div')
89
- errorContainer.setAttribute('data-error-container', '')
90
- article.appendChild(errorContainer)
91
- return article
92
- },
93
- },
94
- ])
95
- return InputBuilder
96
- })()
97
- exports.InputBuilder = InputBuilder
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.InvalidEvent = void 0;
7
- 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, _toPropertyKey(descriptor.key), descriptor); } }
8
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
13
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
15
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
16
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
17
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
18
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
20
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
- var InvalidEvent = /*#__PURE__*/function (_Error) {
23
- _inherits(InvalidEvent, _Error);
24
- var _super = _createSuper(InvalidEvent);
25
- function InvalidEvent(event) {
26
- var _this;
27
- _classCallCheck(this, InvalidEvent);
28
- _this = _super.call(this, "".concat(event, " is not valid. Please provide a valid event name"));
29
- _this.name = 'InvalidEvent';
30
- return _this;
31
- }
32
- return _createClass(InvalidEvent);
33
- }( /*#__PURE__*/_wrapNativeSuper(Error));
34
- exports.InvalidEvent = InvalidEvent;
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.NotInitializedError = void 0;
7
- 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, _toPropertyKey(descriptor.key), descriptor); } }
8
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
13
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
15
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
16
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
17
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
18
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
20
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
- var NotInitializedError = /*#__PURE__*/function (_Error) {
23
- _inherits(NotInitializedError, _Error);
24
- var _super = _createSuper(NotInitializedError);
25
- function NotInitializedError() {
26
- var _this;
27
- _classCallCheck(this, NotInitializedError);
28
- _this = _super.call(this, 'You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id');
29
- _this.name = 'NotInitializedError';
30
- return _this;
31
- }
32
- return _createClass(NotInitializedError);
33
- }( /*#__PURE__*/_wrapNativeSuper(Error));
34
- exports.NotInitializedError = NotInitializedError;
package/lib/event.js DELETED
@@ -1,162 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
- exports.default = void 0
7
- var _invalidEvent = require('./errors/invalidEvent')
8
- function ownKeys(object, enumerableOnly) {
9
- var keys = Object.keys(object)
10
- if (Object.getOwnPropertySymbols) {
11
- var symbols = Object.getOwnPropertySymbols(object)
12
- enumerableOnly &&
13
- (symbols = symbols.filter(function (sym) {
14
- return Object.getOwnPropertyDescriptor(object, sym).enumerable
15
- })),
16
- keys.push.apply(keys, symbols)
17
- }
18
- return keys
19
- }
20
- function _objectSpread(target) {
21
- for (var i = 1; i < arguments.length; i++) {
22
- var source = null != arguments[i] ? arguments[i] : {}
23
- i % 2
24
- ? ownKeys(Object(source), !0).forEach(function (key) {
25
- _defineProperty(target, key, source[key])
26
- })
27
- : Object.getOwnPropertyDescriptors
28
- ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source))
29
- : ownKeys(Object(source)).forEach(function (key) {
30
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key))
31
- })
32
- }
33
- return target
34
- }
35
- function _defineProperty(obj, key, value) {
36
- key = _toPropertyKey(key)
37
- if (key in obj) {
38
- Object.defineProperty(obj, key, {
39
- value: value,
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- })
44
- } else {
45
- obj[key] = value
46
- }
47
- return obj
48
- }
49
- function _classCallCheck(instance, Constructor) {
50
- if (!(instance instanceof Constructor)) {
51
- throw new TypeError('Cannot call a class as a function')
52
- }
53
- }
54
- function _defineProperties(target, props) {
55
- for (var i = 0; i < props.length; i++) {
56
- var descriptor = props[i]
57
- descriptor.enumerable = descriptor.enumerable || false
58
- descriptor.configurable = true
59
- if ('value' in descriptor) descriptor.writable = true
60
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor)
61
- }
62
- }
63
- function _createClass(Constructor, protoProps, staticProps) {
64
- if (protoProps) _defineProperties(Constructor.prototype, protoProps)
65
- if (staticProps) _defineProperties(Constructor, staticProps)
66
- Object.defineProperty(Constructor, 'prototype', { writable: false })
67
- return Constructor
68
- }
69
- function _toPropertyKey(arg) {
70
- var key = _toPrimitive(arg, 'string')
71
- return typeof key === 'symbol' ? key : String(key)
72
- }
73
- function _toPrimitive(input, hint) {
74
- if (typeof input !== 'object' || input === null) return input
75
- var prim = input[Symbol.toPrimitive]
76
- if (prim !== undefined) {
77
- var res = prim.call(input, hint || 'default')
78
- if (typeof res !== 'object') return res
79
- throw new TypeError('@@toPrimitive must return a primitive value.')
80
- }
81
- return (hint === 'string' ? String : Number)(input)
82
- }
83
- var Event = /*#__PURE__*/ (function () {
84
- function Event() {
85
- _classCallCheck(this, Event)
86
- this.subscribers = {}
87
- }
88
- _createClass(
89
- Event,
90
- [
91
- {
92
- key: 'addSubscriber',
93
- value: function addSubscriber(eventName, callback) {
94
- if (Event.invalid(eventName)) {
95
- throw new _invalidEvent.InvalidEvent(eventName)
96
- }
97
- this.subscribers = _objectSpread(
98
- _objectSpread({}, this.subscribers),
99
- {},
100
- {
101
- [eventName]: this.subscribers[eventName]
102
- ? [...this.subscribers[eventName], callback]
103
- : [callback],
104
- },
105
- )
106
- },
107
- },
108
- {
109
- key: 'removeSubscriber',
110
- value: function removeSubscriber(eventName, callback) {
111
- if (Event.invalid(eventName)) {
112
- throw new _invalidEvent.InvalidEvent(eventName)
113
- }
114
- if (this.subscribers[eventName]) {
115
- this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback)
116
- }
117
- },
118
- },
119
- {
120
- key: 'dispatch',
121
- value: function dispatch(eventName, data) {
122
- var _this$subscribers$eve
123
- ;(_this$subscribers$eve = this.subscribers[eventName]) === null ||
124
- _this$subscribers$eve === void 0
125
- ? void 0
126
- : _this$subscribers$eve.forEach(subscriber => {
127
- subscriber(data)
128
- })
129
- },
130
- },
131
- {
132
- key: 'listeners',
133
- get: function get() {
134
- return Object.keys(this.subscribers).length !== 0
135
- },
136
- },
137
- ],
138
- [
139
- {
140
- key: 'valid',
141
- value: function valid(name) {
142
- return Event.exists(name)
143
- },
144
- },
145
- {
146
- key: 'invalid',
147
- value: function invalid(name) {
148
- return !this.valid(name)
149
- },
150
- },
151
- {
152
- key: 'exists',
153
- value: function exists(name) {
154
- return this.events.find(eventName => eventName === name) !== undefined
155
- },
156
- },
157
- ],
158
- )
159
- return Event
160
- })()
161
- exports.default = Event
162
- Event.events = ['session-set', 'forms:collected', 'form:completed']
@@ -1,142 +0,0 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- })
6
- exports.default = void 0
7
- var _event = _interopRequireDefault(require('./event'))
8
- var _invalidEvent = require('./errors/invalidEvent')
9
- function _interopRequireDefault(obj) {
10
- return obj && obj.__esModule ? obj : { default: obj }
11
- }
12
- function ownKeys(object, enumerableOnly) {
13
- var keys = Object.keys(object)
14
- if (Object.getOwnPropertySymbols) {
15
- var symbols = Object.getOwnPropertySymbols(object)
16
- enumerableOnly &&
17
- (symbols = symbols.filter(function (sym) {
18
- return Object.getOwnPropertyDescriptor(object, sym).enumerable
19
- })),
20
- keys.push.apply(keys, symbols)
21
- }
22
- return keys
23
- }
24
- function _objectSpread(target) {
25
- for (var i = 1; i < arguments.length; i++) {
26
- var source = null != arguments[i] ? arguments[i] : {}
27
- i % 2
28
- ? ownKeys(Object(source), !0).forEach(function (key) {
29
- _defineProperty(target, key, source[key])
30
- })
31
- : Object.getOwnPropertyDescriptors
32
- ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source))
33
- : ownKeys(Object(source)).forEach(function (key) {
34
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key))
35
- })
36
- }
37
- return target
38
- }
39
- function _defineProperty(obj, key, value) {
40
- key = _toPropertyKey(key)
41
- if (key in obj) {
42
- Object.defineProperty(obj, key, {
43
- value: value,
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- })
48
- } else {
49
- obj[key] = value
50
- }
51
- return obj
52
- }
53
- function _classCallCheck(instance, Constructor) {
54
- if (!(instance instanceof Constructor)) {
55
- throw new TypeError('Cannot call a class as a function')
56
- }
57
- }
58
- function _defineProperties(target, props) {
59
- for (var i = 0; i < props.length; i++) {
60
- var descriptor = props[i]
61
- descriptor.enumerable = descriptor.enumerable || false
62
- descriptor.configurable = true
63
- if ('value' in descriptor) descriptor.writable = true
64
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor)
65
- }
66
- }
67
- function _createClass(Constructor, protoProps, staticProps) {
68
- if (protoProps) _defineProperties(Constructor.prototype, protoProps)
69
- if (staticProps) _defineProperties(Constructor, staticProps)
70
- Object.defineProperty(Constructor, 'prototype', { writable: false })
71
- return Constructor
72
- }
73
- function _toPropertyKey(arg) {
74
- var key = _toPrimitive(arg, 'string')
75
- return typeof key === 'symbol' ? key : String(key)
76
- }
77
- function _toPrimitive(input, hint) {
78
- if (typeof input !== 'object' || input === null) return input
79
- var prim = input[Symbol.toPrimitive]
80
- if (prim !== undefined) {
81
- var res = prim.call(input, hint || 'default')
82
- if (typeof res !== 'object') return res
83
- throw new TypeError('@@toPrimitive must return a primitive value.')
84
- }
85
- return (hint === 'string' ? String : Number)(input)
86
- }
87
- var EventEmitter = /*#__PURE__*/ (function () {
88
- function EventEmitter() {
89
- _classCallCheck(this, EventEmitter)
90
- this.subscribers = {}
91
- }
92
- _createClass(EventEmitter, [
93
- {
94
- key: 'addSubscriber',
95
- value: function addSubscriber(eventName, callback) {
96
- if (_event.default.invalid(eventName)) {
97
- throw new _invalidEvent.InvalidEvent(eventName)
98
- }
99
- this.subscribers = _objectSpread(
100
- _objectSpread({}, this.subscribers),
101
- {},
102
- {
103
- [eventName]: this.subscribers[eventName]
104
- ? [...this.subscribers[eventName], callback]
105
- : [callback],
106
- },
107
- )
108
- },
109
- },
110
- {
111
- key: 'removeSubscriber',
112
- value: function removeSubscriber(eventName, callback) {
113
- if (_event.default.invalid(eventName)) {
114
- throw new _invalidEvent.InvalidEvent(eventName)
115
- }
116
- if (this.subscribers[eventName]) {
117
- this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback)
118
- }
119
- },
120
- },
121
- {
122
- key: 'emit',
123
- value: function emit(eventName, data) {
124
- var _this$subscribers$eve
125
- ;(_this$subscribers$eve = this.subscribers[eventName]) === null ||
126
- _this$subscribers$eve === void 0
127
- ? void 0
128
- : _this$subscribers$eve.forEach(subscriber => {
129
- subscriber(data)
130
- })
131
- },
132
- },
133
- {
134
- key: 'listeners',
135
- get: function get() {
136
- return Object.keys(this.subscribers).length !== 0
137
- },
138
- },
139
- ])
140
- return EventEmitter
141
- })()
142
- exports.default = EventEmitter