routify icon indicating copy to clipboard operation
routify copied to clipboard

Support for Promise in beforeUrlChange

Open www-chique opened this issue 2 years ago • 4 comments

I would love to have support for Promise in $beforeUrlChange.

Currently, in a "form", I look if the form has some changes, and if yes, I show a dialog which returns a promise, that resolves after user's choice of whether to discard the change. It's pretty neat to wait for that response before I can return the $beforeUrlChange a "true" or "false".

Surprisingly, I am already using an asynchronous function there, but it pops out an incorrect type warning. I am not sure whether it's merely a fix for the types or actually needs to support in the codebase.

image

I am happy to provide more details as needed.

www-chique avatar Jan 08 '22 01:01 www-chique

I thought this was already supported.

Are you using R2 or R3?

jakobrosenberg avatar Jan 09 '22 18:01 jakobrosenberg

I am with R2, version 2.15.1. If you ignore VSCode complaining about the type error, it actually works just fine.

-- Here is a sidenote: Routify is amazingly awesome. Thanks to you, Ghost and everyone else involved in the community for active support and amazing ideas.

www-chique avatar Jan 09 '22 22:01 www-chique

Can be fixed in this line I imagine @jakobrosenberg - https://github.com/roxiness/routify/blob/0a7eff304e781ecf30c686312fd765fdb90466db/typings/runtime/helpers.d.ts#L86

If this is valid jsdoc then it's as simple as:

(event?: PopStateEvent, route?: ClientNodeApi) => boolean} to (event?: PopStateEvent, route?: ClientNodeApi) => boolean | Promise<boolean>}

ghostdevv avatar Jan 13 '22 20:01 ghostdevv

I have found the issue behind this. The types are automatically generated on build, but the type for beforeUrlChange was added manually in the generated definition file.

I'll try to sort this when I get home.

jakobrosenberg avatar Jan 15 '22 21:01 jakobrosenberg