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

Crushing because of null assignment to context value #65

Open
nixtaxe opened this issue May 2, 2020 · 1 comment
Open

Crushing because of null assignment to context value #65

nixtaxe opened this issue May 2, 2020 · 1 comment

Comments

@nixtaxe
Copy link

nixtaxe commented May 2, 2020

Description
I was playing around with the state machine from this article and then tried to visualize it but due to my mistake in code the page crushed with an error "TypeError: "e.assignment[n] is null"".
I didn't expect visualizer to crush.

Reproduction

const fetchMachine = Machine({
  id: "dogFetcher",
  initial: "idle",
  context: {
    dog: null,
    error: null,
  },
  states: {
    idle: {
      on: { fetch: "loading" },
    },
    loading: {
      invoke: {
        src: () => fetch("https://dog.ceo/api/breeds/image/random")
        .then(data => data.json()),
        onDone: {
          target: "success",
          actions: assign({ dog: (_, event) => event.data.message, 
          // mistake here
          error: null }),
          // this works fine
          // actions: assign({ dog: (_, event) => event.data.message, error: () => null }),
        },
        onError: {
          target: "failure",
          actions: assign({ error: (_, event) => event.data }),
        },
      },
      on: { cancel: "idle" },
    },
    success: {
      on: { fetch: "loading" },
    },
    failure: {
      on: { fetch: "loading" },
    },
  },
});
@davidkpiano
Copy link
Collaborator

I'm working on a new visualizer which will not have this problem.

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

No branches or pull requests

2 participants