diff options
author | Michael Muré <batolettre@gmail.com> | 2022-08-01 17:16:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-01 17:16:45 +0200 |
commit | cd52872475f1b39f3fb6546606c1e78afb6c08e3 (patch) | |
tree | 9f04b1e1ee362e210e74aaa324d950058ed14bf2 /entity/dag/op_noop.go | |
parent | 2ade8fb1d570ddcb4aedc9386af46d208b129daa (diff) | |
parent | 56966fec5562c3a0e23340d0fbe754626c3beb64 (diff) | |
download | git-bug-cd52872475f1b39f3fb6546606c1e78afb6c08e3.tar.gz |
Merge pull request #835 from MichaelMure/op-base
entity/dag: proper base operation for simplified implementation
Diffstat (limited to 'entity/dag/op_noop.go')
-rw-r--r-- | entity/dag/op_noop.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/entity/dag/op_noop.go b/entity/dag/op_noop.go new file mode 100644 index 00000000..2bc53578 --- /dev/null +++ b/entity/dag/op_noop.go @@ -0,0 +1,39 @@ +package dag + +import ( + "github.com/MichaelMure/git-bug/entity" + "github.com/MichaelMure/git-bug/identity" +) + +var _ Operation = &NoOpOperation[Snapshot]{} +var _ OperationDoesntChangeSnapshot = &NoOpOperation[Snapshot]{} + +// NoOpOperation is an operation that does not change the entity state. It can +// however be used to store arbitrary metadata in the entity history, for example +// to support a bridge feature. +type NoOpOperation[SnapT Snapshot] struct { + OpBase +} + +func NewNoOpOp[SnapT Snapshot](opType OperationType, author identity.Interface, unixTime int64) *NoOpOperation[SnapT] { + return &NoOpOperation[SnapT]{ + OpBase: NewOpBase(opType, author, unixTime), + } +} + +func (op *NoOpOperation[SnapT]) Id() entity.Id { + return IdOperation(op, &op.OpBase) +} + +func (op *NoOpOperation[SnapT]) Apply(snapshot SnapT) { + // Nothing to do +} + +func (op *NoOpOperation[SnapT]) Validate() error { + if err := op.OpBase.Validate(op, op.OperationType); err != nil { + return err + } + return nil +} + +func (op *NoOpOperation[SnapT]) DoesntChangeSnapshot() {} |