NullVoxPopuli / NullVoxPopuli/ember-statechart-component

How to work with "state"?

Open
#522 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

external bug
Dominant language
TypeScript
Stars
39
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Hi,

I can see that for xstate matches there is a shorthand in ember-statechart-component:

<Toggle as |toggle|>
  (toggle.matches 'inactive')
</Toggle>

From the official xstate documentation it seems like it should also work in this way:

<!-- This does not work -->
<Toggle as |toggle|>
  (toggle.snapshot.matches 'inactive')
</Toggle>

But this does not work with:

Uncaught TypeError: Cannot read properties of undefined (reading 'value')

And respective this(?) is there set to undefined:

Screenshot 2024-12-22 at 17 33 54
(screenshot tests step1, but it's supposed to be inactive in the example above)

I came to this conclusion from an ability to access context on snapshot which works for me:

<Toggle as |toggle|>
  {{toggle.snapshot.context.isActive}}
</Toggle>

I do not necessarily care about how do I call state.matches as there is a way, but I wanted to access state.can and possibly other functions, but it does not work for me.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two Handlebars examples in issue #522, comparing the working toggle.matches call with toggle.snapshot.matches and the reported undefined-value error. Check the ember-statechart-component API against the linked XState matches, context, and can documentation; done means the intended state methods are either accessible through the yielded value or the supported usage is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.