Skip to content

Commit

Permalink
add getEditType to OperationModel
Browse files Browse the repository at this point in the history
  • Loading branch information
vuong committed Oct 16, 2022
1 parent f2dede7 commit 0be2042
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 11 deletions.
8 changes: 7 additions & 1 deletion backend/editor/OT/data/array_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
// ArrayOperation is an operation on an array type
// @implements OperationModel
type ArrayOperation struct {
newValue datamodels.DataType
newValue datamodels.DataType
operationType EditType
}

// TransformAgainst is the ArrayOperation implementation of the operationModel interface
Expand All @@ -20,3 +21,8 @@ func (arrOp ArrayOperation) TransformAgainst(operation OperationModel, applicati
func (arrOp ArrayOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
return parentNode
}

// getEditType is the ArrayOperation implementation of the OperationModel interface
func (arrOp ArrayOperation) GetEditType() EditType {
return arrOp.operationType
}
8 changes: 7 additions & 1 deletion backend/editor/OT/data/boolean_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"
// BooleanOperations represents an operation on a boolean type
// @implements OperationModel
type BooleanOperation struct {
newValue bool
newValue bool
operationType EditType
}

// TransformAgainst is the BooleanOperation implementation of the operationModel interface
Expand All @@ -17,3 +18,8 @@ func (boolOp BooleanOperation) TransformAgainst(operation OperationModel, applic
func (boolOp BooleanOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
return parentNode
}

// getEditType is the BooleanOperation implementation of the OperationModel interface
func (boolOp BooleanOperation) GetEditType() EditType {
return boolOp.operationType
}
8 changes: 7 additions & 1 deletion backend/editor/OT/data/integer_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"
// IntegerOperation represents an operation on an integer type
// @implementations of OperationModel
type IntegerOperation struct {
newValue int
newValue int
operationType EditType
}

// TransformAgainst is the IntegerOperation implementation of the operationModel interface
Expand All @@ -17,3 +18,8 @@ func (intOp IntegerOperation) TransformAgainst(operation OperationModel, applica
func (intOp IntegerOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
return parentNode
}

// getEditType is the IntegerOperation implementation of the OperationModel interface
func (intOp IntegerOperation) GetEditType() EditType {
return intOp.operationType
}
9 changes: 8 additions & 1 deletion backend/editor/OT/data/noop_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"

// Noop represents a non-existent operation
// @implements OperationModel
type Noop struct{}
type Noop struct {
operationType EditType
}

// TransformAgainst is the noop implementation of the operationModel interface
func (noop Noop) TransformAgainst(operation OperationModel, applicationType EditType) (OperationModel, OperationModel) {
Expand All @@ -15,3 +17,8 @@ func (noop Noop) TransformAgainst(operation OperationModel, applicationType Edit
func (noop Noop) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
return parentNode
}

// getEditType is the noop implementation of the OperationModel interface
func (noop Noop) GetEditType() EditType {
return noop.operationType
}
8 changes: 7 additions & 1 deletion backend/editor/OT/data/object_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (

// ObjectOperation represents an operation we perform on an object
type ObjectOperation struct {
newValue datamodels.DataType
newValue datamodels.DataType
operationType EditType
}

// TransformAgainst is the ArrayOperation implementation of the operationModel interface
Expand All @@ -19,3 +20,8 @@ func (objOp ObjectOperation) TransformAgainst(operation OperationModel, applicat
func (objOp ObjectOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
return parentNode
}

// getEditType is the ArrayOperation implementation of the OperationModel interface
func (objOp ObjectOperation) GetEditType() EditType {
return objOp.operationType
}
7 changes: 3 additions & 4 deletions backend/editor/OT/data/operation_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ type (
OperationModel interface {
TransformAgainst(op OperationModel, applicationType EditType) (OperationModel, OperationModel)
Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode
GetEditType() EditType
}

// Operation is the fundamental incoming type from the frontend
Operation struct {
Path []int
OperationType EditType
AcknowledgedServerOps int

IsNoOp bool
Operation OperationModel
IsNoOp bool
Operation OperationModel
}
)

Expand Down
6 changes: 6 additions & 0 deletions backend/editor/OT/data/string_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"
type StringOperation struct {
rangeStart, rangeEnd int
newValue string
operationType EditType
}

// TransformAgainst is the ArrayOperation implementation of the operationModel interface
Expand All @@ -18,3 +19,8 @@ func (stringOp StringOperation) TransformAgainst(operation OperationModel, appli
func (arrOp StringOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
return parentNode
}

// getEditType is the ArrayOperation implementation of the OperationModel interface
func (arrOp StringOperation) GetEditType() EditType {
return arrOp.operationType
}
4 changes: 2 additions & 2 deletions backend/editor/OT/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
func transformPipeline(x data.Operation, y data.Operation) (data.Operation, data.Operation) {
// Finally normalise the operations to account for no-op return values
needsAppSpecific := false
x.Path, y.Path, needsAppSpecific = transformPaths(x.Path, y.Path, x.OperationType, y.OperationType)
x.Path, y.Path, needsAppSpecific = transformPaths(x.Path, y.Path, x.Operation.GetEditType(), y.Operation.GetEditType())
x, y = normaliseOperation(x), normaliseOperation(y)

if needsAppSpecific {
x.Operation.TransformAgainst(y.Operation, x.OperationType)
x.Operation.TransformAgainst(y.Operation, x.Operation.GetEditType())
}

return x, y
Expand Down

0 comments on commit 0be2042

Please sign in to comment.