Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Nested spreads not getting parsed from MachineConfig objects #9

Open
NixBiks opened this issue Sep 16, 2021 · 0 comments · May be fixed by #19
Open

Nested spreads not getting parsed from MachineConfig objects #9

NixBiks opened this issue Sep 16, 2021 · 0 comments · May be fixed by #19

Comments

@NixBiks
Copy link

NixBiks commented Sep 16, 2021

The following example

import { createMachine, MachineConfig } from "xstate";

type Context = { name: string };
type Event = { type: "CHANGE_NAME"; name: string };

const config: MachineConfig<Context, any, Event> = {
  states: {
    a: { always: { target: "b" } },
    b: { type: "final" },
  },
};

const machine = createMachine<Context, Event>({
  initial: "A",
  states: {
    A: { ...config },
    B: { ...config, states: { ...config.states, c: {} } },
  },
});

parses to

[
  {
    "initial": "A",
    "states": {
      "A": {
        "states": {
          "a": {
            "always": {
              "target": "b"
            }
          },
          "b": {
            "type": "final"
          }
        }
      },
      "B": {
        "states": {
          "c": {}
        }
      }
    }
  }
]

instead of

[
  {
    "initial": "A",
    "states": {
      "A": {
        "states": {
          "a": {
            "always": {
              "target": "b"
            }
          },
          "b": {
            "type": "final"
          }
        }
      },
      "B": {
        "states": {
          "a": {
            "always": {
              "target": "b"
            }
          },
          "b": {
            "type": "final"
          },
          "c": {}
        }
      }
    }
  }
]
@with-heart with-heart linked a pull request Feb 25, 2022 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant