From d14d2d6aa1cdc50ff084f801fa741221667ee577 Mon Sep 17 00:00:00 2001 From: Yiyu He Date: Fri, 10 Nov 2017 05:08:48 -0600 Subject: [PATCH] fix: rename to createJsonpBody (#9) --- app/extend/application.js | 4 ++-- app/extend/context.js | 11 ++++++----- lib/private_key.js | 1 - test/fixtures/jsonp-test/app/router.js | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/extend/application.js b/app/extend/application.js index df0ec69..e2109e5 100644 --- a/app/extend/application.js +++ b/app/extend/application.js @@ -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 = { /** @@ -64,7 +64,7 @@ module.exports = { yield next; // generate jsonp body - this[JSONP_WRAPPER](this.body); + this.createJsonpBody(this.body); }; }, }; diff --git a/app/extend/context.js b/app/extend/context.js index aaa1154..87458ac 100644 --- a/app/extend/context.js +++ b/app/extend/context.js @@ -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 = { /** @@ -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; diff --git a/lib/private_key.js b/lib/private_key.js index c56687a..9580f00 100644 --- a/lib/private_key.js +++ b/lib/private_key.js @@ -1,4 +1,3 @@ 'use strict'; exports.JSONP_CONFIG = Symbol('jsonp#config'); -exports.JSONP_WRAPPER = Symbol.for('jsonp#wrapper'); diff --git a/test/fixtures/jsonp-test/app/router.js b/test/fixtures/jsonp-test/app/router.js index 8dbe57a..765e6ab 100644 --- a/test/fixtures/jsonp-test/app/router.js +++ b/test/fixtures/jsonp-test/app/router.js @@ -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'); };