Changeset - b51c74da9d35
[Not reviewed]
default
0 3 0
drewp@bigasterisk.com - 20 months ago 2023-05-29 20:22:44
drewp@bigasterisk.com
more cleanup- mixed up with other commits
3 files changed with 10 insertions and 8 deletions:
0 comments (0 inline, 0 general)
light9/web/AutoDependencies.ts
Show inline comments
 
import debug from "debug";
 
import { NamedNode, Quad_Graph, Quad_Object, Quad_Predicate, Quad_Subject, Term, Util } from "n3";
 
import { filter } from "underscore";
 
import { Patch, QuadPattern } from "./patch";
 
import { SubEvent } from "sub-events";
 
import { SyncedGraph } from "./SyncedGraph";
 

	
 
const log = debug("autodep");
 

	
 
interface QuadPattern {
 
  subject: Quad_Subject | null;
 
  predicate: Quad_Predicate | null;
 
  object: Quad_Object | null;
 
  graph: Quad_Graph | null;
 
}
 

	
 
// use patch as an optional optimization, but you can't count on it
 
export type HandlerFunc = (p?: Patch) => void;
 

	
 
class Handler {
 
  patterns: QuadPattern[];
 
  innerHandlers: Handler[];
 
@@ -25,13 +20,14 @@ class Handler {
 
  }
 
}
 

	
 
export class AutoDependencies {
 
  handlers: Handler;
 
  handlerStack: Handler[];
 
  constructor() {
 
  graphError: SubEvent<string> = new SubEvent();
 
  constructor(private graph: SyncedGraph) {
 
    // tree of all known Handlers (at least those with non-empty
 
    // patterns). Top node is not a handler.
 
    this.handlers = new Handler(null, "root");
 
    this.handlerStack = [this.handlers]; // currently running
 
    log("window.ad");
 
    (window as any).ad = this;
 
@@ -72,12 +68,13 @@ export class AutoDependencies {
 
      // assuming here it didn't get to do all its queries, we could
 
      // add a *,*,*,* handler to call for sure the next time?
 
      // log('done. got: ', handler.patterns)
 
      this.handlerStack.pop();
 
    }
 
  }
 

	
 
  // handler might have no watches, in which case we could forget about it
 
  logHandlerTree() {
 
    log("handler tree:");
 
    const shorten = (x: Term | null) => {
 
      if (x === null) {
 
        return "null";
light9/web/RdfdbSyncedGraph.ts
Show inline comments
 
@@ -30,12 +30,13 @@ export class RdfdbSyncedGraph extends Li
 
  constructor() {
 
    super();
 
    this.status = "startup";
 
    const prefixes = new Map<string, string>([
 
      ["", "http://light9.bigasterisk.com/"],
 
      ["dev", "http://light9.bigasterisk.com/device/"],
 
      ["effect", "http://light9.bigasterisk.com/effect/"],
 
      ["rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"],
 
      ["rdfs", "http://www.w3.org/2000/01/rdf-schema#"],
 
      ["xsd", "http://www.w3.org/2001/XMLSchema#"],
 
    ]);
 
    this.graph = new SyncedGraph(
 
      this.testGraph ? "unused" : "/rdfdb/api/syncedGraph",
light9/web/SyncedGraph.ts
Show inline comments
 
@@ -33,12 +33,16 @@ export class SyncedGraph {
 
    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() {
0 comments (0 inline, 0 general)