Removed `req.flash()` references
Before adoption: this commit came in with the history the project adopted, so no landing records it.
it will be req.notify(), req.session.notifications etc
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 3a04888 · Browse files · 2 files·+32 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+32 added−33 removed
- tests:+19 added−19 removed
- other:+13 added−14 removed
Provenance
- Commit
3ab3702- Tree
1b50bea- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
3a04888
2 files changed+32 added−33 removed
modified:lib/request.js+13 added-14 removed
13 unmodified lines14 , utils = require('./utils')15 , mime = require('mime');16 17 /**18- * Default flash formatters.18+ * Default notification formatters.19 */20 21 var defaultFormatters = exports.formatters = {22 s: function(val){23 return String(val);24 },25- 25 d: function(val){26 return val | 0;27 }28 };156 unmodified lines185 *186 * Examples:187 *188 * req.notify('info', 'email sent');190- * req.flash('info', 'email sent');191- * req.flash('error', 'email delivery failed');192- * req.flash('info', 'email re-sent');189+ * req.notify('info', 'email sent');190+ * req.notify('error', 'email delivery failed');191+ * req.notify('info', 'email re-sent');192 * // => 2193 *195- * req.flash('info');194+ * req.notify('info');195 * // => ['email sent', 'email re-sent']196 *198- * req.flash('info');197+ * req.notify('info');198 * // => []199 *201- * req.flash();200+ * req.notify();201 * // => { error: ['email delivery failed'], info: [] }202 *203 * Formatting:204 *205 * Flash notifications also support arbitrary formatting support.207- * For example you may pass variable arguments to `req.flash()`206+ * For example you may pass variable arguments to `req.notify()`207 * and use the %s specifier to be replaced by the associated argument:208 *210- * req.flash('info', 'email has been sent to %s.', userName);209+ * req.notify('info', 'email has been sent to %s.', userName);210 *211 * You may add addition formatters by defining `app.formatters`,212 * for example in the following snippet we define `%u` to uppercase213 * a string:9 unmodified lines223 * @return {Array|Object|Number}224 * @api public225 */226 228-req.flash = 227 req.notify = function(type, msg){230- if (this.session === undefined) throw Error('req.flash() requires sessions');231- var msgs = this.session.flash = this.session.flash || {};228+ var sess = this.session;229+ if (null == sess) throw Error('req.notify() requires sessions');230+ var msgs = sess.notifications = sess.notifications || {};231 232 // notification233 if (type && msg) {234 var i = 215 unmodified lines250 return arr || [];251 }252 253 // flush all messages255- this.session.flash = {};254+ sess.notifications = {};255 return msgs;256 };257 258 /**77 unmodified linesmodified:test/request.test.js+19 added-19 removed
126 unmodified lines127 { url: '/user', method: 'POST', data: 'id=1', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }},128 { body: 'user 1' });129 },130 131- 'test #flash()': function(){131+ 'test #notify()': function(){132 var app = express.createServer(133 connect.cookieParser()134 , connect.session({ secret: 'something' })135 );5 unmodified lines141 };142 143 app.get('/', function(req, res){144 req.notify('info').should.be.empty;145- req.flash('error').should.be.empty;146- req.flash().should.eql({});147- req.session.flash.should.eql({});145+ req.notify('error').should.be.empty;146+ req.notify().should.eql({});147+ req.session.notifications.should.eql({});148 149- req.flash('info', 'one').should.equal(1);150- req.flash('info', 'two').should.equal(2);151- req.flash('info').should.eql(['one', 'two']);152- req.flash('info').should.eql([]);149+ req.notify('info', 'one').should.equal(1);150+ req.notify('info', 'two').should.equal(2);151+ req.notify('info').should.eql(['one', 'two']);152+ req.notify('info').should.eql([]);153 154- req.flash('info', 'one').should.equal(1);155- req.flash('info').should.eql(['one']);154+ req.notify('info', 'one').should.equal(1);155+ req.notify('info').should.eql(['one']);156 157- req.flash('info', 'Email _sent_.');158- req.flash('info', '<script>');159- req.flash('info').should.eql(['Email <em>sent</em>.', '<script>']);157+ req.notify('info', 'Email _sent_.');158+ req.notify('info', '<script>');159+ req.notify('info').should.eql(['Email <em>sent</em>.', '<script>']);160 161- req.flash('info', 'Welcome _%s_ to %s', 'TJ', 'something');162- req.flash('info').should.eql(['Welcome <em>TJ</em> to something']);161+ req.notify('info', 'Welcome _%s_ to %s', 'TJ', 'something');162+ req.notify('info').should.eql(['Welcome <em>TJ</em> to something']);163 164- req.flash('info', 'TJ has %d pets', 5.12323);165- req.flash('info').should.eql(['TJ has 5 pets']);164+ req.notify('info', 'TJ has %d pets', 5.12323);165+ req.notify('info').should.eql(['TJ has 5 pets']);166 167- req.flash('error', 'Foo %u', 'bar');168- req.flash('error').should.eql(['Foo BAR']);167+ req.notify('error', 'Foo %u', 'bar');168+ req.notify('error').should.eql(['Foo BAR']);169 170 res.send('ok');171 });172 169 unmodified lines