Forráskód Böngészése

beginning documentation

Raanan Weber 7 éve
szülő
commit
dd806acbf9
2 módosított fájl, 40 hozzáadás és 0 törlés
  1. 16 0
      Viewer/src/configuration/loader.ts
  2. 24 0
      Viewer/src/configuration/mappers.ts

+ 16 - 0
Viewer/src/configuration/loader.ts

@@ -5,6 +5,11 @@ import { getConfigurationType } from './types';
 import * as deepmerge from '../../assets/deepmerge.min.js';
 import { Tools, IFileRequest } from 'babylonjs';
 
+/**
+ * The configuration loader will load the configuration object from any source and will use the defined mapper to
+ * parse the object and return a conform ViewerConfiguration.
+ * It is a private member of the scene.
+ */
 export class ConfigurationLoader {
 
     private _configurationCache: { [url: string]: any };
@@ -16,6 +21,14 @@ export class ConfigurationLoader {
         this._loadRequests = [];
     }
 
+    /**
+     * load a configuration object that is defined in the initial configuration provided.
+     * The viewer configuration can extend different types of configuration objects and have an extra configuration defined.
+     * 
+     * @param initConfig the initial configuration that has the definitions of further configuration to load.
+     * @param callback an optional callback that will be called sync, if noconfiguration needs to be loaded or configuration is payload-only
+     * @returns A promise that delivers the extended viewer configuration, when done.
+     */
     public loadConfiguration(initConfig: ViewerConfiguration = {}, callback?: (config: ViewerConfiguration) => void): Promise<ViewerConfiguration> {
 
         let loadedConfig: ViewerConfiguration = deepmerge({}, initConfig);
@@ -69,6 +82,9 @@ export class ConfigurationLoader {
         }
     }
 
+    /**
+     * Dispose the configuration loader. This will cancel file requests, if active.
+     */
     public dispose() {
         this._loadRequests.forEach(request => {
             request.abort();

+ 24 - 0
Viewer/src/configuration/mappers.ts

@@ -3,12 +3,36 @@ import { ViewerConfiguration } from './configuration';
 
 import { kebabToCamel } from '../helper';
 
+/**
+ * This is the mapper's interface. Implement this function to create your own mapper and register it at the mapper manager
+ */
 export interface IMapper {
     map(rawSource: any): ViewerConfiguration;
 }
 
+/**
+ * This is a simple HTML mapper. 
+ * This mapper parses a single HTML element and returns the configuration from its attributes.
+ * it parses numbers and boolean values to the corresponding variable types.
+ * The following HTML element: 
+ *  <div test="1" random-flag="true" a.string.object="test"> will result in the following configuration:
+ * 
+ *  {
+ *      test: 1, //a number!
+ *      randomFlag: boolean, //camelCase and boolean
+ *      a: {
+ *          string: {
+ *              object: "test" //dot-separated object levels
+ *          }
+ *      }
+ *  }
+ */
 class HTMLMapper implements IMapper {
 
+    /**
+     * Map a specific element and get configuration from it
+     * @param element the HTML element to analyze. 
+     */
     map(element: HTMLElement): ViewerConfiguration {
 
         let config = {};