Synphonyte / leptos-struct-table

Easily create Leptos table components from structs
Apache License 2.0
164 stars 24 forks source link

Make the derive macro less magic and let implentors of CellValue act on a RenderOptions #29

Closed lukashermansson closed 6 months ago

lukashermansson commented 6 months ago

This in conjunction with the changes in https://github.com/Synphonyte/leptos-struct-table-macro/pull/6 attempts to remove the chrono magic built into the macro and instead gets formatting options to the CellValue trait.

This should if merged, allow time integration without any macro magic. It also allows implementors of CellValue to act on the RenderOptions collected from the macro.

Feels like this pr could still use some polish, but I wanted to get a draft out pretty early as it might make sense to (in case you like the idea) get this out before we cut a new release.

maccesch commented 6 months ago

Man, you're on a roll! This is really nice.

I was thinking if it would be possible to make the format options an associated type of the CellValue trait.

trait CellValue {
    type RenderOptions: Default = ();

    fn render_value(self, options: &Self::RenderOptions) -> impl IntoView;
}

Then in the maco with some more advanced parsing we translate

#[table(format(foo = "%m.%d.%Y", bar = 3))]

to

CellRenderer::RenderOptions {
    foo: "%m.%d.%Y",
    bar: 3,
}

What do you think? Am I going too far here? 😄

lukashermansson commented 6 months ago

Man, you're on a roll! This is really nice.

I was thinking if it would be possible to make the format options an associated type of the CellValue trait.

trait CellValue {
    type RenderOptions: Default = ();

    fn render_value(self, options: &Self::RenderOptions) -> impl IntoView;
}

Then in the maco with some more advanced parsing we translate

#[table(format(foo = "%m.%d.%Y", bar = 3))]

to

CellRenderer::RenderOptions {
    foo: "%m.%d.%Y",
    bar: 3,
}

What do you think? Am I going too far here? 😄

I love the ideas provided here, I will make an attempt at that behaviour. It will probably have to have a restriction that the type provided as the RenderOptions is a struct with named public fields (as the macro would have to make some assumptions about this)

I will try it out and if i can get it to work nicely I will push what I can come up with. Thanks for the feedback and the nice ideas.

maccesch commented 6 months ago

This has me excited! Thanks so much!

I should be able to find some time tomorrow and make a new release.