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

Switch Angular for XState #45

Closed
sync-by-unito bot opened this issue Mar 8, 2021 · 1 comment · Fixed by #105
Closed

Switch Angular for XState #45

sync-by-unito bot opened this issue Mar 8, 2021 · 1 comment · Fixed by #105
Assignees
Labels
low priority This issue has low priority package:demo Scope limited to demo package

Comments

@sync-by-unito
Copy link

sync-by-unito bot commented Mar 8, 2021

Goodbye Angular! We will make an XState & LitElement version of the demo app.

This issue will be very similar to the switch from platform-public to ui-transfer, so definitely take a look at the demo machine and demo (root) component there, and how all the XState parts match with the Angular app in platform-public. In short, the following guidelines can be followed.

  • The Angular component itself (script, html & css together) becomes an (Rx)LitElement that
    • creates and interprets a machine,
    • subscribes to the interpreted machine (state) and its necessary context,
    • uses this context to render a LitElement template (based on the home component's html),
    • listens to HTML Events of the (sub)components in the template, and
    • translates them to XState events to the machine.
  • The Angular state becomes the context of the machine, with
    • the initial state being set in the component when it creates the machine, and
    • the reducers being translated to XState assign actions.
  • The Angular actions become XState events, which consist of
    • an enumeration of their labels,
    • classes which define their payload, and
    • a union type of those classes.
  • The Angular effects remain functions, called services, which
    • are almost the same code, starting after their current Angular ofType operator,
    • take an XState context and event as input, and
    • end with a map to an XState event for the machine.
  • The real creativity lies in defining the XState states of the machine:
    • Define an enumeration of states ("toestanden", "situaties") the machine can be in.
    • Make a union type of objects for every state, in which you restrict the context in those states, for example by making some optional properties mandatory. For this you can add interfaces that extend the context.
    • Add a boilerplate XState state schema, just because we sometimes need it.
  • Finally, create a machine configuration, with for every state:
    • an invoke block with a service function as src, if needed, and
    • an on block with a target and optional actions for certain events.

NOTE: The SemCom demo contains an app component and a home component. The app component only really adds the authentication, so we mostly need to translate the home component as main demo component. The authentication part can then be added to the new demo component and machine using the ui-transfer parts exactly like in the ui-tranfer demo.

When in doubt, always look back to the ui-tranfer demo, and don't hesitate to ask for help.

┆Issue is synchronized with this Wrike Task by Unito

@woutermont woutermont added package:demo Scope limited to demo package low priority This issue has low priority labels Apr 30, 2021
@woutermont woutermont changed the title Switch AngularDI for ComponentsJS Switch Angular for XState May 7, 2021
@woutermont woutermont self-assigned this May 8, 2021
@arnevandoorslaer arnevandoorslaer linked a pull request Jun 22, 2021 that will close this issue
@woutermont
Copy link
Contributor

Nice work!

@sync-by-unito sync-by-unito bot reopened this Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority This issue has low priority package:demo Scope limited to demo package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants