@doreamonjs/plugin-shared 0.3.6 → 0.3.7
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 +8 -0
- package/lib/index.js +2 -0
- package/lib/message.js +5 -2
- package/lib/notification.js +5 -2
- package/lib/router.d.ts +3 -4
- package/lib/router.js +13 -18
- package/lib/shared.d.ts +8 -0
- package/lib/shared.js +23 -0
- package/lib/type.d.ts +3 -5
- package/lib/type.js +0 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.7](https://github.com/zcorky/zodash/compare/v0.3.6...v0.3.7) (2022-08-31)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @doreamonjs/plugin-shared
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [0.3.6](https://github.com/zcorky/zodash/compare/v0.3.5...v0.3.6) (2022-08-31)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @doreamonjs/plugin-shared
|
package/lib/index.js
CHANGED
|
@@ -10,7 +10,9 @@ 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);
|
|
14
15
|
__exportStar(require("./message"), exports);
|
|
15
16
|
__exportStar(require("./notification"), exports);
|
|
16
17
|
__exportStar(require("./router"), exports);
|
|
18
|
+
window.__doreamonjs = shared_1.shared;
|
package/lib/message.js
CHANGED
|
@@ -12,8 +12,11 @@ class Message {
|
|
|
12
12
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.messager) {
|
|
13
13
|
this._messager = (_b = this.options) === null || _b === void 0 ? void 0 : _b.messager;
|
|
14
14
|
}
|
|
15
|
-
else if (window.__doreamonjs.message) {
|
|
16
|
-
this._messager = window.__doreamonjs.message;
|
|
15
|
+
else if (window.__doreamonjs.has('message')) {
|
|
16
|
+
this._messager = window.__doreamonjs.get('message');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error('[doreamonjs] message is not registered');
|
|
17
20
|
}
|
|
18
21
|
return this._messager;
|
|
19
22
|
}
|
package/lib/notification.js
CHANGED
|
@@ -12,8 +12,11 @@ class Notification {
|
|
|
12
12
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.notifier) {
|
|
13
13
|
this._notifier = (_b = this.options) === null || _b === void 0 ? void 0 : _b.notifier;
|
|
14
14
|
}
|
|
15
|
-
else if (window.__doreamonjs.notification) {
|
|
16
|
-
this._notifier = window.__doreamonjs.notification;
|
|
15
|
+
else if (window.__doreamonjs.has('notification')) {
|
|
16
|
+
this._notifier = window.__doreamonjs.get('notification');
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error('[doreamonjs] nitification is not registered');
|
|
17
20
|
}
|
|
18
21
|
return this._notifier;
|
|
19
22
|
}
|
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,13 @@ export interface RouteData {
|
|
|
12
11
|
state?: any;
|
|
13
12
|
}
|
|
14
13
|
export interface RouterOptions {
|
|
15
|
-
|
|
14
|
+
router?: IRouter;
|
|
16
15
|
}
|
|
17
16
|
export declare class Router implements IRouter {
|
|
18
17
|
private readonly options?;
|
|
19
|
-
private
|
|
18
|
+
private _router;
|
|
20
19
|
constructor(options?: RouterOptions);
|
|
21
|
-
private get
|
|
20
|
+
private get router();
|
|
22
21
|
push(path: string | RouteData, state?: any): void;
|
|
23
22
|
replace(path: string | RouteData, state?: any): void;
|
|
24
23
|
go(count: number): void;
|
package/lib/router.js
CHANGED
|
@@ -1,42 +1,37 @@
|
|
|
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");
|
|
5
4
|
class Router {
|
|
6
5
|
constructor(options) {
|
|
7
6
|
this.options = options;
|
|
8
7
|
}
|
|
9
|
-
get
|
|
8
|
+
get router() {
|
|
10
9
|
var _a, _b;
|
|
11
|
-
if (this.
|
|
12
|
-
return this.
|
|
13
|
-
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.
|
|
14
|
-
this.
|
|
10
|
+
if (this._router)
|
|
11
|
+
return this._router;
|
|
12
|
+
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.router) {
|
|
13
|
+
this._router = (_b = this.options) === null || _b === void 0 ? void 0 : _b.router;
|
|
15
14
|
}
|
|
16
|
-
else if (window.__doreamonjs.
|
|
15
|
+
else if (window.__doreamonjs.has('router')) {
|
|
17
16
|
// doreamonjs
|
|
18
|
-
this.
|
|
19
|
-
}
|
|
20
|
-
else if (window.g_history) {
|
|
21
|
-
// umi
|
|
22
|
-
this._history = window.g_history;
|
|
17
|
+
this._router = window.__doreamonjs.get('router');
|
|
23
18
|
}
|
|
24
19
|
else {
|
|
25
|
-
|
|
20
|
+
throw new Error('[doreamonjs] router is not registered');
|
|
26
21
|
}
|
|
27
|
-
return this.
|
|
22
|
+
return this._router;
|
|
28
23
|
}
|
|
29
24
|
push(path, state) {
|
|
30
|
-
this.
|
|
25
|
+
this.router.push(path, state);
|
|
31
26
|
}
|
|
32
27
|
replace(path, state) {
|
|
33
|
-
this.
|
|
28
|
+
this.router.replace(path, state);
|
|
34
29
|
}
|
|
35
30
|
go(count) {
|
|
36
|
-
this.
|
|
31
|
+
this.router.go(count);
|
|
37
32
|
}
|
|
38
33
|
goBack() {
|
|
39
|
-
this.
|
|
34
|
+
this.router.goBack();
|
|
40
35
|
}
|
|
41
36
|
}
|
|
42
37
|
exports.Router = Router;
|
package/lib/shared.d.ts
ADDED
|
@@ -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,23 @@
|
|
|
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(`Shared service ${key} not registered`);
|
|
15
|
+
}
|
|
16
|
+
return service;
|
|
17
|
+
}
|
|
18
|
+
has(key) {
|
|
19
|
+
return !!this.store[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.Shared = Shared;
|
|
23
|
+
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:
|
|
4
|
+
__doreamonjs: DoreamonJSShared;
|
|
4
5
|
}
|
|
5
6
|
}
|
|
6
|
-
export interface
|
|
7
|
-
message: any;
|
|
8
|
-
history: any;
|
|
9
|
-
notification: any;
|
|
7
|
+
export interface DoreamonJSShared extends Shared {
|
|
10
8
|
}
|
package/lib/type.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doreamonjs/plugin-shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
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": "
|
|
74
|
+
"gitHead": "2cf9eafc163ecd43d50cb9c6bd5c1c82ab5fb37d"
|
|
75
75
|
}
|