ziggy icon indicating copy to clipboard operation
ziggy copied to clipboard

feat: Add resolve() method

Open Tofandel opened this issue 3 years ago • 2 comments

Follow up of #514 to make API consistent

This is rebased on #514 so for a real diff see https://github.com/Tofandel/ziggy/pull/1/files

Tofandel avatar Mar 01 '22 00:03 Tofandel

Is there a particular use case you have for this? The code looks fine but I'm not sure it's necessary, the new resolve() method basically just does exactly what toString() does now, right?

bakerkretzmar avatar Mar 04 '22 20:03 bakerkretzmar

It's to make the api consistent, I had some problems with the fact route().params currently doesn't give query params separately, so I fixed that in unresolve which returns an object of the form {name, query, params, route}, that the resolve method could take back in without having to go through object transformations and inner workings methods, the goal is to have a reversible transformation

You'll notice this is also the same api as vue router :to="{name, params, query}" and that's because I made a plugin to make inertia.js +ziggy a drop In vue router replacement so that it works with the whole vue ecosystem and I use this method instead because it provides a direct interface

Use case, which isn't possible to make without the resolve api, is to be able to just pass it params and have the current url returned with only the params passed (see last tests to understand) so basically this allows optional params

Tofandel avatar Mar 05 '22 10:03 Tofandel