Skip to content

Commit

Permalink
fix: rename to createJsonpBody (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored Nov 10, 2017
1 parent f7137a0 commit d14d2d6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/extend/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const is = require('is-type-of');
const url = require('url');
const { JSONP_CONFIG, JSONP_WRAPPER } = require('../../lib/private_key');
const { JSONP_CONFIG } = require('../../lib/private_key');

module.exports = {
/**
Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = {
yield next;

// generate jsonp body
this[JSONP_WRAPPER](this.body);
this.createJsonpBody(this.body);
};
},
};
Expand Down
11 changes: 6 additions & 5 deletions app/extend/context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const jsonpBody = require('jsonp-body');
const { JSONP_CONFIG, JSONP_WRAPPER } = require('../../lib/private_key');
const { JSONP_CONFIG } = require('../../lib/private_key');

module.exports = {
/**
Expand All @@ -12,12 +12,13 @@ module.exports = {
},

/**
* jsonp wrap body function
* set jsonp response wrap function, other plugin can use it.
* JSONP wrap body function
* Set jsonp response wrap function, other plugin can use it.
* If not necessary, please don't use this method in your application code.
* @param {Object} body respones body
* @public
* @private
*/
[JSONP_WRAPPER](body) {
createJsonpBody(body) {
const jsonpConfig = this[JSONP_CONFIG];
if (!jsonpConfig || !jsonpConfig.jsonpFunction) {
this.body = body;
Expand Down
1 change: 0 additions & 1 deletion lib/private_key.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

exports.JSONP_CONFIG = Symbol('jsonp#config');
exports.JSONP_WRAPPER = Symbol.for('jsonp#wrapper');
2 changes: 1 addition & 1 deletion test/fixtures/jsonp-test/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = app => {
try {
yield next;
} catch (error) {
this[Symbol.for('jsonp#wrapper')]({ msg: error.message });
this.createJsonpBody({ msg: error.message });
}
}, app.jsonp(), 'jsonp.error');
};

0 comments on commit d14d2d6

Please sign in to comment.