@pisell/core 1.0.20 → 1.0.22

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/es/app/app.d.ts CHANGED
@@ -35,7 +35,7 @@ declare class App {
35
35
  locales: Locales;
36
36
  models: {
37
37
  getStore: () => import("../models").Store;
38
- StoreProvider: typeof import("react-redux").Provider;
38
+ StoreProvider: any;
39
39
  setConfig: (models: any[]) => void;
40
40
  };
41
41
  request: {
@@ -301,13 +301,10 @@ export var Application = /*#__PURE__*/function () {
301
301
  key: "setComponent",
302
302
  value: function setComponent(code, component) {
303
303
  var _this4 = this;
304
- var Component = function Component() {
304
+ var Component = function Component(props) {
305
305
  var _ref4 = useRef();
306
306
  var Com = component === null || component === void 0 ? void 0 : component.Component;
307
- for (var _len = arguments.length, result = new Array(_len), _key = 0; _key < _len; _key++) {
308
- result[_key] = arguments[_key];
309
- }
310
- return /*#__PURE__*/React.createElement(Com, _extends({}, result, {
307
+ return /*#__PURE__*/React.createElement(Com, _extends({}, props, {
311
308
  ref: function ref(_ref) {
312
309
  _ref4.current = _ref;
313
310
  console.log('组件ref执行了');
@@ -318,7 +315,7 @@ export var Application = /*#__PURE__*/function () {
318
315
  }));
319
316
  };
320
317
  this.components.set(code, _objectSpread(_objectSpread({}, component), {}, {
321
- Component: Component
318
+ Component: component.autoRender ? Component : component.Component
322
319
  }));
323
320
  }
324
321
 
@@ -386,8 +383,8 @@ export var Application = /*#__PURE__*/function () {
386
383
  var _params = _objectSpread({
387
384
  app: this.app
388
385
  }, params);
389
- for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
390
- args[_key2 - 2] = arguments[_key2];
386
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
387
+ args[_key - 2] = arguments[_key];
391
388
  }
392
389
  return (_this$getFunction = this.getFunction(code)) === null || _this$getFunction === void 0 ? void 0 : _this$getFunction.code.apply(_this$getFunction, [_params].concat(args));
393
390
  }
package/es/aws/index.d.ts CHANGED
@@ -11,6 +11,6 @@ declare class AWS {
11
11
  private app;
12
12
  private config?;
13
13
  constructor(app: App, options?: AWSOptions);
14
- upload(params: UploadParams): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
14
+ upload(params: UploadParams): Promise<any>;
15
15
  }
16
16
  export default AWS;
@@ -1,14 +1,13 @@
1
1
  import type { History as HistoryType } from "history";
2
- import { useHistory, useLocation, useParams } from "react-router-dom";
3
2
  import App from "../app";
4
3
  export interface HistoryOptions {
5
4
  basename?: string;
6
5
  }
7
6
  export declare class History {
8
- instance: HistoryType<unknown>;
9
- useHistory: typeof useHistory;
10
- useLocation: typeof useLocation;
11
- useParams: typeof useParams;
7
+ instance: any;
8
+ useHistory: any;
9
+ useLocation: any;
10
+ useParams: any;
12
11
  app: App;
13
12
  constructor(app: App, options?: HistoryOptions);
14
13
  push: HistoryType["push"];
@@ -14,4 +14,4 @@ export declare const MenuProvider: React.FC<{
14
14
  children: React.ReactNode;
15
15
  menus: MenuItem[];
16
16
  }>;
17
- export declare const useMenu: () => MenuContextType;
17
+ export declare const useMenu: () => any;
@@ -12,7 +12,7 @@ export declare class MenuManager {
12
12
  private menuItems;
13
13
  private menuMaps;
14
14
  private app;
15
- useMenu: () => import("./hooks").MenuContextType;
15
+ useMenu: () => any;
16
16
  MenuProvider: React.FC<{
17
17
  children: React.ReactNode;
18
18
  menus: MenuItem[];
@@ -1,5 +1,4 @@
1
1
  import hooks from '../hooks';
2
- import { Provider as StoreProvider } from "react-redux";
3
2
  declare const models: import("./global").GlobalModal[];
4
3
  declare type ModalsType = (typeof models[number]);
5
4
  export interface Store {
@@ -39,7 +38,7 @@ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T
39
38
  declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
40
39
  declare const _default: {
41
40
  getStore: () => Store;
42
- StoreProvider: typeof StoreProvider;
41
+ StoreProvider: any;
43
42
  setConfig: (models: any[]) => void;
44
43
  };
45
44
  export default _default;
@@ -28,6 +28,16 @@ declare class PubSub {
28
28
  * @param args 事件参数
29
29
  */
30
30
  publish(event: string, ...args: any[]): void;
31
+ /**
32
+ * @title: 异步发布, 某些事件需要延迟发布
33
+ * @description:
34
+ * @param {string} event
35
+ * @param {number} timeout
36
+ * @param {array} args
37
+ * @return {*}
38
+ * @Author: zhiwei.Wang
39
+ */
40
+ publishDelay(event: string, delay?: number, ...args: any[]): void;
31
41
  /**
32
42
  * 移除某个事件的所有订阅
33
43
  * @param event 事件名称
@@ -77,6 +77,28 @@ var PubSub = /*#__PURE__*/function () {
77
77
  });
78
78
  }
79
79
 
80
+ /**
81
+ * @title: 异步发布, 某些事件需要延迟发布
82
+ * @description:
83
+ * @param {string} event
84
+ * @param {number} timeout
85
+ * @param {array} args
86
+ * @return {*}
87
+ * @Author: zhiwei.Wang
88
+ */
89
+ }, {
90
+ key: "publishDelay",
91
+ value: function publishDelay(event) {
92
+ var _this2 = this;
93
+ var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
94
+ for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
95
+ args[_key2 - 2] = arguments[_key2];
96
+ }
97
+ setTimeout(function () {
98
+ _this2.publish.apply(_this2, [event].concat(args));
99
+ }, delay);
100
+ }
101
+
80
102
  /**
81
103
  * 移除某个事件的所有订阅
82
104
  * @param event 事件名称
@@ -129,9 +151,9 @@ var PubSub = /*#__PURE__*/function () {
129
151
  }, {
130
152
  key: "once",
131
153
  value: function once(event, callback) {
132
- var _this2 = this;
154
+ var _this3 = this;
133
155
  var wrappedCallback = function wrappedCallback() {
134
- _this2.unsubscribe(event, wrappedCallback);
156
+ _this3.unsubscribe(event, wrappedCallback);
135
157
  callback.apply(void 0, arguments);
136
158
  };
137
159
  return this.subscribe(event, wrappedCallback);
@@ -32,7 +32,7 @@ export declare const getCacheData: (url: string, data: any, cache: CacheProps) =
32
32
  * @return {*}
33
33
  * @Author: zhiwei.Wang
34
34
  */
35
- export declare const setCacheData: (url: string, data: any, res: any, cache: CacheProps) => any | null;
35
+ export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
36
36
  /**
37
37
  * @title: 缓存函数包装器
38
38
  * @description:
@@ -251,7 +251,10 @@ export var getCacheData = /*#__PURE__*/function () {
251
251
  * @return {*}
252
252
  * @Author: zhiwei.Wang
253
253
  */
254
- export var setCacheData = function setCacheData(url, data, res, cache) {
254
+ export var setCacheData = function setCacheData(url, data, res) {
255
+ var cache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
256
+ type: 'memory'
257
+ };
255
258
  // 创建缓存key
256
259
  var _key = createCacheKey(url, data, cache);
257
260
  setCache(_key, res, cache);
@@ -269,37 +272,44 @@ export var setCacheData = function setCacheData(url, data, res, cache) {
269
272
  */
270
273
  export var cacheFn = /*#__PURE__*/function () {
271
274
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(props, fn) {
272
- var url, data, config, _data, _config$cache;
275
+ var url, data, config, cache, _data, _config$cache;
273
276
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
274
277
  while (1) switch (_context4.prev = _context4.next) {
275
278
  case 0:
276
279
  url = props.url, data = props.data, config = props.config;
277
- if (!(config !== null && config !== void 0 && config.cache)) {
278
- _context4.next = 8;
280
+ if (!(config !== null && config !== void 0 && config.cache || config !== null && config !== void 0 && config.useCache)) {
281
+ _context4.next = 10;
279
282
  break;
280
283
  }
281
- _context4.next = 4;
282
- return getCacheData(url, data, config.cache);
283
- case 4:
284
+ cache = config.cache;
285
+ if (config.useCache) {
286
+ cache = {
287
+ type: 'memory'
288
+ };
289
+ }
290
+ // 获取缓存数据
291
+ _context4.next = 6;
292
+ return getCacheData(url, data, cache);
293
+ case 6:
284
294
  _data = _context4.sent;
285
295
  if (!_data) {
286
- _context4.next = 8;
296
+ _context4.next = 10;
287
297
  break;
288
298
  }
289
299
  // 如果开启更新缓存执行函数
290
300
  if ((_config$cache = config.cache) !== null && _config$cache !== void 0 && _config$cache.updateCache) {
291
301
  fn(_objectSpread(_objectSpread({}, props), {}, {
292
302
  config: _objectSpread(_objectSpread({}, props.config), {}, {
293
- cache: _objectSpread(_objectSpread({}, props.config.cache), {}, {
303
+ cache: _objectSpread(_objectSpread({}, cache), {}, {
294
304
  updateCache: false
295
305
  })
296
306
  })
297
307
  }));
298
308
  }
299
309
  return _context4.abrupt("return", _data);
300
- case 8:
310
+ case 10:
301
311
  return _context4.abrupt("return", fn(props));
302
- case 9:
312
+ case 11:
303
313
  case "end":
304
314
  return _context4.stop();
305
315
  }
@@ -128,7 +128,7 @@ export var requestCallback = function requestCallback(resData) {
128
128
  if (codeFn) {
129
129
  if ((res === null || res === void 0 ? void 0 : res.code) === 200) {
130
130
  // 需要缓存的进行缓存数据
131
- if (config !== null && config !== void 0 && config.cache) {
131
+ if (config !== null && config !== void 0 && config.useCache || config !== null && config !== void 0 && config.cache) {
132
132
  var _config$cacheUpdateCh;
133
133
  setCacheData(props.url, props.data, res, config === null || config === void 0 ? void 0 : config.cache);
134
134
  config === null || config === void 0 || (_config$cacheUpdateCh = config.cacheUpdateChange) === null || _config$cacheUpdateCh === void 0 || _config$cacheUpdateCh.call(config, res);
@@ -20,9 +20,9 @@ export declare class RouterManager {
20
20
  get(name: string): RouteType;
21
21
  has(name: string): boolean;
22
22
  remove(name: string): void;
23
- renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): any;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
27
- }): JSX.Element[];
27
+ }): any[];
28
28
  }
@@ -7,7 +7,7 @@ export declare class TasksManager {
7
7
  private app;
8
8
  private db;
9
9
  useTasks: () => {
10
- tasks: TasksModule;
10
+ tasks: any;
11
11
  };
12
12
  watchTaskCallback: (taskModule: TasksModule) => void;
13
13
  private timerIds;
@@ -1,5 +1,4 @@
1
- import { TasksModule } from './type';
2
1
  declare const useTasks: () => {
3
- tasks: TasksModule;
2
+ tasks: any;
4
3
  };
5
4
  export default useTasks;
package/lib/app/app.d.ts CHANGED
@@ -35,7 +35,7 @@ declare class App {
35
35
  locales: Locales;
36
36
  models: {
37
37
  getStore: () => import("../models").Store;
38
- StoreProvider: typeof import("react-redux").Provider;
38
+ StoreProvider: any;
39
39
  setConfig: (models: any[]) => void;
40
40
  };
41
41
  request: {
@@ -170,13 +170,13 @@ var Application = class {
170
170
  * @returns {void}
171
171
  */
172
172
  setComponent(code, component) {
173
- const Component = (...result) => {
173
+ const Component = (props) => {
174
174
  const ref = (0, import_react.useRef)();
175
175
  const Com = component == null ? void 0 : component.Component;
176
176
  return /* @__PURE__ */ import_react.default.createElement(
177
177
  Com,
178
178
  {
179
- ...result,
179
+ ...props,
180
180
  ref: (_ref) => {
181
181
  ref.current = _ref;
182
182
  console.log("组件ref执行了");
@@ -190,7 +190,7 @@ var Application = class {
190
190
  };
191
191
  this.components.set(code, {
192
192
  ...component,
193
- Component
193
+ Component: component.autoRender ? Component : component.Component
194
194
  });
195
195
  }
196
196
  /**
@@ -11,6 +11,6 @@ declare class AWS {
11
11
  private app;
12
12
  private config?;
13
13
  constructor(app: App, options?: AWSOptions);
14
- upload(params: UploadParams): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
14
+ upload(params: UploadParams): Promise<any>;
15
15
  }
16
16
  export default AWS;
@@ -1,14 +1,13 @@
1
1
  import type { History as HistoryType } from "history";
2
- import { useHistory, useLocation, useParams } from "react-router-dom";
3
2
  import App from "../app";
4
3
  export interface HistoryOptions {
5
4
  basename?: string;
6
5
  }
7
6
  export declare class History {
8
- instance: HistoryType<unknown>;
9
- useHistory: typeof useHistory;
10
- useLocation: typeof useLocation;
11
- useParams: typeof useParams;
7
+ instance: any;
8
+ useHistory: any;
9
+ useLocation: any;
10
+ useParams: any;
12
11
  app: App;
13
12
  constructor(app: App, options?: HistoryOptions);
14
13
  push: HistoryType["push"];
@@ -14,4 +14,4 @@ export declare const MenuProvider: React.FC<{
14
14
  children: React.ReactNode;
15
15
  menus: MenuItem[];
16
16
  }>;
17
- export declare const useMenu: () => MenuContextType;
17
+ export declare const useMenu: () => any;
@@ -12,7 +12,7 @@ export declare class MenuManager {
12
12
  private menuItems;
13
13
  private menuMaps;
14
14
  private app;
15
- useMenu: () => import("./hooks").MenuContextType;
15
+ useMenu: () => any;
16
16
  MenuProvider: React.FC<{
17
17
  children: React.ReactNode;
18
18
  menus: MenuItem[];
@@ -1,5 +1,4 @@
1
1
  import hooks from '../hooks';
2
- import { Provider as StoreProvider } from "react-redux";
3
2
  declare const models: import("./global").GlobalModal[];
4
3
  declare type ModalsType = (typeof models[number]);
5
4
  export interface Store {
@@ -39,7 +38,7 @@ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T
39
38
  declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
40
39
  declare const _default: {
41
40
  getStore: () => Store;
42
- StoreProvider: typeof StoreProvider;
41
+ StoreProvider: any;
43
42
  setConfig: (models: any[]) => void;
44
43
  };
45
44
  export default _default;
@@ -28,6 +28,16 @@ declare class PubSub {
28
28
  * @param args 事件参数
29
29
  */
30
30
  publish(event: string, ...args: any[]): void;
31
+ /**
32
+ * @title: 异步发布, 某些事件需要延迟发布
33
+ * @description:
34
+ * @param {string} event
35
+ * @param {number} timeout
36
+ * @param {array} args
37
+ * @return {*}
38
+ * @Author: zhiwei.Wang
39
+ */
40
+ publishDelay(event: string, delay?: number, ...args: any[]): void;
31
41
  /**
32
42
  * 移除某个事件的所有订阅
33
43
  * @param event 事件名称
@@ -74,6 +74,20 @@ var PubSub = class {
74
74
  }
75
75
  });
76
76
  }
77
+ /**
78
+ * @title: 异步发布, 某些事件需要延迟发布
79
+ * @description:
80
+ * @param {string} event
81
+ * @param {number} timeout
82
+ * @param {array} args
83
+ * @return {*}
84
+ * @Author: zhiwei.Wang
85
+ */
86
+ publishDelay(event, delay = 0, ...args) {
87
+ setTimeout(() => {
88
+ this.publish(event, ...args);
89
+ }, delay);
90
+ }
77
91
  /**
78
92
  * 移除某个事件的所有订阅
79
93
  * @param event 事件名称
@@ -32,7 +32,7 @@ export declare const getCacheData: (url: string, data: any, cache: CacheProps) =
32
32
  * @return {*}
33
33
  * @Author: zhiwei.Wang
34
34
  */
35
- export declare const setCacheData: (url: string, data: any, res: any, cache: CacheProps) => any | null;
35
+ export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
36
36
  /**
37
37
  * @title: 缓存函数包装器
38
38
  * @description:
@@ -122,15 +122,23 @@ var getCacheData = async (url, data, cache) => {
122
122
  const res = await getCache(_key, cache);
123
123
  return res;
124
124
  };
125
- var setCacheData = (url, data, res, cache) => {
125
+ var setCacheData = (url, data, res, cache = {
126
+ type: "memory"
127
+ }) => {
126
128
  let _key = createCacheKey(url, data, cache);
127
129
  setCache(_key, res, cache);
128
130
  };
129
131
  var cacheFn = async (props, fn) => {
130
132
  var _a;
131
133
  const { url, data, config } = props;
132
- if (config == null ? void 0 : config.cache) {
133
- let _data = await getCacheData(url, data, config.cache);
134
+ if ((config == null ? void 0 : config.cache) || (config == null ? void 0 : config.useCache)) {
135
+ let cache = config.cache;
136
+ if (config.useCache) {
137
+ cache = {
138
+ type: "memory"
139
+ };
140
+ }
141
+ let _data = await getCacheData(url, data, cache);
134
142
  if (_data) {
135
143
  if ((_a = config.cache) == null ? void 0 : _a.updateCache) {
136
144
  fn({
@@ -138,7 +146,7 @@ var cacheFn = async (props, fn) => {
138
146
  config: {
139
147
  ...props.config,
140
148
  cache: {
141
- ...props.config.cache,
149
+ ...cache,
142
150
  updateCache: false
143
151
  }
144
152
  }
@@ -86,7 +86,7 @@ var requestCallback = (resData) => {
86
86
  const codeFn = requestCallbacks == null ? void 0 : requestCallbacks[res == null ? void 0 : res.code];
87
87
  if (codeFn) {
88
88
  if ((res == null ? void 0 : res.code) === 200) {
89
- if (config == null ? void 0 : config.cache) {
89
+ if ((config == null ? void 0 : config.useCache) || (config == null ? void 0 : config.cache)) {
90
90
  (0, import_cache.setCacheData)(props.url, props.data, res, config == null ? void 0 : config.cache);
91
91
  (_a = config == null ? void 0 : config.cacheUpdateChange) == null ? void 0 : _a.call(config, res);
92
92
  }
@@ -20,9 +20,9 @@ export declare class RouterManager {
20
20
  get(name: string): RouteType;
21
21
  has(name: string): boolean;
22
22
  remove(name: string): void;
23
- renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): any;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
27
- }): JSX.Element[];
27
+ }): any[];
28
28
  }
@@ -7,7 +7,7 @@ export declare class TasksManager {
7
7
  private app;
8
8
  private db;
9
9
  useTasks: () => {
10
- tasks: TasksModule;
10
+ tasks: any;
11
11
  };
12
12
  watchTaskCallback: (taskModule: TasksModule) => void;
13
13
  private timerIds;
@@ -1,5 +1,4 @@
1
- import { TasksModule } from './type';
2
1
  declare const useTasks: () => {
3
- tasks: TasksModule;
2
+ tasks: any;
4
3
  };
5
4
  export default useTasks;
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
+ "scripts": {
5
+ "build": "father build",
6
+ "dev": "father dev",
7
+ "build:types": "tsc --project tsconfig.types.json",
8
+ "publish:types": "npm run build:types && cd types && cp ../types-package.json package.json && npm publish"
9
+ },
4
10
  "sideEffects": false,
5
11
  "main": "./lib/index.js",
6
12
  "module": "./es/index.js",
@@ -38,11 +44,5 @@
38
44
  ],
39
45
  "publishConfig": {
40
46
  "access": "public"
41
- },
42
- "scripts": {
43
- "build": "father build",
44
- "dev": "father dev",
45
- "build:types": "tsc --project tsconfig.types.json",
46
- "publish:types": "npm run build:types && cd types && cp ../types-package.json package.json && npm publish"
47
47
  }
48
48
  }