package cabana_test import ( "context" "fmt" "git.golem15.com/golem15/summercms/modules/backpack" "git.golem15.com/golem15/summercms/modules/cabana" "git.golem15.com/golem15/summercms/modules/pact" ) func ExampleEmitRecordSaved() { app := backpack.New(nil) // in a plugin, the application it booted with // acme.audit listens from its Boot step; record events arrive as pointers. app.Events.Listen("acme.audit", func(ctx context.Context, ev *pact.RecordSaved) error { for _, change := range ev.Changes { fmt.Printf("%s %s: %s %q -> %q (locale %q)\n", ev.Model, ev.ID, change.Attribute, change.Old, change.New, change.Locale) } return nil }) // acme.blog's own API handler has saved a post outside the admin forms. // The write has committed, so it passes no transaction and the event // fires at once; inside a lagoon.Transaction it would pass tx and the // event would wait for the commit. cabana.EmitRecordSaved(context.Background(), app, nil, pact.RecordSaved{ Model: "acme_blog_posts", ID: "42", Changes: []pact.RecordChange{{Attribute: "slug", Old: "hello", New: "hello-world"}}, }) // Output: // acme_blog_posts 42: slug "hello" -> "hello-world" (locale "") }