slovnicki / beamer

A routing package built on top of Router and Navigator's pages API, supporting arbitrary nested navigation, guards and more.
MIT License
591 stars 129 forks source link

[Help / Improvement] Data object inside Beam Location #604

Open FrBernad opened 1 year ago

FrBernad commented 1 year ago

What's the equivalent of the data parameter for a Location Builder using a Beam Location?

The RoutersLocationBuilder receives a data parameter, but It's not the case with the buildPages of a locationBuilder.

Reading the source code I find out that the data object is added as property to the currentLocation, but that is after the build pages method is called, so there is not way of accessing that instance of the data object in the buildPages method.

Accessing the current data object inside the build pages method should be a thing right?

slovnicki commented 1 year ago

Hey @FrBernad :wave: Thanks for creating an issue and sorry for my absence lately.

Indeed, data is a public property of BeamLocation so it can be accessed freely. Fun fact; so is the state, but it was added as a parameter to buildPages out of convenience, because it is literary always used. I was thinking of adding data too...

data should be set before buildPages is called :thinking: It is set in the update (the function that all the beamTo* functions call) and buildPages is called during build, which is triggered at the end of update.

Do you have a small example that demonstrates how data is not available during buildPages?