jj.js 1.0.0-rc.4 → 1.0.0-rc.6

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/lib/controller.js CHANGED
@@ -50,30 +50,33 @@ class Controller extends Middleware
50
50
  * 获取文件内容并输出
51
51
  * @public
52
52
  * @param {string} [template]
53
+ * @returns {Promise<'__EXIT__'>}
53
54
  */
54
55
  async $load(template) {
55
56
  const content = await this._$view.load(template);
56
- this.$show(content);
57
+ return this.$show(content);
57
58
  }
58
59
 
59
60
  /**
60
61
  * 渲染(解析数据)内容并输出
61
62
  * @public
62
63
  * @param {string} content
64
+ * @returns {Promise<'__EXIT__'>}
63
65
  */
64
66
  async $render(content) {
65
67
  const html = await this._$view.render(content);
66
- this.$show(html);
68
+ return this.$show(html);
67
69
  }
68
70
 
69
71
  /**
70
72
  * 渲染(解析数据)文件并输出
71
73
  * @public
72
74
  * @param {string} [template]
75
+ * @returns {Promise<'__EXIT__'>}
73
76
  */
74
77
  async $fetch(template) {
75
78
  const content = await this._$view.fetch(template);
76
- this.$show(content);
79
+ return this.$show(content);
77
80
  }
78
81
 
79
82
  /**
package/lib/middleware.js CHANGED
@@ -11,6 +11,12 @@ const Context = require('./context');
11
11
  */
12
12
  class Middleware extends Context
13
13
  {
14
+ /**
15
+ * 控制器_init方法或action方法返回此值,表示不继续执行后续方法
16
+ * @type {'__EXIT__'}
17
+ */
18
+ __EXIT__ = '__EXIT__';
19
+
14
20
  /**
15
21
  * Initialize a new `Middleware`
16
22
  * @public
@@ -26,9 +32,10 @@ class Middleware extends Context
26
32
  * 直接输出内容
27
33
  * @public
28
34
  * @param {*} data
35
+ * @returns {'__EXIT__'}
29
36
  */
30
37
  $show(data) {
31
- this._$response.show(data);
38
+ return this._$response.show(data);
32
39
  }
33
40
 
34
41
  /**
@@ -36,9 +43,10 @@ class Middleware extends Context
36
43
  * @public
37
44
  * @param {(string|object)} url
38
45
  * @param {number} [status]
46
+ * @returns {'__EXIT__'}
39
47
  */
40
48
  $redirect(url, status) {
41
- this._$response.redirect(url, status);
49
+ return this._$response.redirect(url, status);
42
50
  }
43
51
 
44
52
  /**
@@ -46,9 +54,10 @@ class Middleware extends Context
46
54
  * @public
47
55
  * @param {(string|object)} [msg]
48
56
  * @param {(string|object)} [url]
57
+ * @returns {'__EXIT__'}
49
58
  */
50
59
  $success(msg, url) {
51
- this._$response.success(msg, url);
60
+ return this._$response.success(msg, url);
52
61
  }
53
62
 
54
63
  /**
@@ -56,9 +65,10 @@ class Middleware extends Context
56
65
  * @public
57
66
  * @param {(string|object)} [msg]
58
67
  * @param {(string|object)} [url]
68
+ * @returns {'__EXIT__'}
59
69
  */
60
70
  $error(msg, url) {
61
- this._$response.error(msg, url);
71
+ return this._$response.error(msg, url);
62
72
  }
63
73
 
64
74
  /**
package/lib/response.js CHANGED
@@ -13,6 +13,12 @@ const Context = require('./context');
13
13
  */
14
14
  class Response extends Context
15
15
  {
16
+ /**
17
+ * 控制器_init方法或action方法返回此值,表示不继续执行后续方法
18
+ * @type {'__EXIT__'}
19
+ */
20
+ __EXIT__ = '__EXIT__';
21
+
16
22
  /**
17
23
  * Initialize a new `Response`
18
24
  * @public
@@ -29,9 +35,11 @@ class Response extends Context
29
35
  * 直接输出内容
30
36
  * @public
31
37
  * @param {*} data
38
+ * @returns {'__EXIT__'}
32
39
  */
33
40
  show(data) {
34
41
  this.ctx.body = data;
42
+ return this.__EXIT__;
35
43
  }
36
44
 
37
45
  /**
@@ -39,10 +47,12 @@ class Response extends Context
39
47
  * @public
40
48
  * @param {*} url
41
49
  * @param {number} status
50
+ * @returns {'__EXIT__'}
42
51
  */
43
52
  redirect(url, status=302) {
44
53
  this.ctx.status = status;
45
54
  this.ctx.redirect(this._$url.build(url));
55
+ return this.__EXIT__;
46
56
  }
47
57
 
48
58
  /**
@@ -50,11 +60,12 @@ class Response extends Context
50
60
  * @public
51
61
  * @param {(string|object)} [msg]
52
62
  * @param {(string|object)} [url]
63
+ * @returns {'__EXIT__'}
53
64
  */
54
65
  success(msg='操作成功!', url) {
55
66
  typeof msg == 'object' && ([msg, url] = ['操作成功!', msg]);
56
67
  url = typeof url == 'string' ? this._$url.build(url) : (url || this.ctx.header.referer || '');
57
- this.jump(msg, url, 1);
68
+ return this.jump(msg, url, 1);
58
69
  }
59
70
 
60
71
  /**
@@ -62,11 +73,12 @@ class Response extends Context
62
73
  * @public
63
74
  * @param {(string|object)} [msg]
64
75
  * @param {(string|object)} [url]
76
+ * @returns {'__EXIT__'}
65
77
  */
66
78
  error(msg='操作失败!', url) {
67
79
  typeof msg == 'object' && ([msg, url] = ['操作失败!', msg]);
68
80
  url = typeof url == 'string' ? this._$url.build(url) : (url || 'javascript:history.back(-1);');
69
- this.jump(msg, url, 0);
81
+ return this.jump(msg, url, 0);
70
82
  }
71
83
 
72
84
  /**
@@ -75,6 +87,7 @@ class Response extends Context
75
87
  * @param {(string|object)} msg
76
88
  * @param {(string|object)} url
77
89
  * @param {number} state
90
+ * @returns {'__EXIT__'}
78
91
  */
79
92
  jump(msg, url, state=1) {
80
93
  const tplData = {state, msg, url, wait: this._wait};
@@ -82,6 +95,7 @@ class Response extends Context
82
95
  // @ts-ignore
83
96
  return tplData[args[1]];
84
97
  });
98
+ return this.__EXIT__;
85
99
  }
86
100
 
87
101
  /**
@@ -99,6 +113,7 @@ class Response extends Context
99
113
  * 输出异常信息(html|json)
100
114
  * @public
101
115
  * @param {Error} err
116
+ * @returns {'__EXIT__'}
102
117
  */
103
118
  exception(err) {
104
119
  const escapeHtml = require('./utils/escape-html');
@@ -112,6 +127,7 @@ class Response extends Context
112
127
  // @ts-ignore
113
128
  return tplData[args[1]];
114
129
  });
130
+ return this.__EXIT__;
115
131
  }
116
132
 
117
133
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jj.js",
3
- "version": "1.0.0-rc.4",
3
+ "version": "1.0.0-rc.6",
4
4
  "description": "A super simple lightweight NodeJS MVC framework(一个超级简单轻量的NodeJS MVC框架)",
5
5
  "main": "jj.js",
6
6
  "bin": {