Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ 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
);
};
}

toJSON() {
return {
Expand Down
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';
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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)
);
};
}

toJSON() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ 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
);
};
}

toJSON() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ 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)
);
};
}

toJSON() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export class LiteralNodeTerm {
this.value = value;
}

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

toJSON() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ 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
);
};
}

toJSON() {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-rdfa-editor/src/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)
);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ 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
);
};
}

toJSON() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import type {
ModelTerm,
} from '#root/utils/_private/rdfa-parser/rdfa-parser.ts';

export class ModelDataFactory<N> extends DataFactory {
export class ModelDataFactory<N> extends DataFactory<ModelQuad<N>> {
quad(
subject: ModelQuadSubject<N>,
predicate: ModelQuadPredicate<N>,
object: ModelQuadObject<N>,
graph: Quad_Graph,
): ModelQuad<N> {
const quad = super.quad(subject, predicate, object, graph);
return { ...quad, subject, predicate, object, graph };
return super.quad(subject, predicate, object, graph);
}

namedNode<N, I extends string = string>(
Expand Down