You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be nice if the helpers intended for use within load/actions and similar functions (such as redirect() and error()) were accessible via the RequestEvent object. This would make it easy for newcomers to see what’s at their disposal by simply inspecting the event object. It would also eliminate the need to import them. Moreover, if the standalone helpers were deprecated, this approach would prevent their usage in wrong places.
So instead of this:
import{redirect}from'@sveltejs/kit';exportconstactions={default: async()=>{// Some logicredirect(303,'/projects');}};
You would do this:
exportconstactions={default: async(event)=>{// Some logicevent.redirect(303,'/projects');}};
But I think the most potential benefit of such a change would be that those helpers would be aware of the context in which they are invoked, which might make it possible in the future to implement a typesafe redirect function that would work with relative paths?
The only downside I can see with such a change, if the standalone helpers were also deprecated, is that it would no longer allow external functions to invoke them without passing the RequestEvent object to them. However, this is something we already have to do to a certain extent with, for example, cookies, so at least it would make for a more consistent way of handling these things.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I think it would be nice if the helpers intended for use within load/actions and similar functions (such as
redirect()
anderror()
) were accessible via theRequestEvent
object. This would make it easy for newcomers to see what’s at their disposal by simply inspecting the event object. It would also eliminate the need to import them. Moreover, if the standalone helpers were deprecated, this approach would prevent their usage in wrong places.So instead of this:
You would do this:
But I think the most potential benefit of such a change would be that those helpers would be aware of the context in which they are invoked, which might make it possible in the future to implement a typesafe redirect function that would work with relative paths?
The only downside I can see with such a change, if the standalone helpers were also deprecated, is that it would no longer allow external functions to invoke them without passing the
RequestEvent
object to them. However, this is something we already have to do to a certain extent with, for example, cookies, so at least it would make for a more consistent way of handling these things.Beta Was this translation helpful? Give feedback.
All reactions