Changeset - ed0db55f604c
[Not reviewed]
default
0 3 0
drewp@bigasterisk.com - 20 months ago 2023-06-01 21:20:40
drewp@bigasterisk.com
use undefined for 'nothing selected' insetad of null
3 files changed with 12 insertions and 9 deletions:
0 comments (0 inline, 0 general)
light9/fade/Light9FadeUi.ts
Show inline comments
 
@@ -82,56 +82,56 @@ export class Light9EffectFader extends L
 
      <light9-fader .value=${this.value} @change=${this.onSliderInput}></light9-fader>
 
      <div>${this.value.toPrecision(3)}</div>
 
      <div>eff: <edit-choice .uri=${this.effect} @edited=${this.onEffectChange}></edit-choice></div>
 
      <div>attr: <edit-choice .uri=${this.effectAttr} @edited=${this.onEffectAttrChange}></edit-choice></div>
 
      <div>&lt;=&gt; Slider ${this.column}</div>
 
    `;
 
  }
 

	
 
  graph?: SyncedGraph;
 
  ctx: NamedNode = new NamedNode(showRoot + "/fade");
 
  @property() uri!: NamedNode;
 
  @property() column!: string;
 
  @property() effect: NamedNode | null = null;
 
  @property() effectAttr: NamedNode | null = null;
 
  @state() setting: NamedNode | null = null;
 
  @property() effect?: NamedNode;
 
  @property() effectAttr?: NamedNode
 
  @state() setting?: NamedNode;
 

	
 
  @property() value: number = 0.0;
 

	
 
  constructor() {
 
    super();
 
    getTopGraph().then((g) => {
 
      this.graph = g;
 
      this.graph.runHandler(this.compile.bind(this, this.graph), `config ${this.uri.value}`);
 
      this.graph.runHandler(this.compileValue.bind(this, this.graph), `valueSync ${this.uri.value}`);
 
    });
 
  }
 

	
 
  private compile(graph: SyncedGraph) {
 
    const U = graph.U();
 
    if (!graph.contains(this.uri, U("rdf:type"), U(":Fader"))) {
 
      // not loaded yet, perhaps
 
      this.column = "unset";
 
      this.effect = null;
 
      this.effectAttr = null;
 
      this.effect = undefined;
 
      this.effectAttr = undefined;
 
      return;
 
    }
 
    this.column = graph.stringValue(this.uri, U(":column"));
 
    this.effect = graph.uriValue(this.uri, U(":effect"));
 
    this.setting = graph.uriValue(this.uri, U(":setting"));
 
    if (this.setting !== null) {
 
    if (this.setting !== undefined) {
 
      try {
 
        this.effectAttr = graph.uriValue(this.setting, U(":effectAttr"));
 
      } catch (e) {
 
        this.effectAttr = null;
 
        this.effectAttr = undefined;
 
      }
 
    }
 
  }
 

	
 
  private compileValue(graph: SyncedGraph) {
 
    const U = graph.U();
 
    if (!graph.contains(this.uri, U("rdf:type"), U(":Fader"))) {
 
      // not loaded yet
 
      // console.timeEnd(`valueSync ${this.uri.value}`)
 
      return;
 
    }
 
    const st = graph.uriValue(this.uri, U(":setting"));
 
@@ -160,19 +160,19 @@ export class Light9EffectFader extends L
 
    if (this.graph === undefined) {
 
      return;
 
    }
 
    const { newValue } = ev.detail;
 
    this.graph.patchObject(this.uri, this.graph.Uri(":effect"), newValue, this.ctx);
 
  }
 

	
 
  onEffectAttrChange(ev: CustomEvent) {
 
    if (this.graph === undefined) {
 
      return;
 
    }
 
    const { newValue } = ev.detail;
 
    if (this.setting === null) {
 
    if (this.setting === undefined) {
 
      this.setting = this.graph.nextNumberedResource(this.graph.Uri(":fade_set"));
 
      this.graph.patchObject(this.uri, this.graph.Uri(":setting"), this.setting, this.ctx);
 
    }
 
    this.graph.patchObject(this.setting, this.graph.Uri(":effectAttr"), newValue, this.ctx);
 
  }
 
}
light9/web/ResourceDisplay.ts
Show inline comments
 
@@ -89,26 +89,29 @@ export class ResourceDisplay extends Lit
 
  }
 

	
 
  updated(changedProperties: PropertyValues) {
 
    if (changedProperties.has("uri")) {
 
      this.onUri();
 
    }
 
  }
 

	
 
  private onUri() {
 
    if (!this.graph) {
 
      return; /*too soon, but getTopGraph will call us again*/
 
    }
 
    
 
    if (this.uri === undefined) {
 
      this.label = "(unset)";
 
    } else if  (this.uri === null) {
 
      throw 'use undefined please'
 
    } else {
 
      this.graph.runHandler(this.compile.bind(this, this.graph), `label for ${this.uri.id}`);
 
    }
 
  }
 
  private compile(graph: SyncedGraph) {
 
    if (this.uri === undefined) {
 
      return;
 
    } else {
 
      this.label = this.graph.labelOrTail(this.uri);
 
    }
 
  }
 

	
tsconfig.json
Show inline comments
 
@@ -18,25 +18,25 @@
 
    // "rootDir": "./",                             /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
 
    // "composite": true,                           /* Enable project compilation */
 
    // "tsBuildInfoFile": "./",                     /* Specify file to store incremental compilation information */
 
    // "removeComments": true,                      /* Do not emit comments to output. */
 
    // "noEmit": true,                              /* Do not emit outputs. */
 
    // "importHelpers": true,                       /* Import emit helpers from 'tslib'. */
 
    // "downlevelIteration": true,                  /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
 
    // "isolatedModules": true,                     /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
 

	
 
    /* Strict Type-Checking Options */
 
    "strict": true,                                 /* Enable all strict type-checking options. */
 
    // "noImplicitAny": true,                       /* Raise error on expressions and declarations with an implied 'any' type. */
 
    // "strictNullChecks": true,                    /* Enable strict null checks. */
 
    "strictNullChecks": true,                    /* Enable strict null checks. */
 
    // "strictFunctionTypes": true,                 /* Enable strict checking of function types. */
 
    // "strictBindCallApply": true,                 /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
 
    // "strictPropertyInitialization": true,        /* Enable strict checking of property initialization in classes. */
 
    // "noImplicitThis": true,                      /* Raise error on 'this' expressions with an implied 'any' type. */
 
    // "alwaysStrict": true,                        /* Parse in strict mode and emit "use strict" for each source file. */
 

	
 
    /* Additional Checks */
 
    // "noUnusedLocals": true,                      /* Report errors on unused locals. */
 
    // "noUnusedParameters": true,                  /* Report errors on unused parameters. */
 
    // "noImplicitReturns": true,                   /* Report error when not all code paths in function return a value. */
 
    // "noFallthroughCasesInSwitch": true,          /* Report errors for fallthrough cases in switch statement. */
 
    // "noUncheckedIndexedAccess": true,            /* Include 'undefined' in index signature results */
0 comments (0 inline, 0 general)