Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(widget): widget v2 #4789

Draft
wants to merge 34 commits into
base: squad-core-into-widget
Choose a base branch
from
Draft

feat(widget): widget v2 #4789

wants to merge 34 commits into from

Conversation

Rathoz
Copy link
Collaborator

@Rathoz Rathoz commented Sep 23, 2024

Summary

Widget v2 contain two main changes.

  1. Structural change to the Widgets are made
  2. Replacement of Customizables & Injectors with Contexts

Thanks to these changes in combination, the Inversion of Control becomes a lot better.

Contexts

Add support for the provider pattern, similiar to that of react in our Widgets. Contexts allow for a clearer hierarchy, and smooth implementations. Contexts allows for any data, allowing for, for instance, more specific data. One could make a context that implements just the content of the role cell on Infobox Person instead of having to do the entire cell, as an example instance, allowing for better fine-tuned control, and less broad overrides. Additionally it doesn't have the implementation overhead with injectors that more complex Widgets ran into.

Widget changes

The biggest changes:

  • uses render() instead of make(children) and makeChildren(injector)
  • all parameters goes into a prop field, handled automatically from the Widget Base (Module:Widget)
  • Support for what to render if there's an error, such as wrapper (:getDerivedStateFromError())
  • Backwards compatibility with WidgetV1 through legacy handling

The impact and flexibility thanks to these changes makes a huge difference, especially the first one. The second one make the boilerplate needed to create a widget a lot smaller.

Squad

The PR also replaces the Squad feature to Widget v2

Code

This is how a wiki-custom for Squad render can look like

return SquadContext.RoleName{value = 'Position', children = {
  SquadTable{
    title = 'My Title',
    type = SquadType.ACTIVE,
    children = {
      --
    },
}

Future

Not super pleased with the context's default handling, but it works for now. The way it works here makes it very simple to convert existing customizables. Maybe for later

How did you test this change?

dev and busted

Copy link
Collaborator

@hjpalpha hjpalpha left a comment

Choose a reason for hiding this comment

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

still some failed tests ;)

generally okay imo

components/widget/contexts/widget_contexts_squad.lua Outdated Show resolved Hide resolved
@Rathoz
Copy link
Collaborator Author

Rathoz commented Sep 24, 2024

still some failed tests ;)

generally okay imo

The failed goldens are just a change from inline styling to css

@Rathoz Rathoz changed the title refactor(widget): replace customizable with contexts refactor(widget): widget v2 Sep 24, 2024
@Rathoz Rathoz changed the title refactor(widget): widget v2 feat(widget): widget v2 Sep 24, 2024
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.

2 participants