From 53f6f5937600b5b1d48b45006bd33f58d9ba3f4c Mon Sep 17 00:00:00 2001 From: Elena Poelman Date: Mon, 17 Jun 2024 12:59:30 +0200 Subject: [PATCH] define term equals methods as prototype methods instead of arrow functions --- .changeset/lucky-experts-kneel.md | 11 +++++++++++ addon/core/say-data-factory/blank-node.ts | 4 ++-- addon/core/say-data-factory/default-graph.ts | 4 ++-- addon/core/say-data-factory/literal.ts | 4 ++-- addon/core/say-data-factory/named-node.ts | 4 ++-- .../prosemirror-terms/content-literal.ts | 4 ++-- .../prosemirror-terms/literal-node.ts | 4 ++-- .../prosemirror-terms/resource-node.ts | 4 ++-- addon/core/say-data-factory/quad.ts | 4 ++-- addon/core/say-data-factory/variable.ts | 4 ++-- 10 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 .changeset/lucky-experts-kneel.md diff --git a/.changeset/lucky-experts-kneel.md b/.changeset/lucky-experts-kneel.md new file mode 100644 index 000000000..c232f7e1b --- /dev/null +++ b/.changeset/lucky-experts-kneel.md @@ -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. diff --git a/addon/core/say-data-factory/blank-node.ts b/addon/core/say-data-factory/blank-node.ts index 1238d872e..6738f0e68 100644 --- a/addon/core/say-data-factory/blank-node.ts +++ b/addon/core/say-data-factory/blank-node.ts @@ -13,9 +13,9 @@ export class SayBlankNode implements RDF.BlankNode { this.value = value; } - equals = (other?: Option) => { + equals(other?: Option) { return ( !!other && other.termType === 'BlankNode' && other.value === this.value ); - }; + } } diff --git a/addon/core/say-data-factory/default-graph.ts b/addon/core/say-data-factory/default-graph.ts index 5240927ce..24d59dca0 100644 --- a/addon/core/say-data-factory/default-graph.ts +++ b/addon/core/say-data-factory/default-graph.ts @@ -16,7 +16,7 @@ export class SayDefaultGraph implements RDF.DefaultGraph { // Private constructor } - equals = (other?: Option) => { + equals(other?: Option) { return !!other && other.termType === 'DefaultGraph'; - }; + } } diff --git a/addon/core/say-data-factory/literal.ts b/addon/core/say-data-factory/literal.ts index 0dcc1c83e..f8cb14849 100644 --- a/addon/core/say-data-factory/literal.ts +++ b/addon/core/say-data-factory/literal.ts @@ -37,7 +37,7 @@ export class SayLiteral implements RDF.Literal { } } - equals = (other?: Option) => { + equals(other?: Option) { return ( !!other && other.termType === 'Literal' && @@ -45,5 +45,5 @@ export class SayLiteral implements RDF.Literal { other.language === this.language && this.datatype.equals(other.datatype) ); - }; + } } diff --git a/addon/core/say-data-factory/named-node.ts b/addon/core/say-data-factory/named-node.ts index 65047c0fe..f874915dc 100644 --- a/addon/core/say-data-factory/named-node.ts +++ b/addon/core/say-data-factory/named-node.ts @@ -15,9 +15,9 @@ export class SayNamedNode this.value = value; } - equals = (other?: Option) => { + equals(other?: Option) { return ( !!other && other.termType === 'NamedNode' && other.value === this.value ); - }; + } } diff --git a/addon/core/say-data-factory/prosemirror-terms/content-literal.ts b/addon/core/say-data-factory/prosemirror-terms/content-literal.ts index 8f697064a..2cf877cad 100644 --- a/addon/core/say-data-factory/prosemirror-terms/content-literal.ts +++ b/addon/core/say-data-factory/prosemirror-terms/content-literal.ts @@ -33,12 +33,12 @@ export class ContentLiteralTerm { } } - equals = (other?: Option) => { + equals(other?: Option) { return ( !!other && other.termType === 'ContentLiteral' && other.language === this.language && this.datatype.equals(other.datatype) ); - }; + } } diff --git a/addon/core/say-data-factory/prosemirror-terms/literal-node.ts b/addon/core/say-data-factory/prosemirror-terms/literal-node.ts index aeaab9ef5..6a9d5b06d 100644 --- a/addon/core/say-data-factory/prosemirror-terms/literal-node.ts +++ b/addon/core/say-data-factory/prosemirror-terms/literal-node.ts @@ -37,7 +37,7 @@ export class LiteralNodeTerm { } } - equals = (other?: Option) => { + equals(other?: Option) { return ( !!other && other.termType === 'LiteralNode' && @@ -45,5 +45,5 @@ export class LiteralNodeTerm { other.language === this.language && this.datatype.equals(other.datatype) ); - }; + } } diff --git a/addon/core/say-data-factory/prosemirror-terms/resource-node.ts b/addon/core/say-data-factory/prosemirror-terms/resource-node.ts index 5ae20699a..89c89c7bb 100644 --- a/addon/core/say-data-factory/prosemirror-terms/resource-node.ts +++ b/addon/core/say-data-factory/prosemirror-terms/resource-node.ts @@ -12,9 +12,9 @@ export class ResourceNodeTerm { this.value = value; } - equals = (other?: Option) => { + equals(other?: Option) { return ( !!other && other.termType === 'ResourceNode' && other.value === this.value ); - }; + } } diff --git a/addon/core/say-data-factory/quad.ts b/addon/core/say-data-factory/quad.ts index 80ad4e33f..35f3ad926 100644 --- a/addon/core/say-data-factory/quad.ts +++ b/addon/core/say-data-factory/quad.ts @@ -17,7 +17,7 @@ export class SayQuad implements RDF.BaseQuad { public readonly graph: RDF.Term, ) {} - equals = (other?: Option) => { + equals(other?: Option) { // `|| !other.termType` is for backwards-compatibility with old factories without RDF* support. return ( !!other && @@ -27,5 +27,5 @@ export class SayQuad implements RDF.BaseQuad { this.object.equals(other.object) && this.graph.equals(other.graph) ); - }; + } } diff --git a/addon/core/say-data-factory/variable.ts b/addon/core/say-data-factory/variable.ts index 4aeadaa39..afb9386b0 100644 --- a/addon/core/say-data-factory/variable.ts +++ b/addon/core/say-data-factory/variable.ts @@ -13,9 +13,9 @@ export class SayVariable implements RDF.Variable { this.value = value; } - equals = (other?: Option) => { + equals(other?: Option) { return ( !!other && other.termType === 'Variable' && other.value === this.value ); - }; + } }