@doreamonjs/plugin-shared 0.3.6 → 0.3.9

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/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.3.9](https://github.com/zcorky/zodash/compare/v0.3.8...v0.3.9) (2022-08-31)
7
+
8
+ **Note:** Version bump only for package @doreamonjs/plugin-shared
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.3.8](https://github.com/zcorky/zodash/compare/v0.3.7...v0.3.8) (2022-08-31)
15
+
16
+ **Note:** Version bump only for package @doreamonjs/plugin-shared
17
+
18
+
19
+
20
+
21
+
22
+ ## [0.3.7](https://github.com/zcorky/zodash/compare/v0.3.6...v0.3.7) (2022-08-31)
23
+
24
+ **Note:** Version bump only for package @doreamonjs/plugin-shared
25
+
26
+
27
+
28
+
29
+
6
30
  ## [0.3.6](https://github.com/zcorky/zodash/compare/v0.3.5...v0.3.6) (2022-08-31)
7
31
 
8
32
  **Note:** Version bump only for package @doreamonjs/plugin-shared
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './type';
2
+ export * from './shared';
2
3
  export * from './message';
3
4
  export * from './notification';
4
5
  export * from './router';
package/lib/index.js CHANGED
@@ -10,7 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ const shared_1 = require("./shared");
13
14
  __exportStar(require("./type"), exports);
15
+ __exportStar(require("./shared"), exports);
14
16
  __exportStar(require("./message"), exports);
15
17
  __exportStar(require("./notification"), exports);
16
18
  __exportStar(require("./router"), exports);
19
+ window.__doreamonjs = shared_1.shared;
package/lib/message.d.ts CHANGED
@@ -33,13 +33,12 @@ export interface OpenConfig {
33
33
  }
34
34
  export declare type NoticeType = 'info' | 'success' | 'error' | 'warning' | 'loading';
35
35
  export interface MessageConfig {
36
- messager?: IMessage;
36
+ message?: IMessage;
37
37
  }
38
38
  export declare class Message implements IMessage {
39
39
  private readonly options?;
40
- private _messager;
41
40
  constructor(options?: MessageConfig);
42
- private get messager();
41
+ private get message();
43
42
  info(content: string, duration?: number, onClose?: () => void): void | Promise<void>;
44
43
  success(content: string, duration?: number, onClose?: () => void): void | Promise<void>;
45
44
  error(content: string, duration?: number, onClose?: () => void): void | Promise<void>;
package/lib/message.js CHANGED
@@ -1,44 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.message = exports.Message = void 0;
4
+ const shared_1 = require("./shared");
4
5
  class Message {
5
6
  constructor(options) {
6
7
  this.options = options;
7
8
  }
8
- get messager() {
9
+ get message() {
9
10
  var _a, _b;
10
- if (this._messager)
11
- return this._messager;
12
- if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.messager) {
13
- this._messager = (_b = this.options) === null || _b === void 0 ? void 0 : _b.messager;
11
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.message) {
12
+ return (_b = this.options) === null || _b === void 0 ? void 0 : _b.message;
14
13
  }
15
- else if (window.__doreamonjs.message) {
16
- this._messager = window.__doreamonjs.message;
17
- }
18
- return this._messager;
14
+ return shared_1.shared.get('message');
19
15
  }
20
16
  info(content, duration, onClose) {
21
- return this.messager.info(content, duration, onClose);
17
+ return this.message.info(content, duration, onClose);
22
18
  }
23
19
  success(content, duration, onClose) {
24
- return this.messager.success(content, duration, onClose);
20
+ return this.message.success(content, duration, onClose);
25
21
  }
26
22
  error(content, duration, onClose) {
27
- return this.messager.error(content, duration, onClose);
23
+ return this.message.error(content, duration, onClose);
28
24
  }
29
25
  warning(content, duration, onClose) {
30
- return this.messager.warning(content, duration, onClose);
26
+ return this.message.warning(content, duration, onClose);
31
27
  }
32
28
  loading(content, duration, onClose) {
33
- return this.messager.loading(content, duration, onClose);
29
+ return this.message.loading(content, duration, onClose);
34
30
  }
35
31
  //
36
32
  open(config) {
37
- return this.messager.open(config);
33
+ return this.message.open(config);
38
34
  }
39
35
  config(options) {
40
36
  var _a, _b;
41
- return (_b = (_a = this.messager) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.call(_a, options);
37
+ return (_b = (_a = this.message) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.call(_a, options);
42
38
  }
43
39
  }
44
40
  exports.Message = Message;
@@ -40,7 +40,7 @@ export interface ConfigNotificationOptions {
40
40
  export declare type NotificationPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
41
41
  export declare type IconType = 'success' | 'info' | 'error' | 'warning';
42
42
  export interface NotificationConfig {
43
- notifier?: INotification;
43
+ notification?: INotification;
44
44
  }
45
45
  export declare class Notification implements INotification {
46
46
  private readonly options?;
@@ -1,21 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.notification = exports.Notification = void 0;
4
+ const shared_1 = require("./shared");
4
5
  class Notification {
5
6
  constructor(options) {
6
7
  this.options = options;
7
8
  }
8
9
  get notifier() {
9
10
  var _a, _b;
10
- if (this._notifier)
11
- return this._notifier;
12
- if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.notifier) {
13
- this._notifier = (_b = this.options) === null || _b === void 0 ? void 0 : _b.notifier;
11
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.notification) {
12
+ return (_b = this.options) === null || _b === void 0 ? void 0 : _b.notification;
14
13
  }
15
- else if (window.__doreamonjs.notification) {
16
- this._notifier = window.__doreamonjs.notification;
17
- }
18
- return this._notifier;
14
+ return shared_1.shared.get('notification');
19
15
  }
20
16
  success(cfg) {
21
17
  return this.notifier.success(cfg);
package/lib/router.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { History } from 'history';
2
1
  export interface IRouter {
3
2
  push: (path: string | RouteData, state?: any) => void;
4
3
  replace: (path: string | RouteData, state?: any) => void;
@@ -12,13 +11,12 @@ export interface RouteData {
12
11
  state?: any;
13
12
  }
14
13
  export interface RouterOptions {
15
- history?: History;
14
+ router?: IRouter;
16
15
  }
17
16
  export declare class Router implements IRouter {
18
17
  private readonly options?;
19
- private _history;
20
18
  constructor(options?: RouterOptions);
21
- private get history();
19
+ private get router();
22
20
  push(path: string | RouteData, state?: any): void;
23
21
  replace(path: string | RouteData, state?: any): void;
24
22
  go(count: number): void;
package/lib/router.js CHANGED
@@ -1,42 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.router = exports.Router = void 0;
4
- const history_1 = require("history");
4
+ const shared_1 = require("./shared");
5
5
  class Router {
6
6
  constructor(options) {
7
7
  this.options = options;
8
8
  }
9
- get history() {
9
+ get router() {
10
10
  var _a, _b;
11
- if (this._history)
12
- return this._history;
13
- if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.history) {
14
- this._history = (_b = this.options) === null || _b === void 0 ? void 0 : _b.history;
11
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.router) {
12
+ return (_b = this.options) === null || _b === void 0 ? void 0 : _b.router;
15
13
  }
16
- else if (window.__doreamonjs.history) {
17
- // doreamonjs
18
- this._history = window.__doreamonjs.history;
19
- }
20
- else if (window.g_history) {
21
- // umi
22
- this._history = window.g_history;
23
- }
24
- else {
25
- this._history = history_1.createBrowserHistory();
26
- }
27
- return this._history;
14
+ return shared_1.shared.get('router');
28
15
  }
29
16
  push(path, state) {
30
- this.history.push(path, state);
17
+ this.router.push(path, state);
31
18
  }
32
19
  replace(path, state) {
33
- this.history.replace(path, state);
20
+ this.router.replace(path, state);
34
21
  }
35
22
  go(count) {
36
- this.history.go(count);
23
+ this.router.go(count);
37
24
  }
38
25
  goBack() {
39
- this.history.back();
26
+ this.router.goBack();
40
27
  }
41
28
  }
42
29
  exports.Router = Router;
@@ -0,0 +1,8 @@
1
+ export declare type SharedServiceKey = 'message' | 'notification' | 'router';
2
+ export declare class Shared {
3
+ private store;
4
+ register(key: SharedServiceKey, value: any): void;
5
+ get(key: SharedServiceKey): any;
6
+ has(key: SharedServiceKey): boolean;
7
+ }
8
+ export declare const shared: Shared;
package/lib/shared.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shared = exports.Shared = void 0;
4
+ class Shared {
5
+ constructor() {
6
+ this.store = {};
7
+ }
8
+ register(key, value) {
9
+ this.store[key] = value;
10
+ }
11
+ get(key) {
12
+ const service = this.store[key];
13
+ if (!service) {
14
+ // throw new Error('[doreamonjs] router is not registered');
15
+ throw new Error(`[doreamonjs] shared service ${key} is not registered`);
16
+ }
17
+ return service;
18
+ }
19
+ has(key) {
20
+ return !!this.store[key];
21
+ }
22
+ }
23
+ exports.Shared = Shared;
24
+ exports.shared = new Shared();
package/lib/type.d.ts CHANGED
@@ -1,10 +1,8 @@
1
+ import { Shared } from './shared';
1
2
  declare global {
2
3
  interface Window {
3
- __doreamonjs: DoreamonJS;
4
+ __doreamonjs: DoreamonJSShared;
4
5
  }
5
6
  }
6
- export interface DoreamonJS {
7
- message: any;
8
- history: any;
9
- notification: any;
7
+ export interface DoreamonJSShared extends Shared {
10
8
  }
package/lib/type.js CHANGED
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- window.__doreamonjs = window.__doreamonjs || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doreamonjs/plugin-shared",
3
- "version": "0.3.6",
3
+ "version": "0.3.9",
4
4
  "description": "shared plugin for doreamonjs",
5
5
  "keywords": [
6
6
  "doreamonjs",
@@ -71,5 +71,5 @@
71
71
  "@zodash/doreamon": "^1.0.17",
72
72
  "history": "^5.3.0"
73
73
  },
74
- "gitHead": "3ad0b680e6da424c4b48b4df426b7482c38eef24"
74
+ "gitHead": "fa400a314445ddfe73c9764f0b05bdb9568aa029"
75
75
  }