koa-flash
koa-flash copied to clipboard
Should we Object.seal(this.flash)?
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 :)
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.
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.