Skip to content

Is there a way to get a specific index of the pointer? #7

@danielbeeke

Description

@danielbeeke

I have the following code:

  render () {
    const namesPointer = this.dataPointer().out([this.predicate])

    // My question is about the following three lines.
    const indexSpecificNamesPointer = namesPointer.clone({
      ptrs: [namesPointer.ptrs[this.index]].filter(Boolean)
    }).trim().out([schema('name'), rdfs('label')])

    const name = bestLanguage(indexSpecificNamesPointer, this.uiLanguagePriorities)


    this.innerHTML = `<h2>${name ?? this.value?.value} <em>(blank node)</em></h2>`
  }

A possible syntax might be:

  render () {
    const namesPointer = this.dataPointer()
      .out([this.predicate])
      .index(this.index)
      .out([schema('name'), rdfs('label')])

    const name = bestLanguage(indexSpecificNamesPointer, this.uiLanguagePriorities)


    this.innerHTML = `<h2>${name ?? this.value?.value} <em>(blank node)</em></h2>`
  }

What do you think? Is something like this already in the library or would you be open to a PR for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions