@4i/modal-manager 1.0.6 → 1.0.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,11 +1,12 @@
1
1
  {
2
2
  "name": "@4i/modal-manager",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
- "main": "src/index.js",
5
+ "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
- "build": "tsc"
8
+ "build": "tsc",
9
+ "start": "src/index.ts"
9
10
  },
10
11
  "repository": {
11
12
  "type": "git",
package/src/index.ts CHANGED
File without changes
@@ -1,5 +1,5 @@
1
1
  export interface ModalList {
2
- [key: string]: string;
2
+ [key: string]: (...args: any[]) => any;
3
3
  }
4
4
  declare let modalList: ModalList;
5
5
  export declare const setModalList: (_modalList: ModalList) => void;
@@ -1,5 +1,5 @@
1
1
  export interface ModalList {
2
- [key: string]: string;
2
+ [key: string]: (...args: any[]) => any;
3
3
  }
4
4
 
5
5
  let modalList: ModalList = {};
@@ -2,12 +2,15 @@
2
2
  import { EventEmitter } from "events";
3
3
  declare class Manager {
4
4
  emitter: EventEmitter;
5
- name: string;
5
+ name: string | null;
6
6
  data: {
7
7
  [key: string]: any;
8
8
  };
9
9
  constructor();
10
10
  addEventListener(event: string, listener: (...args: any[]) => void): void;
11
11
  removeEventListener(event: string, listener: (...args: any[]) => void): void;
12
+ emitChange(): void;
13
+ close(...closeList: number[]): void;
14
+ emitClose<T>(closeList?: T): void;
12
15
  }
13
16
  export default Manager;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var events_1 = require("events");
4
- var Constants = {
4
+ var constants = {
5
5
  CHANGE: "change",
6
6
  CLOSE: "close",
7
7
  };
@@ -17,6 +17,21 @@ var Manager = /** @class */ (function () {
17
17
  Manager.prototype.removeEventListener = function (event, listener) {
18
18
  this.emitter.removeListener(event, listener);
19
19
  };
20
+ Manager.prototype.emitChange = function () {
21
+ this.emitter.emit(constants.CHANGE, this.name, this.data);
22
+ };
23
+ Manager.prototype.close = function () {
24
+ var closeList = [];
25
+ for (var _i = 0; _i < arguments.length; _i++) {
26
+ closeList[_i] = arguments[_i];
27
+ }
28
+ this.name = null;
29
+ this.data = {};
30
+ this.emitClose(closeList);
31
+ };
32
+ Manager.prototype.emitClose = function (closeList) {
33
+ this.emitter.emit(constants.CLOSE, closeList);
34
+ };
20
35
  return Manager;
21
36
  }());
22
37
  exports.default = Manager;
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from "events";
2
2
 
3
- const Constants = {
3
+ const constants = {
4
4
  CHANGE: "change",
5
5
  CLOSE: "close",
6
6
  };
@@ -11,7 +11,7 @@ type TData = {
11
11
 
12
12
  class Manager {
13
13
  emitter: EventEmitter;
14
- name: string;
14
+ name: string | null;
15
15
  data: { [key: string]: any };
16
16
 
17
17
  constructor() {
@@ -27,6 +27,17 @@ class Manager {
27
27
  removeEventListener(event: string, listener: (...args: any[]) => void) {
28
28
  this.emitter.removeListener(event, listener);
29
29
  }
30
+ emitChange() {
31
+ this.emitter.emit(constants.CHANGE, this.name, this.data);
32
+ }
33
+ close(...closeList: number[]) {
34
+ this.name = null;
35
+ this.data = {};
36
+ this.emitClose(closeList);
37
+ }
38
+ emitClose<T>(closeList?: T) {
39
+ this.emitter.emit(constants.CLOSE, closeList);
40
+ }
30
41
  }
31
42
 
32
43
  export default Manager;
@@ -5,7 +5,7 @@ declare class ModalManager extends Manager {
5
5
  [key: string]: any;
6
6
  }): void;
7
7
  call(name: string, data?: any): void;
8
- close(position?: number): void;
8
+ emitClose<T>(position?: T): void;
9
9
  }
10
10
  declare const modal: ModalManager;
11
11
  export default modal;
@@ -32,13 +32,13 @@ var ModalManager = /** @class */ (function (_super) {
32
32
  ModalManager.prototype.create = function (name, data) {
33
33
  this.name = name;
34
34
  this.data = data;
35
- this.emitter.emit(constants.CHANGE);
35
+ this.emitChange();
36
36
  };
37
37
  ModalManager.prototype.call = function (name, data) {
38
38
  if (data === void 0) { data = {}; }
39
39
  this.create(name, { modalId: (0, uuid_1.v4)(), data: data });
40
40
  };
41
- ModalManager.prototype.close = function (position) {
41
+ ModalManager.prototype.emitClose = function (position) {
42
42
  this.emitter.emit(constants.CLOSE, position);
43
43
  };
44
44
  return ModalManager;
@@ -14,14 +14,14 @@ class ModalManager extends Manager {
14
14
  create(name: string, data: { [key: string]: any }) {
15
15
  this.name = name;
16
16
  this.data = data;
17
- this.emitter.emit(constants.CHANGE, this.name, this.data);
17
+ this.emitChange();
18
18
  }
19
19
 
20
20
  call(name: string, data: any = {}) {
21
21
  this.create(name, { modalId: uuidv4(), data });
22
22
  }
23
23
 
24
- close(position?: number) {
24
+ emitClose<T>(position?: T) {
25
25
  this.emitter.emit(constants.CLOSE, position);
26
26
  }
27
27
  }