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

Question: How would you handle extra metadata related to a transition? #54

Open
atonse opened this issue Jun 21, 2019 · 4 comments
Open

Comments

@atonse
Copy link
Contributor

atonse commented Jun 21, 2019

We'd like to send in additional metadata related to a transition (like the current user that performed the transition, or a related record ID to close).

How would we pass that in? Currently, I don't see a field in transition_to/3 for this kind of metadata.

Thanks in advance.

@joaomdmoura
Copy link
Owner

🤔 good point, I don't think there is an easy way to to that, unless you add something into the struct that you could pick up later in a callback, but this might be a new feature.

@atonse
Copy link
Contributor Author

atonse commented Oct 25, 2019

I solved this in my fork shortly after writing this. I'll send you a pull request :)

@TalkingQuickly
Copy link

@atonse I'd be very interested in the pull request as well if you have it around!

@TalkingQuickly
Copy link

For anyone who comes to this thread via Google, there's a very simple version of this here (no tests yet so haven't submitted a PR); https://github.com/TalkingQuickly/machinery/tree/feature/transition_metadata which allows you to pass in metadata, e.g:

Machinery.transition_to(user, MyApp.UserStateMachine, "active", %{changed_by: "Someones Name"})

And then define log_transition with arity 3 e.g. def log_transition(struct, next_state, metadata) do and get the metadata map passed in to the log_transition call. Should be backwards compatible because the transition_to call just defaults to an empty map if none is provided.

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

3 participants