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

Callback on entering initial state #233

Open
penguoir opened this issue Jul 21, 2022 · 1 comment
Open

Callback on entering initial state #233

penguoir opened this issue Jul 21, 2022 · 1 comment

Comments

@penguoir
Copy link

I'd like to run a callback when an object enters its initial state. For example:

class Article
  include Workflow

  workflow do
    state :new
  end

  def on_new_entry
    puts 'entered new'
  end
end

Currently, workflow doesn't run the on_new_entry callback. Is this expected? If so, what's the best practice for running a callback on entering of an initial state?

@tlloydthwaites
Copy link

Looking at

def process_event!(name, *args, **kwargs)
, on entry is not called for the initial action, only when transitioning from one action to another.

I'd suggest defining a method with the state name, but that's tricky with an event called 'new'. You could always call it something else, like 'initial', and then you could have an initial method?

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

No branches or pull requests

2 participants