koa-flash icon indicating copy to clipboard operation
koa-flash copied to clipboard

Should we Object.seal(this.flash)?

Open bitinn opened this issue 9 years ago • 2 comments

Just found out doing this.flash.somekey = somevalue can result in some hard to debug problems :)

Instead of handling this edge case though, maybe we should just seal this.flash instead?

Note: Object.seal doesn't cause this.flash.somekey = somevalue to throw any error, it's silently ignored, at least in my test somekey does not appear in Object.keys(this.flash) output.

Alternatively, we could just update the doc to explicit tell users don't do that :)

bitinn avatar Apr 10 '15 09:04 bitinn

Could you give an example of what you were doing and how it was affecting your expected output? Ideally, you should be able to modify the flash object in any way that you want so you can use it on a subsequent request.

rickharrison avatar Apr 10 '15 21:04 rickharrison

The example:

this.flash.somekey = 'somevalue';
this.flash = { somekey: 'othervalue' };

Now since somekey is a property on the flash object, it means this.flash.somekey will return somevalue not othervalue, and it won't be deleted because it's not in the session, but on the object itself.

bitinn avatar Apr 11 '15 04:04 bitinn