Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Actions in nested machines #55

Closed
Santiago-j-s opened this issue Sep 13, 2021 · 2 comments
Closed

Actions in nested machines #55

Santiago-j-s opened this issue Sep 13, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@Santiago-j-s
Copy link

Santiago-j-s commented Sep 13, 2021

I think that i found a bug in lucy 0.3.4

use './utils.js' {assignDays}

machine testMachine {
  action assignDays = assignDays

  initial state test {}
}

compiles to

import { createMachine } from 'xstate';
import { assignDays } from './utils.js';

export function createTestMachine({ context = {} } = {}) {
  return createMachine({
    initial: 'test',
    context,
    states: {
      test: {

      }
    }
  }, {
    actions: {
      assignDays: assignDays
    }
  });
}

which is ok, but

use './utils.js' {assignDays}

machine testMachine {
  action assignDays = assignDays

  initial state test {
    machine nested {
    }
  }
}

compiles to

import { createMachine } from 'xstate';
import { assignDays } from './utils.js';

export function createTestMachine({ context = {} } = {}) {
  return createMachine({
    initial: 'test',
    context,
    states: {
      test: {
        context
      }
    }
  });
}

where actions dissapeared

@Santiago-j-s Santiago-j-s changed the title actions in nested machines Actions in nested machines Sep 13, 2021
@matthewp matthewp added the bug Something isn't working label Sep 13, 2021
@matthewp
Copy link
Collaborator

Thanks for filing! Why do you expect it to be included in the second where it's not used?

@Santiago-j-s
Copy link
Author

Sorry, I didn't express myself well. I expect it to be included only if it's used, a better test case would be

use './utils.js' {assignDays}

machine testMachine {
  action assignDays = assign(days, assignDays)
  
  initial state initial {
    click => assignDays => newState
  }

  final state newState {}
}

machine testNestedMachine {
  initial state test {
    machine nested {
      action assignDays = assign(days, assignDays)

      initial state initial {
        click => assignDays => newState
      }

      final state newState {}
    }
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants