Changeset - 1b7cde922c3d
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 20 months ago 2023-05-29 22:17:28
drewp@bigasterisk.com
save some work
1 file changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
light9/web/SyncedGraph.ts
Show inline comments
 
@@ -30,49 +30,52 @@ export class SyncedGraph {
 
    // The /syncedGraph path of an rdfdb server.
 
    patchSenderUrl: string,
 
    // prefixes can be used in Uri(curie) calls. This mapping may grow during loadTrig calls.
 
    public prefixes: Map<string, string>,
 
    private setStatus: (status: string) => void
 
  ) {
 
    this.prefixFuncs = this.rebuildPrefixFuncs(prefixes);
 
    this.graph = new N3.Store();
 
    this.autoDeps = new AutoDependencies(this);
 
    this.autoDeps.graphError.subscribe((e) => {
 
      log("graph learned of error - reconnecting", e);
 
      this.client.disconnect();
 
    });
 
    this.clearGraph();
 

	
 
    this.client = new RdfDbClient(patchSenderUrl, this._clearGraphOnNewConnection.bind(this), this._applyPatch.bind(this), this.setStatus);
 
  }
 

	
 
  clearGraph() {
 
    // must not try send a patch to the server!
 
    // just deletes the statements; watchers are unaffected.
 
    this.cachedFloatValues = new Map(); // s + '|' + p -> number
 
    this.cachedUriValues = new Map(); // s + '|' + p -> Uri
 

	
 
    this._applyPatch(patchToDeleteEntireGraph(this.graph));
 
    const p = patchToDeleteEntireGraph(this.graph);
 
    if (!p.isEmpty()) {
 
      this._applyPatch(p);
 
    }
 
    // if we had a Store already, this lets N3.Store free all its indices/etc
 
    this.graph = new N3.Store();
 
    this.rebuildPrefixFuncs(this.prefixes);
 
  }
 

	
 
  _clearGraphOnNewConnection() {
 
    // must not try send a patch to the server
 

	
 
    log("clearGraphOnNewConnection");
 
    this.clearGraph();
 
    log("clearGraphOnNewConnection done");
 
  }
 

	
 
  private rebuildPrefixFuncs(prefixes: Map<string, string>) {
 
    const p = Object.create(null);
 
    prefixes.forEach((v: string, k: string) => (p[k] = v));
 

	
 
    this.prefixFuncs = N3.Util.prefixes(p);
 
    return this.prefixFuncs;
 
  }
 

	
 
  U() {
 
    // just a shorthand
 
    return this.Uri.bind(this);
0 comments (0 inline, 0 general)