jj.js 1.0.0-rc.3 → 1.0.0-rc.5

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
@@ -26,9 +26,10 @@ class Middleware extends Context
26
26
  * 直接输出内容
27
27
  * @public
28
28
  * @param {*} data
29
+ * @returns {'__EXIT__'}
29
30
  */
30
31
  $show(data) {
31
- this._$response.show(data);
32
+ return this._$response.show(data);
32
33
  }
33
34
 
34
35
  /**
@@ -36,9 +37,10 @@ class Middleware extends Context
36
37
  * @public
37
38
  * @param {(string|object)} url
38
39
  * @param {number} [status]
40
+ * @returns {'__EXIT__'}
39
41
  */
40
42
  $redirect(url, status) {
41
- this._$response.redirect(url, status);
43
+ return this._$response.redirect(url, status);
42
44
  }
43
45
 
44
46
  /**
@@ -46,9 +48,10 @@ class Middleware extends Context
46
48
  * @public
47
49
  * @param {(string|object)} [msg]
48
50
  * @param {(string|object)} [url]
51
+ * @returns {'__EXIT__'}
49
52
  */
50
53
  $success(msg, url) {
51
- this._$response.success(msg, url);
54
+ return this._$response.success(msg, url);
52
55
  }
53
56
 
54
57
  /**
@@ -56,9 +59,10 @@ class Middleware extends Context
56
59
  * @public
57
60
  * @param {(string|object)} [msg]
58
61
  * @param {(string|object)} [url]
62
+ * @returns {'__EXIT__'}
59
63
  */
60
64
  $error(msg, url) {
61
- this._$response.error(msg, url);
65
+ return this._$response.error(msg, url);
62
66
  }
63
67
 
64
68
  /**
package/lib/response.js CHANGED
@@ -29,9 +29,11 @@ class Response extends Context
29
29
  * 直接输出内容
30
30
  * @public
31
31
  * @param {*} data
32
+ * @returns {'__EXIT__'}
32
33
  */
33
34
  show(data) {
34
35
  this.ctx.body = data;
36
+ return '__EXIT__';
35
37
  }
36
38
 
37
39
  /**
@@ -39,10 +41,12 @@ class Response extends Context
39
41
  * @public
40
42
  * @param {*} url
41
43
  * @param {number} status
44
+ * @returns {'__EXIT__'}
42
45
  */
43
46
  redirect(url, status=302) {
44
47
  this.ctx.status = status;
45
48
  this.ctx.redirect(this._$url.build(url));
49
+ return '__EXIT__';
46
50
  }
47
51
 
48
52
  /**
@@ -50,11 +54,12 @@ class Response extends Context
50
54
  * @public
51
55
  * @param {(string|object)} [msg]
52
56
  * @param {(string|object)} [url]
57
+ * @returns {'__EXIT__'}
53
58
  */
54
59
  success(msg='操作成功!', url) {
55
60
  typeof msg == 'object' && ([msg, url] = ['操作成功!', msg]);
56
61
  url = typeof url == 'string' ? this._$url.build(url) : (url || this.ctx.header.referer || '');
57
- this.jump(msg, url, 1);
62
+ return this.jump(msg, url, 1);
58
63
  }
59
64
 
60
65
  /**
@@ -62,11 +67,12 @@ class Response extends Context
62
67
  * @public
63
68
  * @param {(string|object)} [msg]
64
69
  * @param {(string|object)} [url]
70
+ * @returns {'__EXIT__'}
65
71
  */
66
72
  error(msg='操作失败!', url) {
67
73
  typeof msg == 'object' && ([msg, url] = ['操作失败!', msg]);
68
74
  url = typeof url == 'string' ? this._$url.build(url) : (url || 'javascript:history.back(-1);');
69
- this.jump(msg, url, 0);
75
+ return this.jump(msg, url, 0);
70
76
  }
71
77
 
72
78
  /**
@@ -75,6 +81,7 @@ class Response extends Context
75
81
  * @param {(string|object)} msg
76
82
  * @param {(string|object)} url
77
83
  * @param {number} state
84
+ * @returns {'__EXIT__'}
78
85
  */
79
86
  jump(msg, url, state=1) {
80
87
  const tplData = {state, msg, url, wait: this._wait};
@@ -82,6 +89,7 @@ class Response extends Context
82
89
  // @ts-ignore
83
90
  return tplData[args[1]];
84
91
  });
92
+ return '__EXIT__';
85
93
  }
86
94
 
87
95
  /**
@@ -99,6 +107,7 @@ class Response extends Context
99
107
  * 输出异常信息(html|json)
100
108
  * @public
101
109
  * @param {Error} err
110
+ * @returns {'__EXIT__'}
102
111
  */
103
112
  exception(err) {
104
113
  const escapeHtml = require('./utils/escape-html');
@@ -112,6 +121,7 @@ class Response extends Context
112
121
  // @ts-ignore
113
122
  return tplData[args[1]];
114
123
  });
124
+ return '__EXIT__';
115
125
  }
116
126
 
117
127
  /**
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "jj.js",
3
- "version": "1.0.0-rc.3",
3
+ "version": "1.0.0-rc.5",
4
4
  "description": "A super simple lightweight NodeJS MVC framework(一个超级简单轻量的NodeJS MVC框架)",
5
5
  "main": "jj.js",
6
6
  "bin": {
7
- "init": "./bin/jj.js"
7
+ "jj-cli": "./bin/jj.js"
8
8
  },
9
9
  "scripts": {
10
10
  "demo": "node ./tests/_demo/server.js",