Skip to content

Enable modifiers to be reified#234

Draft
armanbilge wants to merge 1 commit intomainfrom
pr/i207
Draft

Enable modifiers to be reified#234
armanbilge wants to merge 1 commit intomainfrom
pr/i207

Conversation

@armanbilge
Copy link
Owner

Closes #207.

This PR introduces Mod[IO, Elem] which reifies modifier, as well as a .toMod syntax.

This would make it possible to write:

def MyComponent(mod: Mod[IO, HtmlElement[IO]]) = 
  div(
    cls := "decoration",
    mod
  )

instead of

def MyComponent[M](mod: M)(using Modifier[IO, HtmlElement[IO], M]) = 
  div(
    cls := "decoration",
    mod
  )

and generally make it easier to pass modifiers around.

I'm not entirely sold on this yet, since it moves in the direction that Modifier should not be a typeclass, which in turn was motivated so that a .toMod extension wouldn't be needed for stuff like String or HtmlElement. But if we're going to do that anyway, then maybe we should change the encoding.

h/t @kubukoz, cc @yurique

Co-authored-by: =?UTF-8?q?Jakub=20Koz=C5=82owski?= <kubukoz@gmail.com>
/**
* A reified modifier
*/
trait Mod[F[_], E]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make E a type member and point it to Node[F]?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not, esp. if I go forward with proposed changes in #180 so that modifiers can only be applied to elements/nodes on which they are valid. Right now it's a bit wild west.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should Modifier be a typeclass?

2 participants