Skip to content

Commit

Permalink
define term equals methods as prototype methods instead of arrow func…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
elpoelma committed Jun 17, 2024
1 parent aee4be4 commit 53f6f59
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 18 deletions.
11 changes: 11 additions & 0 deletions .changeset/lucky-experts-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@lblod/ember-rdfa-editor": patch
---

Define `equals` as a prototype method on RDF term instances instead of as arrow functions.

**Why is this necessary?**
Defining `equals` as a prototype method ensures that is not part of the RDF term objects themselves. This makes it easier/less error-prone to compare objects containing these terms. (e.g. the object-comparison library used by prosemirror-tools does not support function properties)

**Possible drawbacks of this approach**
This approach does have the drawback that spreading an RDF term results in losing the `equals` method.
4 changes: 2 additions & 2 deletions addon/core/say-data-factory/blank-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class SayBlankNode implements RDF.BlankNode {
this.value = value;
}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
return (
!!other && other.termType === 'BlankNode' && other.value === this.value
);
};
}
}
4 changes: 2 additions & 2 deletions addon/core/say-data-factory/default-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SayDefaultGraph implements RDF.DefaultGraph {
// Private constructor
}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
return !!other && other.termType === 'DefaultGraph';
};
}
}
4 changes: 2 additions & 2 deletions addon/core/say-data-factory/literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class SayLiteral implements RDF.Literal {
}
}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
return (
!!other &&
other.termType === 'Literal' &&
other.value === this.value &&
other.language === this.language &&
this.datatype.equals(other.datatype)
);
};
}
}
4 changes: 2 additions & 2 deletions addon/core/say-data-factory/named-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export class SayNamedNode<Iri extends string = string>
this.value = value;
}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
return (
!!other && other.termType === 'NamedNode' && other.value === this.value
);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export class ContentLiteralTerm {
}
}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
return (
!!other &&
other.termType === 'ContentLiteral' &&
other.language === this.language &&
this.datatype.equals(other.datatype)
);
};
}
}
4 changes: 2 additions & 2 deletions addon/core/say-data-factory/prosemirror-terms/literal-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class LiteralNodeTerm {
}
}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
return (
!!other &&
other.termType === 'LiteralNode' &&
other.value === this.value &&
other.language === this.language &&
this.datatype.equals(other.datatype)
);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class ResourceNodeTerm<Iri extends string = string> {
this.value = value;
}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
return (
!!other && other.termType === 'ResourceNode' && other.value === this.value
);
};
}
}
4 changes: 2 additions & 2 deletions addon/core/say-data-factory/quad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SayQuad implements RDF.BaseQuad {
public readonly graph: RDF.Term,
) {}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
// `|| !other.termType` is for backwards-compatibility with old factories without RDF* support.
return (
!!other &&
Expand All @@ -27,5 +27,5 @@ export class SayQuad implements RDF.BaseQuad {
this.object.equals(other.object) &&
this.graph.equals(other.graph)
);
};
}
}
4 changes: 2 additions & 2 deletions addon/core/say-data-factory/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class SayVariable implements RDF.Variable {
this.value = value;
}

equals = (other?: Option<SayTerm>) => {
equals(other?: Option<SayTerm>) {
return (
!!other && other.termType === 'Variable' && other.value === this.value
);
};
}
}

0 comments on commit 53f6f59

Please sign in to comment.