Skip to content

Commit 0be2042

Browse files
author
vuong
committed
add getEditType to OperationModel
1 parent f2dede7 commit 0be2042

8 files changed

+47
-11
lines changed

Diff for: backend/editor/OT/data/array_operation.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
// ArrayOperation is an operation on an array type
99
// @implements OperationModel
1010
type ArrayOperation struct {
11-
newValue datamodels.DataType
11+
newValue datamodels.DataType
12+
operationType EditType
1213
}
1314

1415
// TransformAgainst is the ArrayOperation implementation of the operationModel interface
@@ -20,3 +21,8 @@ func (arrOp ArrayOperation) TransformAgainst(operation OperationModel, applicati
2021
func (arrOp ArrayOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
2122
return parentNode
2223
}
24+
25+
// getEditType is the ArrayOperation implementation of the OperationModel interface
26+
func (arrOp ArrayOperation) GetEditType() EditType {
27+
return arrOp.operationType
28+
}

Diff for: backend/editor/OT/data/boolean_operation.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"
55
// BooleanOperations represents an operation on a boolean type
66
// @implements OperationModel
77
type BooleanOperation struct {
8-
newValue bool
8+
newValue bool
9+
operationType EditType
910
}
1011

1112
// TransformAgainst is the BooleanOperation implementation of the operationModel interface
@@ -17,3 +18,8 @@ func (boolOp BooleanOperation) TransformAgainst(operation OperationModel, applic
1718
func (boolOp BooleanOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
1819
return parentNode
1920
}
21+
22+
// getEditType is the BooleanOperation implementation of the OperationModel interface
23+
func (boolOp BooleanOperation) GetEditType() EditType {
24+
return boolOp.operationType
25+
}

Diff for: backend/editor/OT/data/integer_operation.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"
55
// IntegerOperation represents an operation on an integer type
66
// @implementations of OperationModel
77
type IntegerOperation struct {
8-
newValue int
8+
newValue int
9+
operationType EditType
910
}
1011

1112
// TransformAgainst is the IntegerOperation implementation of the operationModel interface
@@ -17,3 +18,8 @@ func (intOp IntegerOperation) TransformAgainst(operation OperationModel, applica
1718
func (intOp IntegerOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
1819
return parentNode
1920
}
21+
22+
// getEditType is the IntegerOperation implementation of the OperationModel interface
23+
func (intOp IntegerOperation) GetEditType() EditType {
24+
return intOp.operationType
25+
}

Diff for: backend/editor/OT/data/noop_operation.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"
44

55
// Noop represents a non-existent operation
66
// @implements OperationModel
7-
type Noop struct{}
7+
type Noop struct {
8+
operationType EditType
9+
}
810

911
// TransformAgainst is the noop implementation of the operationModel interface
1012
func (noop Noop) TransformAgainst(operation OperationModel, applicationType EditType) (OperationModel, OperationModel) {
@@ -15,3 +17,8 @@ func (noop Noop) TransformAgainst(operation OperationModel, applicationType Edit
1517
func (noop Noop) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
1618
return parentNode
1719
}
20+
21+
// getEditType is the noop implementation of the OperationModel interface
22+
func (noop Noop) GetEditType() EditType {
23+
return noop.operationType
24+
}

Diff for: backend/editor/OT/data/object_operation.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77

88
// ObjectOperation represents an operation we perform on an object
99
type ObjectOperation struct {
10-
newValue datamodels.DataType
10+
newValue datamodels.DataType
11+
operationType EditType
1112
}
1213

1314
// TransformAgainst is the ArrayOperation implementation of the operationModel interface
@@ -19,3 +20,8 @@ func (objOp ObjectOperation) TransformAgainst(operation OperationModel, applicat
1920
func (objOp ObjectOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
2021
return parentNode
2122
}
23+
24+
// getEditType is the ArrayOperation implementation of the OperationModel interface
25+
func (objOp ObjectOperation) GetEditType() EditType {
26+
return objOp.operationType
27+
}

Diff for: backend/editor/OT/data/operation_model.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ type (
1414
OperationModel interface {
1515
TransformAgainst(op OperationModel, applicationType EditType) (OperationModel, OperationModel)
1616
Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode
17+
GetEditType() EditType
1718
}
1819

1920
// Operation is the fundamental incoming type from the frontend
2021
Operation struct {
2122
Path []int
22-
OperationType EditType
2323
AcknowledgedServerOps int
24-
25-
IsNoOp bool
26-
Operation OperationModel
24+
IsNoOp bool
25+
Operation OperationModel
2726
}
2827
)
2928

Diff for: backend/editor/OT/data/string_operation.go

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"
77
type StringOperation struct {
88
rangeStart, rangeEnd int
99
newValue string
10+
operationType EditType
1011
}
1112

1213
// TransformAgainst is the ArrayOperation implementation of the operationModel interface
@@ -18,3 +19,8 @@ func (stringOp StringOperation) TransformAgainst(operation OperationModel, appli
1819
func (arrOp StringOperation) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) cmsjson.AstNode {
1920
return parentNode
2021
}
22+
23+
// getEditType is the ArrayOperation implementation of the OperationModel interface
24+
func (arrOp StringOperation) GetEditType() EditType {
25+
return arrOp.operationType
26+
}

Diff for: backend/editor/OT/transform.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
func transformPipeline(x data.Operation, y data.Operation) (data.Operation, data.Operation) {
1010
// Finally normalise the operations to account for no-op return values
1111
needsAppSpecific := false
12-
x.Path, y.Path, needsAppSpecific = transformPaths(x.Path, y.Path, x.OperationType, y.OperationType)
12+
x.Path, y.Path, needsAppSpecific = transformPaths(x.Path, y.Path, x.Operation.GetEditType(), y.Operation.GetEditType())
1313
x, y = normaliseOperation(x), normaliseOperation(y)
1414

1515
if needsAppSpecific {
16-
x.Operation.TransformAgainst(y.Operation, x.OperationType)
16+
x.Operation.TransformAgainst(y.Operation, x.Operation.GetEditType())
1717
}
1818

1919
return x, y

0 commit comments

Comments
 (0)