|
@@ -0,0 +1,6479 @@
|
|
|
+
|
|
|
+The MIT License (MIT)
|
|
|
+Copyright (c) 2014-2020 Nikolai Suslov and the Krestianstvo.org project contributors. (https:
|
|
|
+
|
|
|
+Virtual World Framework Apache 2.0 license (https:
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import { Helpers } from '/core/helpers.js';
|
|
|
+import { VirtualTime } from '/core/virtualTime.js';
|
|
|
+import { ReflectorClient } from '/core/reflectorClient.js';
|
|
|
+import { Luminary } from '/core/luminary.js';
|
|
|
+
|
|
|
+import { Logger } from '/core/vwf/utility/logger.js';
|
|
|
+import { KUtility } from '/core/vwf/utility/kutility.js';
|
|
|
+import { Utility } from '/core/vwf/utility/utility.js';
|
|
|
+import { XPath } from '/core/vwf/utility/xpath.js';
|
|
|
+
|
|
|
+import { Fabric } from '/core/vwf/fabric.js';
|
|
|
+import { ViewKernel } from '/core/vwf/view.js';
|
|
|
+import { ModelKernel } from '/core/vwf/model.js';
|
|
|
+import { Log } from '/core/vwf/model/stage/log.js';
|
|
|
+
|
|
|
+class VWF {
|
|
|
+
|
|
|
+ constructor(driverConf, proxy, doc, connectionConf) {
|
|
|
+ console.log("VWF constructor");
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ this.helpers = new Helpers;
|
|
|
+
|
|
|
+ this.driverConfiguration = driverConf || {};
|
|
|
+ this.proxy = proxy;
|
|
|
+ this.doc = doc;
|
|
|
+
|
|
|
+ this.isLuminary = connectionConf.luminary;
|
|
|
+ this.isLuminaryGlobalHB = connectionConf.luminaryHB;
|
|
|
+ this.luminaryGlobalHBPath = connectionConf.luminaryGlobalHBPath;
|
|
|
+
|
|
|
+
|
|
|
+ this.luminary = new Luminary;
|
|
|
+ this.reflectorClient = new ReflectorClient;
|
|
|
+ this.virtualTime = new VirtualTime;
|
|
|
+ window._Time = this.virtualTime;
|
|
|
+
|
|
|
+ this.applicationLoad = undefined;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.configuration = {
|
|
|
+ "log-level": "info",
|
|
|
+ "random-seed": +new Date,
|
|
|
+ "randomize-ids": true,
|
|
|
+ "humanize-ids": true,
|
|
|
+ "preserve-script-closures": false,
|
|
|
+ "load-timeout": 30
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.kutility = new KUtility;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.xpath = new XPath;
|
|
|
+ this.utility = new Utility;
|
|
|
+
|
|
|
+ this.viewModule = new Fabric({
|
|
|
+ id:"vwf/view"
|
|
|
+ }, 'View');
|
|
|
+
|
|
|
+ this.modelModule = new Fabric({
|
|
|
+ id:"vwf/model"
|
|
|
+ }, 'Model');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.logger = (new Logger).for("vwf", this, this.configuration["log-level"] );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.modules = [];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models = [];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views = [];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Object.defineProperty(this.models, "actual", {
|
|
|
+
|
|
|
+ get: function () {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var actual = this.map(function (model) {
|
|
|
+ return last(model);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (var propertyName in this) {
|
|
|
+ if (isNaN(Number(propertyName))) {
|
|
|
+ actual[propertyName] = last(this[propertyName]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function last(model) {
|
|
|
+ while (model.model) model = model.model;
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ return actual;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Object.defineProperty(this.views, "actual", {
|
|
|
+
|
|
|
+ get: function () {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var actual = this.map(function (model) {
|
|
|
+ return last(model);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (var propertyName in this) {
|
|
|
+ if (isNaN(Number(propertyName))) {
|
|
|
+ actual[propertyName] = last(this[propertyName]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function last(model) {
|
|
|
+ while (model.model) model = model.model;
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+ return actual;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.moniker_ = undefined;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.tickable = {
|
|
|
+
|
|
|
+
|
|
|
+ nodeIDs: [],
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.private = {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.components = this.private.components = {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ window.vwf = this;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.setProperty.entrants = {};
|
|
|
+ this.getProperty.entrants = {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.keyedCollectionPrototype = {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ create: function (name, changes, value) {
|
|
|
+
|
|
|
+ if (!this.hasOwn(name)) {
|
|
|
+
|
|
|
+ this.makeOwn("existing");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Object.defineProperty(this.existing, name,
|
|
|
+ self.configurable(value ? value : undefined));
|
|
|
+
|
|
|
+ if (changes) {
|
|
|
+
|
|
|
+ this.makeOwn("changes");
|
|
|
+
|
|
|
+ if (this.changes[name] !== "removed") {
|
|
|
+ this.changes[name] = "added";
|
|
|
+ } else {
|
|
|
+ this.changes[name] = "changed";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.container && this.containerMember) {
|
|
|
+ this.container.change(this.containerMember);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ delete: function (name, changes) {
|
|
|
+
|
|
|
+ if (this.hasOwn(name)) {
|
|
|
+
|
|
|
+ delete this.existing[name];
|
|
|
+
|
|
|
+ if (changes) {
|
|
|
+
|
|
|
+ this.makeOwn("changes");
|
|
|
+
|
|
|
+ if (this.changes[name] !== "added") {
|
|
|
+ this.changes[name] = "removed";
|
|
|
+ } else {
|
|
|
+ delete this.changes[name];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.container && this.containerMember) {
|
|
|
+ this.container.change(this.containerMember);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ change: function (name, value) {
|
|
|
+
|
|
|
+ if (this.hasOwn(name)) {
|
|
|
+
|
|
|
+ this.makeOwn("changes");
|
|
|
+
|
|
|
+ if (this.changes[name] !== "added") {
|
|
|
+ this.changes[name] = value ?
|
|
|
+ value : this.changes[name] || "changed";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.container && this.containerMember) {
|
|
|
+ this.container.change(this.containerMember);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ has: function (name) {
|
|
|
+ return name in this.existing;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ hasOwn: function (name) {
|
|
|
+ return Object.prototype.hasOwnProperty.call(this.existing, name);
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ makeOwn: function (fieldName) {
|
|
|
+
|
|
|
+ if (!this.hasOwnProperty(fieldName)) {
|
|
|
+
|
|
|
+ if (this[fieldName] instanceof Array) {
|
|
|
+ this[fieldName] = this[fieldName].slice();
|
|
|
+ } else if (typeof this[fieldName] === "object" && this[fieldName] !== null) {
|
|
|
+ this[fieldName] = Object.create(this[fieldName]);
|
|
|
+ } else {
|
|
|
+ this[fieldName] = this[fieldName];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ existing: Object.create(null
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ),
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ changes: {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ container: undefined,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ containerMember: undefined,
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.indexedCollectionPrototype = {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ create: function (id, changes) {
|
|
|
+
|
|
|
+ if (!this.hasOwn(id)) {
|
|
|
+
|
|
|
+ this.makeOwn("existing");
|
|
|
+ this.existing.push(id);
|
|
|
+
|
|
|
+ if (changes) {
|
|
|
+
|
|
|
+ this.makeOwn("changes");
|
|
|
+
|
|
|
+ var removedIndex = this.changes.removed ?
|
|
|
+ this.changes.removed.indexOf(id) : -1;
|
|
|
+
|
|
|
+ if (removedIndex < 0) {
|
|
|
+ this.changes.added = this.changes.added || [];
|
|
|
+ this.changes.added.push(id);
|
|
|
+ } else {
|
|
|
+ this.changes.removed.splice(removedIndex, 1);
|
|
|
+ this.changes.changed = this.changes.changed || [];
|
|
|
+ this.changes.changed.push(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.container && this.containerMember) {
|
|
|
+ this.container.change(this.containerMember);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ delete: function (id, changes) {
|
|
|
+
|
|
|
+ if (this.hasOwn(id)) {
|
|
|
+
|
|
|
+ this.existing.splice(this.existing.indexOf(id), 1);
|
|
|
+
|
|
|
+ if (changes) {
|
|
|
+
|
|
|
+ this.makeOwn("changes");
|
|
|
+
|
|
|
+ var addedIndex = this.changes.added ?
|
|
|
+ this.changes.added.indexOf(id) : -1;
|
|
|
+
|
|
|
+ if (addedIndex < 0) {
|
|
|
+ this.changes.removed = this.changes.removed || [];
|
|
|
+ this.changes.removed.push(id);
|
|
|
+ } else {
|
|
|
+ this.changes.added.splice(addedIndex, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.container && this.containerMember) {
|
|
|
+ this.container.change(this.containerMember);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ change: function (id) {
|
|
|
+
|
|
|
+ if (this.hasOwn(id)) {
|
|
|
+
|
|
|
+ this.makeOwn("changes");
|
|
|
+
|
|
|
+ var addedIndex = this.changes.added ?
|
|
|
+ this.changes.added.indexOf(id) : -1;
|
|
|
+
|
|
|
+ var changedIndex = this.changes.changed ?
|
|
|
+ this.changes.changed.indexOf(id) : -1;
|
|
|
+
|
|
|
+ if (addedIndex < 0 && changedIndex < 0) {
|
|
|
+ this.changes.changed = this.changes.changed || [];
|
|
|
+ this.changes.changed.push(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.container && this.containerMember) {
|
|
|
+ this.container.change(this.containerMember);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ has: function (id) {
|
|
|
+ return this.hasOwn(id);
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ hasOwn: function (id) {
|
|
|
+ return this.existing ? this.existing.indexOf(id) >= 0 : false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ makeOwn: function (fieldName) {
|
|
|
+
|
|
|
+ if (!this.hasOwnProperty(fieldName)) {
|
|
|
+
|
|
|
+ if (this[fieldName] instanceof Array) {
|
|
|
+ this[fieldName] = this[fieldName].slice();
|
|
|
+ } else if (typeof this[fieldName] === "object" && this[fieldName] !== null) {
|
|
|
+ this[fieldName] = Object.create(this[fieldName]);
|
|
|
+ } else {
|
|
|
+ this[fieldName] = this[fieldName];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ existing: [
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ],
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ changes: {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ container: undefined,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ containerMember: undefined,
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.eventCollectionPrototype = Object.create(self.keyedCollectionPrototype, {
|
|
|
+
|
|
|
+ create: {
|
|
|
+ value: function (name, changes, parameters) {
|
|
|
+ var value = parameters ? {
|
|
|
+ parameters: parameters.slice(),
|
|
|
+ } : {};
|
|
|
+
|
|
|
+ value.listeners = Object.create(self.indexedCollectionPrototype, {
|
|
|
+ container: self.enumerable(this),
|
|
|
+ containerMember: self.enumerable(name),
|
|
|
+ });
|
|
|
+
|
|
|
+ return self.keyedCollectionPrototype.create.call(this, name, changes, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.nodes = this.private.nodes = {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ create: function (nodeID, prototypeID, behaviorIDs, nodeURI, nodeName, parentID) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let selfNode = this;
|
|
|
+ var prototypeNode = behaviorIDs.reduce(function (prototypeNode, behaviorID) {
|
|
|
+ return selfNode.proxy(prototypeNode, selfNode.existing[behaviorID]);
|
|
|
+ }, this.existing[prototypeID]);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var parentNode = this.existing[parentID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!parentNode) {
|
|
|
+ this.globals[nodeID] = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return this.existing[nodeID] = {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ uri: nodeURI,
|
|
|
+ name: nodeName,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ properties: Object.create(self.keyedCollectionPrototype, {
|
|
|
+ existing: self.enumerable(Object.create(prototypeNode ?
|
|
|
+ prototypeNode.properties.existing : null)),
|
|
|
+ }),
|
|
|
+
|
|
|
+ methods: Object.create(self.keyedCollectionPrototype, {
|
|
|
+ existing: self.enumerable(Object.create(prototypeNode ?
|
|
|
+ prototypeNode.methods.existing : null)),
|
|
|
+ }),
|
|
|
+
|
|
|
+ events: Object.create(self.eventCollectionPrototype, {
|
|
|
+ existing: self.enumerable(Object.create(prototypeNode ?
|
|
|
+ prototypeNode.events.existing : null)),
|
|
|
+ }),
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ patchable: !!(nodeURI ||
|
|
|
+ parentNode && !parentNode.initialized && parentNode.patchable),
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ initialized: false,
|
|
|
+
|
|
|
+ childsDeleted: {}
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ initialize: function (nodeID) {
|
|
|
+
|
|
|
+ if (this.existing[nodeID]) {
|
|
|
+
|
|
|
+ this.existing[nodeID].initialized = true;
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ delete: function (nodeID, parentID) {
|
|
|
+
|
|
|
+ if (this.existing[nodeID] && this.existing[parentID]) {
|
|
|
+
|
|
|
+ this.existing[parentID].childsDeleted[this.existing[nodeID].name] = nodeID;
|
|
|
+
|
|
|
+ delete this.existing[nodeID];
|
|
|
+ delete this.globals[nodeID];
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ proxy: function (prototypeNode, behaviorNode) {
|
|
|
+
|
|
|
+ return {
|
|
|
+
|
|
|
+ properties: {
|
|
|
+ existing: Object.create(
|
|
|
+ prototypeNode ? prototypeNode.properties.existing : null,
|
|
|
+ propertyDescriptorsFor(behaviorNode.properties.existing)
|
|
|
+ ),
|
|
|
+ },
|
|
|
+
|
|
|
+ methods: {
|
|
|
+ existing: Object.create(
|
|
|
+ prototypeNode ? prototypeNode.methods.existing : null,
|
|
|
+ propertyDescriptorsFor(behaviorNode.methods.existing)
|
|
|
+ ),
|
|
|
+ },
|
|
|
+
|
|
|
+ events: {
|
|
|
+ existing: Object.create(
|
|
|
+ prototypeNode ? prototypeNode.events.existing : null,
|
|
|
+ propertyDescriptorsFor(behaviorNode.events.existing)
|
|
|
+ ),
|
|
|
+ },
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function propertyDescriptorsFor(collectionExisting) {
|
|
|
+
|
|
|
+ return Object.keys(collectionExisting).reduce(
|
|
|
+
|
|
|
+ function (propertiesObject, memberName) {
|
|
|
+
|
|
|
+ propertiesObject[memberName] = {
|
|
|
+ get: function () {
|
|
|
+ return collectionExisting[memberName]
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ };
|
|
|
+
|
|
|
+ return propertiesObject;
|
|
|
+ },
|
|
|
+
|
|
|
+ {}
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ existing: {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ globals: {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loadConfiguration(app, userLib, cb
|
|
|
+
|
|
|
+
|
|
|
+ { viewInitializers } */
|
|
|
+ ) {
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ let applicationLoad = app;
|
|
|
+ let userLibraries = userLib || {};
|
|
|
+
|
|
|
+ var applicationConfig = {};
|
|
|
+ let callback = cb;
|
|
|
+
|
|
|
+ var initializers = {
|
|
|
+ model: [
|
|
|
+ {
|
|
|
+ library: "/core/vwf/model/ohm",
|
|
|
+ active: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ library: "/core/vwf/model/javascript",
|
|
|
+ active: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ library: "/core/vwf/model/object",
|
|
|
+ active: true
|
|
|
+ }
|
|
|
+
|
|
|
+ ],
|
|
|
+ view: [
|
|
|
+
|
|
|
+ {
|
|
|
+ library: "/core/vwf/view/ohm",
|
|
|
+ active: true
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ library: "/core/vwf/view/document",
|
|
|
+ active: true
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ ]
|
|
|
+ };
|
|
|
+
|
|
|
+ mapLibraryName(initializers["model"]);
|
|
|
+ mapLibraryName(initializers["view"]);
|
|
|
+
|
|
|
+ function mapLibraryName(array) {
|
|
|
+ for (var i = 0; i < array.length; i++) {
|
|
|
+ array[array[i].library] = array[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function getActiveLibraries(libraryList, includeParameters) {
|
|
|
+ var activeLibraryList = [];
|
|
|
+ for (var i = 0; i < libraryList.length; i++) {
|
|
|
+ if (libraryList[i].active) {
|
|
|
+ if (includeParameters) {
|
|
|
+ var activeLibrary = {};
|
|
|
+ activeLibrary[libraryList[i].library] = libraryList[i].parameters;
|
|
|
+ activeLibraryList.push(activeLibrary);
|
|
|
+ } else {
|
|
|
+ activeLibraryList.push(libraryList[i].library);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return activeLibraryList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let configLibraries = this.driverConfiguration;
|
|
|
+
|
|
|
+ if (configLibraries && typeof configLibraries == "object") {
|
|
|
+ if (typeof configLibraries.configuration == "object") {
|
|
|
+ applicationConfig = configLibraries.configuration;
|
|
|
+ }
|
|
|
+ Object.keys(configLibraries).forEach(function (libraryType) {
|
|
|
+ if (libraryType == 'info' && configLibraries[libraryType]["title"]) {
|
|
|
+
|
|
|
+ document.querySelector('title').innerHTML = configLibraries[libraryType]["title"]
|
|
|
+ }
|
|
|
+ if (!userLibraries[libraryType]) {
|
|
|
+ userLibraries[libraryType] = {};
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object.keys(configLibraries[libraryType]).forEach(function (libraryName) {
|
|
|
+ var disabled = false;
|
|
|
+ if (!disabled) {
|
|
|
+ if (userLibraries[libraryType][libraryName] == undefined) {
|
|
|
+ userLibraries[libraryType][libraryName] = configLibraries[libraryType][libraryName];
|
|
|
+ } else if (typeof userLibraries[libraryType][libraryName] == "object" && typeof configLibraries[libraryType][libraryName] == "object") {
|
|
|
+ userLibraries[libraryType][libraryName] = Object.assign({}, configLibraries[libraryType][libraryName], userLibraries[libraryType][libraryName]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object.keys(userLibraries).forEach(function (libraryType) {
|
|
|
+ if (initializers[libraryType]) {
|
|
|
+ Object.keys(userLibraries[libraryType]).forEach(function (libraryName) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(!initializers[libraryType][libraryName]){
|
|
|
+
|
|
|
+ initializers[libraryType].unshift({'library': libraryName});
|
|
|
+ initializers[libraryType][libraryName] = initializers[libraryType][0];
|
|
|
+
|
|
|
+ }
|
|
|
+ initializers[libraryType][libraryName].active = true;
|
|
|
+ if (userLibraries[libraryType][libraryName] && userLibraries[libraryType][libraryName] != "") {
|
|
|
+ if (typeof initializers[libraryType][libraryName].parameters == "object") {
|
|
|
+
|
|
|
+ initializers[libraryType][libraryName].parameters = Object.assign({}, initializers[libraryType][libraryName].parameters, userLibraries[libraryType][libraryName]);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ initializers[libraryType][libraryName].parameters = userLibraries[libraryType][libraryName];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.initialize(self.applicationLoad, getActiveLibraries(initializers["model"], true), getActiveLibraries(initializers["view"], true), callback);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async initialize(
|
|
|
+
|
|
|
+ [ viewInitializers ] */
|
|
|
+ ) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ var args = Array.prototype.slice.call(arguments);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof args[0] != "object" || !(args[0] instanceof Array)) {
|
|
|
+ this.applicationLoad = args.shift();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var modelInitializers = args.shift() || [];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var viewInitializers = args.shift() || [];
|
|
|
+
|
|
|
+ var callback = args.shift();
|
|
|
+ var compatibilityStatus = {
|
|
|
+ compatible: true,
|
|
|
+ errors: {}
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let modelKernel = new ModelKernel({
|
|
|
+ id:"vwf/kernel/model"
|
|
|
+ }).factory();
|
|
|
+ this.models.kernel = modelKernel.create(vwf);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (let modelInitializer of modelInitializers) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (modelInitializer) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof modelInitializer == "object" && modelInitializer != null) {
|
|
|
+ var modelName = Object.keys(modelInitializer)[0];
|
|
|
+ var modelArguments = modelInitializer[modelName];
|
|
|
+ } else {
|
|
|
+ var modelName = modelInitializer;
|
|
|
+ var modelArguments = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ let log = new Log({
|
|
|
+ id:"vwf/model/stage/log"
|
|
|
+ }).factory();
|
|
|
+
|
|
|
+
|
|
|
+ var modelMod = undefined;
|
|
|
+ await import(modelName+'.js').then(m=>{
|
|
|
+ modelMod = (new m.default({
|
|
|
+ id: modelName
|
|
|
+ }).factory())
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ var model = modelMod.create(
|
|
|
+ this.models.kernel,
|
|
|
+ [log],
|
|
|
+
|
|
|
+ {},
|
|
|
+ [].concat(modelArguments || [])
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ if (model) {
|
|
|
+ this.models.push(model);
|
|
|
+ this.models[modelName] = model;
|
|
|
+
|
|
|
+ if (modelName == "/core/vwf/model/javascript") {
|
|
|
+ this.models.javascript = model;
|
|
|
+ while (this.models.javascript.model) this.models.javascript = this.models.javascript.model;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (modelName == "/core/vwf/model/object") {
|
|
|
+ this.models.object = model;
|
|
|
+ while (this.models.object.model) this.models.object = this.models.object.model;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (model.model.compatibilityStatus) {
|
|
|
+ if (!model.model.compatibilityStatus.compatible) {
|
|
|
+ compatibilityStatus.compatible = false;
|
|
|
+ Object.assign(compatibilityStatus.errors, model.model.compatibilityStatus.errors);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let viewKernel = new ViewKernel({
|
|
|
+ id:"vwf/kernel/view"
|
|
|
+ }).factory();
|
|
|
+
|
|
|
+ this.views.kernel = viewKernel.create(vwf);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for( let viewInitializer of viewInitializers) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (viewInitializer) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof viewInitializer == "object" && viewInitializer != null) {
|
|
|
+ var viewName = Object.keys(viewInitializer)[0];
|
|
|
+ var viewArguments = viewInitializer[viewName];
|
|
|
+ } else {
|
|
|
+ var viewName = viewInitializer;
|
|
|
+ var viewArguments = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var modelPeer = this.models.actual[viewName.replace("view/", "model/")];
|
|
|
+
|
|
|
+
|
|
|
+ var viewMod = undefined;
|
|
|
+ await import(viewName +'.js').then(m=>{
|
|
|
+ viewMod = (new m.default({
|
|
|
+ id: viewName
|
|
|
+ }).factory())
|
|
|
+ })
|
|
|
+
|
|
|
+ var view = viewMod.create(
|
|
|
+ this.views.kernel,
|
|
|
+ [],
|
|
|
+ modelPeer && modelPeer.state || {},
|
|
|
+ [].concat(viewArguments || [])
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (view) {
|
|
|
+ this.views.push(view);
|
|
|
+ this.views[viewName] = view;
|
|
|
+
|
|
|
+ if (view.compatibilityStatus) {
|
|
|
+ if (!view.compatibilityStatus.compatible) {
|
|
|
+ compatibilityStatus.compatible = false;
|
|
|
+ Object.assign(compatibilityStatus.errors, view.compatibilityStatus.errors);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (callback) {
|
|
|
+ callback(compatibilityStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ await _app.getApplicationState()
|
|
|
+ .then(res => {
|
|
|
+ return self.chooseConnection(res)
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ self.ready(self.application, res)
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ready(component_uri_or_json_or_object, path) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.isLuminary) {
|
|
|
+
|
|
|
+
|
|
|
+ this.namespace_ = this.luminary.namespace;
|
|
|
+ this.moniker_ = this.luminary.clientID;
|
|
|
+ console.log('namespace: ' + this.namespace_, ' for client: ' + this.moniker_);
|
|
|
+
|
|
|
+
|
|
|
+ var heartbeat = _lum.get(this.namespace_).get('heartbeat');
|
|
|
+
|
|
|
+ if (this.isLuminaryGlobalHB && this.luminaryGlobalHBPath) {
|
|
|
+ let hbPath = this.luminaryGlobalHBPath.split('/');
|
|
|
+ var heartbeat = _LCSDB;
|
|
|
+ hbPath.forEach(el => {
|
|
|
+ heartbeat = heartbeat.get(el);
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ this.luminary.subscribeOnHeartbeat(heartbeat);
|
|
|
+ this.luminary.subscribeOnMessages();
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ this.reflectorClient.connect(component_uri_or_json_or_object, path);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ log() {
|
|
|
+
|
|
|
+ this.respond(undefined, "log", undefined, undefined, arguments);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setState(appState, callback_async ) {
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ this.logger.debuggx("setState");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var applicationState = appState;
|
|
|
+
|
|
|
+ if (applicationState.init) {
|
|
|
+ applicationState = JSON.parse(localStorage.getItem('lcs_app')).saveObject
|
|
|
+ }
|
|
|
+
|
|
|
+ if (applicationState.configuration) {
|
|
|
+ this.configuration = applicationState.configuration;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (applicationState.kernel) {
|
|
|
+ if (applicationState.kernel.time !== undefined) self.virtualTime.now = applicationState.kernel.time;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var nodes = applicationState.nodes || [];
|
|
|
+ var annotations = applicationState.annotations || {};
|
|
|
+
|
|
|
+ var nodeIndex = 0;
|
|
|
+
|
|
|
+ async.forEachSeries(nodes, function (nodeComponent, each_callback_async /* ( err ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var nodeAnnotation = self.nodes.length > 1 || applicationState.annotations ?
|
|
|
+ annotations[nodeIndex] : "application";
|
|
|
+
|
|
|
+ self.createNode(nodeComponent, nodeAnnotation, function (nodeID) /* async */ {
|
|
|
+ each_callback_async(undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ nodeIndex++;
|
|
|
+
|
|
|
+ }, function (err) /* async */ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.virtualTime.filterQueue();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (applicationState.queue) {
|
|
|
+ self.virtualTime.time = applicationState.queue.time;
|
|
|
+ self.virtualTime.insert(applicationState.queue.queue || []);
|
|
|
+ }
|
|
|
+
|
|
|
+ callback_async && callback_async();
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getState(full, normalize) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("getState", full, normalize);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var applicationState = {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ configuration: self.configuration,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ kernel: {
|
|
|
+ time: self.virtualTime.now,
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodes: [
|
|
|
+ this.getNode("proxy/clients.vwf", full),
|
|
|
+ this.getNode(this.application(), full),
|
|
|
+ ],
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ annotations: {
|
|
|
+ 1: "application",
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ queue: self.virtualTime.stateQueue
|
|
|
+
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (normalize) {
|
|
|
+ applicationState = self.utility.transform(
|
|
|
+ applicationState, self.utility.transforms.hash);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return applicationState;
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ hashState() {
|
|
|
+
|
|
|
+ this.logger.debuggx("hashState");
|
|
|
+
|
|
|
+ var applicationState = this.getState(true, true);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var hashn = this.hashNode(applicationState.nodes[0]);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var hashq = "q" + Crypto.MD5(JSON.stringify(applicationState.queue)).toString().substring(0, 16);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var hashk = "k" + Crypto.MD5(JSON.stringify(applicationState.kernel)).toString().substring(0, 16);
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return hashn + ":" + hashq + ":" + hashk;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ createNode (nodeComponent, nodeAnnotation, baseURI, callback_async ) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof nodeAnnotation == "function" || nodeAnnotation instanceof Function) {
|
|
|
+ callback_async = nodeAnnotation;
|
|
|
+ baseURI = undefined;
|
|
|
+ nodeAnnotation = undefined;
|
|
|
+ } else if (typeof baseURI == "function" || baseURI instanceof Function) {
|
|
|
+ callback_async = baseURI;
|
|
|
+ baseURI = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debuggx("createNode", function () {
|
|
|
+ return [JSON.stringify(self.loggableComponent(nodeComponent)), nodeAnnotation];
|
|
|
+ });
|
|
|
+
|
|
|
+ var nodePatch;
|
|
|
+
|
|
|
+ if (self.componentIsDescriptor(nodeComponent) && nodeComponent.patches) {
|
|
|
+ nodePatch = nodeComponent;
|
|
|
+ nodeComponent = nodeComponent.patches;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var nodeURI, nodeDescriptor, nodeID;
|
|
|
+
|
|
|
+ async.series([
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+ if (self.componentIsURI(nodeComponent)) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeURI = nodeComponent
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!self.components[nodeURI]) {
|
|
|
+
|
|
|
+ self.components[nodeURI] = [];
|
|
|
+
|
|
|
+ self.loadComponent(nodeURI, undefined, function (nodeDescriptor) /* async */ {
|
|
|
+ nodeComponent = nodeDescriptor;
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ }, function (errorMessage) {
|
|
|
+ nodeComponent = undefined;
|
|
|
+ series_callback_async(errorMessage, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else if (self.components[nodeURI] instanceof Array) {
|
|
|
+
|
|
|
+ callback_async && self.components[nodeURI].push(callback_async);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (nodePatch) {
|
|
|
+ self.setNode(self.components[nodeURI], nodePatch, function (nodeID) /* async */ {
|
|
|
+ callback_async && callback_async(self.components[nodeURI]);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ callback_async && callback_async(self.components[nodeURI]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+ if (self.componentIsDescriptor(nodeComponent) && nodeComponent.includes && self.componentIsURI(nodeComponent.includes)) {
|
|
|
+
|
|
|
+ var prototypeURI = nodeComponent.includes
|
|
|
+
|
|
|
+ self.loadComponent(prototypeURI, undefined, function (prototypeDescriptor) /* async */ {
|
|
|
+ prototypeDescriptor = self.resolvedDescriptor(prototypeDescriptor, prototypeURI);
|
|
|
+ nodeComponent = self.mergeDescriptors(nodeComponent, prototypeDescriptor);
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ }, function (errorMessage) {
|
|
|
+ nodeComponent = undefined;
|
|
|
+ series_callback_async(errorMessage, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+ if (self.componentIsDescriptor(nodeComponent)) {
|
|
|
+
|
|
|
+ nodeDescriptor = nodeComponent;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.createChild(0, nodeAnnotation, nodeDescriptor, nodeURI, function (nodeID) /* async */ {
|
|
|
+ nodeComponent = nodeID;
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+ if (self.componentIsID(nodeComponent) || self.components[nodeComponent] instanceof Array) {
|
|
|
+
|
|
|
+ nodeID = nodeComponent;
|
|
|
+
|
|
|
+ if (nodePatch) {
|
|
|
+ self.setNode(nodeID, nodePatch, function (nodeID) /* async */ {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ ], function (err, results) /* async */ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (nodeURI) {
|
|
|
+ var callbacks_async = self.components[nodeURI];
|
|
|
+ self.components[nodeURI] = nodeID;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ callback_async && callback_async(nodeID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (nodeURI) {
|
|
|
+ callbacks_async.forEach(function (callback_async) {
|
|
|
+ callback_async && callback_async(nodeID);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ deleteNode (nodeID) {
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ this.logger.debuggx("deleteNode", nodeID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var parentID = this.parent(nodeID);
|
|
|
+
|
|
|
+ if (parentID !== 0) {
|
|
|
+
|
|
|
+ var nodeIndex = this.children(parentID).indexOf(nodeID);
|
|
|
+
|
|
|
+ if (nodeIndex < 0) {
|
|
|
+ nodeIndex = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.models.kernel.enabled()) {
|
|
|
+ this.fireEvent(parentID, ["children", "removed"],
|
|
|
+ [nodeIndex, this.kutility.nodeReference(nodeID)]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Object.keys(self.components).some(function (nodeURI) {
|
|
|
+ if (self.components[nodeURI] == nodeID) {
|
|
|
+ delete self.components[nodeURI];
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ self.children(nodeID).forEach(function(child)
|
|
|
+ {
|
|
|
+ self.deleteNode(child);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ model.deletingNode && model.deletingNode(nodeID);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.nodes.delete(nodeID, parentID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.deletedNode && view.deletedNode(nodeID);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setNode (nodeID, nodeComponent, callback_async ) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ self.logger.debuggx("setNode", function () {
|
|
|
+ return [nodeID, JSON.stringify(self.loggableComponent(nodeComponent))];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = self.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.object.internals(nodeID, nodeComponent);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.kernel.disable();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeComponent.properties && Object.keys(nodeComponent.properties).forEach(function (propertyName) {
|
|
|
+ var propertyValue = nodeComponent.properties[propertyName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var creating = !node.properties.has(propertyName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (self.valueHasAccessors(propertyValue) && propertyValue.node) {
|
|
|
+ propertyValue = self.kutility.nodeReference(propertyValue.node);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (creating) {
|
|
|
+ self.createProperty(nodeID, propertyName, propertyValue);
|
|
|
+ } else {
|
|
|
+ self.setProperty(nodeID, propertyName, propertyValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeComponent.methods && Object.keys(nodeComponent.methods).forEach(function (methodName) {
|
|
|
+ var methodHandler = nodeComponent.methods[methodName];
|
|
|
+
|
|
|
+ var creating = !node.methods.has(methodName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (creating) {
|
|
|
+ self.createMethod(nodeID, methodName, methodHandler.parameters, methodHandler.body);
|
|
|
+ } else {
|
|
|
+ self.setMethod(nodeID, methodName, methodHandler);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeComponent.events && Object.keys(nodeComponent.events).forEach(function (eventName) {
|
|
|
+ var eventDescriptor = nodeComponent.events[eventName];
|
|
|
+
|
|
|
+ var creating = !node.events.has(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (creating) {
|
|
|
+ self.createEvent(nodeID, eventName, eventDescriptor.parameters);
|
|
|
+ self.setEvent(nodeID, eventName, eventDescriptor);
|
|
|
+ } else {
|
|
|
+ self.setEvent(nodeID, eventName, eventDescriptor);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.kernel.enable();
|
|
|
+
|
|
|
+
|
|
|
+ async.series([
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async.forEach(Object.keys(nodeComponent.children || {}), function (childName, each_callback_async /* ( err ) */ ) {
|
|
|
+
|
|
|
+ var creating = !self.nodeHasOwnChild.call(self, nodeID, childName);
|
|
|
+ if (creating) {
|
|
|
+ self.createChild(nodeID, childName, nodeComponent.children[childName], undefined, function (childID) /* async */ {
|
|
|
+ each_callback_async(undefined);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.setNode(nodeComponent.children[childName].id || nodeComponent.children[childName].patches,
|
|
|
+ nodeComponent.children[childName],
|
|
|
+ function (childID) /* async */ {
|
|
|
+ each_callback_async(undefined);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, function (err) /* async */ {
|
|
|
+ let deletedProtoNodes = nodeComponent.childrenDeleted;
|
|
|
+
|
|
|
+ if (deletedProtoNodes) {
|
|
|
+ let childNames = Object.keys(nodeComponent.childrenDeleted)
|
|
|
+ if (childNames) {
|
|
|
+ childNames.forEach(el => {
|
|
|
+ console.log("DELETE CHILD HERE!: ", el);
|
|
|
+ self.deleteChild(nodeID, el);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ series_callback_async(err, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var scripts = nodeComponent.scripts ? [].concat(nodeComponent.scripts) : [];
|
|
|
+
|
|
|
+ var baseURI = self.uri(nodeID, true);
|
|
|
+
|
|
|
+ async.map(scripts, function (script, map_callback_async /* ( err, result ) */ ) {
|
|
|
+
|
|
|
+ if (self.valueHasType(script)) {
|
|
|
+ if (script.source) {
|
|
|
+ self.loadScript(script.source, baseURI, function (scriptText) /* async */ {
|
|
|
+ map_callback_async(undefined, {
|
|
|
+ text: scriptText,
|
|
|
+ type: script.type
|
|
|
+ });
|
|
|
+ }, function (errorMessage) {
|
|
|
+ map_callback_async(errorMessage, undefined);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ map_callback_async(undefined, {
|
|
|
+ text: script.text,
|
|
|
+ type: script.type
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ map_callback_async(undefined, {
|
|
|
+ text: script,
|
|
|
+ type: undefined
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }, function (err, scripts) /* async */ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.kernel.disable();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ scripts.forEach(function (script) {
|
|
|
+ self.execute(nodeID, script.text, script.type);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.kernel.enable();
|
|
|
+
|
|
|
+ series_callback_async(err, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ ], function (err, results) /* async */ {
|
|
|
+
|
|
|
+ callback_async && callback_async(nodeID);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return nodeComponent;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getNode(nodeID, full, normalize, proto) {
|
|
|
+
|
|
|
+ this.logger.debuggx("getNode", nodeID, full);
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var nodeComponent = {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var patches = this.models.object.patches(nodeID),
|
|
|
+ patched = false;
|
|
|
+
|
|
|
+ if (node.patchable) {
|
|
|
+ nodeComponent.patches = node.uri || nodeID;
|
|
|
+ } else {
|
|
|
+ nodeComponent.id = nodeID;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (full || !node.patchable) {
|
|
|
+
|
|
|
+ var intrinsics = this.intrinsics(nodeID);
|
|
|
+
|
|
|
+ var prototypeID = this.prototype(nodeID);
|
|
|
+
|
|
|
+ if (prototypeID === undefined) {
|
|
|
+ nodeComponent.extends = null;
|
|
|
+ } else if (prototypeID !== this.kutility.protoNodeURI) {
|
|
|
+ nodeComponent.extends = this.getNode(prototypeID);
|
|
|
+ }
|
|
|
+
|
|
|
+ nodeComponent.implements = this.behaviors(nodeID).map(function (behaviorID) {
|
|
|
+ return this.getNode(behaviorID);
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ nodeComponent.implements.length || delete nodeComponent.implements;
|
|
|
+
|
|
|
+ if (intrinsics.source !== undefined) nodeComponent.source = intrinsics.source;
|
|
|
+ if (intrinsics.type !== undefined) nodeComponent.type = intrinsics.type;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (full || !node.patchable || patches.internals) {
|
|
|
+
|
|
|
+ var internals = this.models.object.internals(nodeID);
|
|
|
+
|
|
|
+ nodeComponent.sequence = internals.sequence;
|
|
|
+ nodeComponent.random = internals.random;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.kernel.disable();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (full || !node.patchable) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeComponent.properties = this.getProperties(nodeID);
|
|
|
+
|
|
|
+
|
|
|
+ let jsProps = this.models.javascript.nodes[nodeID];
|
|
|
+ let getters = jsProps.private.getters;
|
|
|
+ let setters = jsProps.private.setters;
|
|
|
+
|
|
|
+ Object.keys(nodeComponent.properties).forEach(el => {
|
|
|
+
|
|
|
+ if (Object.keys(getters).includes(el) || Object.keys(setters).includes(el)) {
|
|
|
+
|
|
|
+ let prop = {
|
|
|
+ value: nodeComponent.properties[el]
|
|
|
+ }
|
|
|
+
|
|
|
+ if (typeof getters[el] == 'function') {
|
|
|
+ let fn = getters[el].toString()
|
|
|
+ prop.get = fn.slice(fn.indexOf("{") + 1, fn.lastIndexOf("}"));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ prop.get = ""
|
|
|
+ }
|
|
|
+
|
|
|
+ if (typeof setters[el] == 'function') {
|
|
|
+ let fn = setters[el].toString()
|
|
|
+ prop.set = fn.slice(fn.indexOf("{") + 1, fn.lastIndexOf("}"));
|
|
|
+ } else {
|
|
|
+ prop.set = ""
|
|
|
+ }
|
|
|
+
|
|
|
+ nodeComponent.properties[el] = prop
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ for (var propertyName in nodeComponent.properties) {
|
|
|
+ var propertyValue = nodeComponent.properties[propertyName];
|
|
|
+
|
|
|
+ if (propertyValue === undefined) {
|
|
|
+ delete nodeComponent.properties[propertyName];
|
|
|
+ } else if (this.kutility.valueIsNodeReference(propertyValue)) {
|
|
|
+
|
|
|
+ nodeComponent.properties[propertyName] = {
|
|
|
+ node: propertyValue.id
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (node.properties.changes) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeComponent.properties = {};
|
|
|
+
|
|
|
+ Object.keys(node.properties.changes).forEach(function (propertyName) {
|
|
|
+
|
|
|
+ if (node.properties.changes[propertyName] !== "removed") {
|
|
|
+
|
|
|
+ var propertyValue = this.getProperty(nodeID, propertyName);
|
|
|
+
|
|
|
+ if (this.kutility.valueIsNodeReference(propertyValue)) {
|
|
|
+
|
|
|
+ nodeComponent.properties[propertyName] = {
|
|
|
+ node: propertyValue.id
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ nodeComponent.properties[propertyName] = propertyValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Object.keys(nodeComponent.properties).length == 0) {
|
|
|
+ delete nodeComponent.properties;
|
|
|
+ } else {
|
|
|
+ patched = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (full || !node.patchable) {
|
|
|
+
|
|
|
+ Object.keys(node.methods.existing).forEach(function (methodName) {
|
|
|
+ nodeComponent.methods = nodeComponent.methods || {};
|
|
|
+ nodeComponent.methods[methodName] = this.getMethod(nodeID, methodName);
|
|
|
+ patched = true;
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ } else if (node.methods.changes) {
|
|
|
+
|
|
|
+ Object.keys(node.methods.changes).forEach(function (methodName) {
|
|
|
+ if (node.methods.changes[methodName] !== "removed") {
|
|
|
+ nodeComponent.methods = nodeComponent.methods || {};
|
|
|
+ nodeComponent.methods[methodName] = this.getMethod(nodeID, methodName);
|
|
|
+ patched = true;
|
|
|
+ }
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var events = full || !node.patchable ?
|
|
|
+ node.events.existing : node.events.changes;
|
|
|
+
|
|
|
+ if (events) {
|
|
|
+ Object.keys(events).forEach(function (eventName) {
|
|
|
+ nodeComponent.events = nodeComponent.events || {};
|
|
|
+ nodeComponent.events[eventName] = this.getEvent(nodeID, eventName);
|
|
|
+ patched = true;
|
|
|
+ }, this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.kernel.enable();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeComponent.children = {};
|
|
|
+
|
|
|
+ this.children(nodeID).forEach(function (childID) {
|
|
|
+ nodeComponent.children[this.name(childID)] = this.getNode(childID, full);
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ for (var childName in nodeComponent.children) {
|
|
|
+ if (nodeComponent.children[childName] === undefined) {
|
|
|
+ delete nodeComponent.children[childName];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeComponent.childrenDeleted = {};
|
|
|
+
|
|
|
+ Object.keys(node.childsDeleted).forEach((childName) => {
|
|
|
+ nodeComponent.childrenDeleted[childName] = null;
|
|
|
+ patched = true;
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (Object.keys(nodeComponent.children).length == 0) {
|
|
|
+ delete nodeComponent.children;
|
|
|
+ } else {
|
|
|
+ patched = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (node.scripts) {
|
|
|
+ console.log("SCRIPTS: ", node.scripts)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (normalize) {
|
|
|
+ nodeComponent = self.utility.transform(
|
|
|
+ nodeComponent, self.utility.transforms.hash);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (full || !node.patchable || patched) {
|
|
|
+ return nodeComponent;
|
|
|
+ } else if (node.uri) {
|
|
|
+ return node.uri;
|
|
|
+ } else {
|
|
|
+ return undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ hashNode(nodeID) {
|
|
|
+
|
|
|
+ this.logger.debuggx("hashNode", typeof nodeID == "object" ? nodeID.id : nodeID);
|
|
|
+
|
|
|
+ var nodeComponent = typeof nodeID == "object" ? nodeID : this.getNode(nodeID, true, true);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var internal = {
|
|
|
+ id: nodeComponent.id,
|
|
|
+ source: nodeComponent.source,
|
|
|
+ type: nodeComponent.type
|
|
|
+ };
|
|
|
+
|
|
|
+ internal.source === undefined && delete internal.source;
|
|
|
+ internal.type === undefined && delete internal.type;
|
|
|
+
|
|
|
+ var hashi = "i" + Crypto.MD5(JSON.stringify(internal)).toString().substring(0, 16);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var properties = nodeComponent.properties || {};
|
|
|
+
|
|
|
+ var hashp = Object.keys(properties).length ?
|
|
|
+ "p" + Crypto.MD5(JSON.stringify(properties)).toString().substring(0, 16) : undefined;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var children = nodeComponent.children || {};
|
|
|
+
|
|
|
+ var hashc = Object.keys(children).length ?
|
|
|
+ "c" + Crypto.MD5(JSON.stringify(children)).toString().substring(0, 16) : undefined;
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return hashi + (hashp ? "." + hashp : "") + (hashc ? "/" + hashc : "");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ createChild(nodeID, childName, childComponent, childURI, callback_async ) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ this.logger.debuggx("createChild", function () {
|
|
|
+ return [nodeID, childName, JSON.stringify(self.loggableComponent(childComponent)), childURI];
|
|
|
+ });
|
|
|
+
|
|
|
+ childComponent = self.normalizedComponent(childComponent);
|
|
|
+
|
|
|
+ var child, childID, childIndex, childPrototypeID, childBehaviorIDs = [],
|
|
|
+ deferredInitializations = {};
|
|
|
+
|
|
|
+ var resolvedSource;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var replicating = !!childComponent.id;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (childComponent.id) {
|
|
|
+ childID = childComponent.id;
|
|
|
+ childIndex = this.children(nodeID).length;
|
|
|
+ } else if (nodeID === 0) {
|
|
|
+ childID = childURI ||
|
|
|
+ Crypto.MD5(JSON.stringify(childComponent)).toString();
|
|
|
+ childIndex = childURI;
|
|
|
+ } else {
|
|
|
+ childID = nodeID + ":" + this.sequence(nodeID) +
|
|
|
+ (this.configuration["randomize-ids"] ? "-" + ("0" + Math.floor(this.random(nodeID) * 100)).slice(-2) : "") +
|
|
|
+ (this.configuration["humanize-ids"] ? "-" + childName.replace(/[^0-9A-Za-z_-]+/g, "-") : "");
|
|
|
+ childIndex = this.children(nodeID).length;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ child = self.nodes.create(childID, childPrototypeID, childBehaviorIDs, childURI, childName, nodeID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.object.creatingNode(nodeID, childID, childPrototypeID, childBehaviorIDs,
|
|
|
+ childComponent.source, childComponent.type, childIndex, childName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var baseURI = this.uri(childID, true);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async.series([
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (self.componentIsDescriptor(childComponent) && childComponent.includes && self.componentIsURI(childComponent.includes)) {
|
|
|
+
|
|
|
+ var prototypeURI = childComponent.includes
|
|
|
+
|
|
|
+ var sync = true;
|
|
|
+
|
|
|
+ self.loadComponent(prototypeURI, undefined, function (prototypeDescriptor) /* async */ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ prototypeDescriptor = self.resolvedDescriptor(prototypeDescriptor, prototypeURI);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ childComponent = self.mergeDescriptors(childComponent, prototypeDescriptor);
|
|
|
+
|
|
|
+ if (sync) {
|
|
|
+
|
|
|
+ self.virtualTime.suspend("before beginning " + childID);
|
|
|
+
|
|
|
+ async.nextTick(function () {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ self.virtualTime.resume("after beginning " + childID);
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ }, function (errorMessage) {
|
|
|
+ childComponent = undefined;
|
|
|
+ series_callback_async(errorMessage, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ sync = false;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ self.virtualTime.suspend("before beginning " + childID);
|
|
|
+
|
|
|
+ async.nextTick(function () {
|
|
|
+ series_callback_async(undefined, undefined);
|
|
|
+ self.virtualTime.resume("after beginning " + childID);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async.parallel([
|
|
|
+
|
|
|
+ function (parallel_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (childComponent.extends !== null) {
|
|
|
+
|
|
|
+ var prototypeComponent = childComponent.extends || self.kutility.protoNodeURI;
|
|
|
+
|
|
|
+ self.createNode(prototypeComponent, undefined, baseURI, function (prototypeID) /* async */ {
|
|
|
+ childPrototypeID = prototypeID;
|
|
|
+
|
|
|
+
|
|
|
+ if (!childComponent.source) {
|
|
|
+ var prototype_intrinsics = self.intrinsics(prototypeID);
|
|
|
+ if (prototype_intrinsics.source) {
|
|
|
+ var prototype_uri = self.uri(prototypeID);
|
|
|
+ var prototype_properties = self.getProperties(prototypeID);
|
|
|
+ childComponent.source = prototype_intrinsics.source
|
|
|
+ childComponent.type = prototype_intrinsics.type;
|
|
|
+ childComponent.properties = childComponent.properties || {};
|
|
|
+ Object.keys(prototype_properties).forEach(function (prototype_property_name) {
|
|
|
+ if (childComponent.properties[prototype_property_name] === undefined && prototype_property_name != "transform") {
|
|
|
+ childComponent.properties[prototype_property_name] = prototype_properties[prototype_property_name];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ parallel_callback_async(undefined, undefined);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ childPrototypeID = undefined;
|
|
|
+ parallel_callback_async(undefined, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ function (parallel_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var behaviorComponents = childComponent.implements ? [].concat(childComponent.implements) : [];
|
|
|
+
|
|
|
+ async.map(behaviorComponents, function (behaviorComponent, map_callback_async /* ( err, result ) */ ) {
|
|
|
+ self.createNode(behaviorComponent, undefined, baseURI, function (behaviorID) /* async */ {
|
|
|
+ map_callback_async(undefined, behaviorID);
|
|
|
+ });
|
|
|
+ }, function (err, behaviorIDs) /* async */ {
|
|
|
+ childBehaviorIDs = behaviorIDs;
|
|
|
+ parallel_callback_async(err, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ ], function (err, results) /* async */ {
|
|
|
+ series_callback_async(err, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ child = self.nodes.create(childID, childPrototypeID, childBehaviorIDs, childURI, childName, nodeID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (childID === self.kutility.protoNodeURI) {
|
|
|
+ child.events.create(self.namespaceEncodedName(["properties", "created"]));
|
|
|
+ child.events.create(self.namespaceEncodedName(["properties", "initialized"]));
|
|
|
+ child.events.create(self.namespaceEncodedName(["properties", "deleted"]));
|
|
|
+ child.events.create(self.namespaceEncodedName(["methods", "created"]));
|
|
|
+ child.events.create(self.namespaceEncodedName(["methods", "deleted"]));
|
|
|
+ child.events.create(self.namespaceEncodedName(["events", "created"]));
|
|
|
+ child.events.create(self.namespaceEncodedName(["events", "deleted"]));
|
|
|
+ child.events.create(self.namespaceEncodedName(["children", "added"]));
|
|
|
+ child.events.create(self.namespaceEncodedName(["children", "removed"]));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.object.creatingNode(nodeID, childID, childPrototypeID, childBehaviorIDs,
|
|
|
+ childComponent.source, childComponent.type, childIndex, childName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ resolvedSource = childComponent.source && childComponent.source
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async.forEachSeries(self.models, function (model, each_callback_async /* ( err ) */ ) {
|
|
|
+
|
|
|
+ var driver_ready = true;
|
|
|
+ var timeoutID;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ model.creatingNode && model.creatingNode(nodeID, childID, childPrototypeID, childBehaviorIDs,
|
|
|
+ resolvedSource, childComponent.type, childIndex, childName,
|
|
|
+ function (ready) /* async */ {
|
|
|
+
|
|
|
+ if (driver_ready && !ready) {
|
|
|
+ suspend();
|
|
|
+ } else if (!driver_ready && ready) {
|
|
|
+ resume();
|
|
|
+ }
|
|
|
+
|
|
|
+ function suspend() {
|
|
|
+ self.virtualTime.suspend("while loading " + childComponent.source + " for " + childID + " in creatingNode");
|
|
|
+ timeoutID = window.setTimeout(function () {
|
|
|
+ resume("timeout loading " + childComponent.source)
|
|
|
+ }, self.configuration["load-timeout"] * 1000);
|
|
|
+ driver_ready = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ function resume(err) {
|
|
|
+ window.clearTimeout(timeoutID);
|
|
|
+ driver_ready = true;
|
|
|
+ err && self.logger.warnx("createChild", nodeID, childName + ":", err);
|
|
|
+ each_callback_async(err);
|
|
|
+ self.virtualTime.resume("after loading " + childComponent.source + " for " + childID + " in creatingNode");
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ driver_ready && each_callback_async(undefined);
|
|
|
+
|
|
|
+ }, function (err) /* async */ {
|
|
|
+ series_callback_async(err, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async.forEach(self.views, function (view, each_callback_async /* ( err ) */ ) {
|
|
|
+
|
|
|
+ var driver_ready = true;
|
|
|
+ var timeoutID;
|
|
|
+
|
|
|
+ view.createdNode && view.createdNode(nodeID, childID, childPrototypeID, childBehaviorIDs,
|
|
|
+ resolvedSource, childComponent.type, childIndex, childName,
|
|
|
+ function (ready) /* async */ {
|
|
|
+
|
|
|
+ if (driver_ready && !ready) {
|
|
|
+ suspend();
|
|
|
+ } else if (!driver_ready && ready) {
|
|
|
+ resume();
|
|
|
+ }
|
|
|
+
|
|
|
+ function suspend() {
|
|
|
+ self.virtualTime.suspend("while loading " + childComponent.source + " for " + childID + " in createdNode");
|
|
|
+ timeoutID = window.setTimeout(function () {
|
|
|
+ resume("timeout loading " + childComponent.source)
|
|
|
+ }, self.configuration["load-timeout"] * 1000);
|
|
|
+ driver_ready = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ function resume(err) {
|
|
|
+ window.clearTimeout(timeoutID);
|
|
|
+ driver_ready = true;
|
|
|
+ err && self.logger.warnx("createChild", nodeID, childName + ":", err);
|
|
|
+ each_callback_async(err);
|
|
|
+ self.virtualTime.resume("after loading " + childComponent.source + " for " + childID + " in createdNode");
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ driver_ready && each_callback_async(undefined);
|
|
|
+
|
|
|
+ }, function (err) /* async */ {
|
|
|
+ series_callback_async(err, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.object.internals(childID, childComponent);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ replicating && self.models.kernel.disable();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ childComponent.properties && Object.keys(childComponent.properties).forEach(function (propertyName) {
|
|
|
+ var propertyValue = childComponent.properties[propertyName];
|
|
|
+
|
|
|
+ var value = propertyValue,
|
|
|
+ get, set, create;
|
|
|
+
|
|
|
+ if (self.valueHasAccessors(propertyValue)) {
|
|
|
+ value = propertyValue.node ? self.kutility.nodeReference(propertyValue.node) : propertyValue.value;
|
|
|
+ get = propertyValue.get;
|
|
|
+ set = propertyValue.set;
|
|
|
+ create = propertyValue.create;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var creating = create ||
|
|
|
+ get !== undefined || set !== undefined || // explicit accessor, or
|
|
|
+ !child.properties.has(propertyName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var assigning = value === undefined ||
|
|
|
+ set === undefined && (creating || !self.nodePropertyHasSetter.call(self, childID, propertyName)) || // no setter, or
|
|
|
+ replicating;
|
|
|
+
|
|
|
+ if (!assigning) {
|
|
|
+ deferredInitializations[propertyName] = value;
|
|
|
+ value = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (creating) {
|
|
|
+ self.createProperty(childID, propertyName, value, get, set);
|
|
|
+ } else {
|
|
|
+ self.setProperty(childID, propertyName, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ childComponent.methods && Object.keys(childComponent.methods).forEach(function (methodName) {
|
|
|
+ var methodValue = childComponent.methods[methodName];
|
|
|
+
|
|
|
+ if (self.valueHasBody(methodValue)) {
|
|
|
+ self.createMethod(childID, methodName, methodValue.parameters, methodValue.body);
|
|
|
+ } else {
|
|
|
+ self.createMethod(childID, methodName, undefined, methodValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ childComponent.events && Object.keys(childComponent.events).forEach(function (eventName) {
|
|
|
+ var eventValue = childComponent.events[eventName];
|
|
|
+
|
|
|
+ if (self.valueHasBody(eventValue)) {
|
|
|
+ self.createEvent(childID, eventName, eventValue.parameters);
|
|
|
+ self.setEvent(childID, eventName, eventValue);
|
|
|
+ } else {
|
|
|
+ self.createEvent(childID, eventName, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ replicating && self.models.kernel.enable();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async.forEach(Object.keys(childComponent.children || {}), function (childName, each_callback_async /* ( err ) */ ) {
|
|
|
+ var childValue = childComponent.children[childName];
|
|
|
+
|
|
|
+ self.createChild(childID, childName, childValue, undefined, function (childID) /* async */ {
|
|
|
+ each_callback_async(undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ }, function (err) /* async */ {
|
|
|
+ series_callback_async(err, undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ function (series_callback_async /* ( err, results ) */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var scripts = childComponent.scripts ? [].concat(childComponent.scripts) : [];
|
|
|
+
|
|
|
+ async.map(scripts, function (script, map_callback_async /* ( err, result ) */ ) {
|
|
|
+
|
|
|
+ if (self.valueHasType(script)) {
|
|
|
+ if (script.source) {
|
|
|
+ self.loadScript(script.source, baseURI, function (scriptText) /* async */ {
|
|
|
+ map_callback_async(undefined, {
|
|
|
+ text: scriptText,
|
|
|
+ type: script.type
|
|
|
+ });
|
|
|
+ }, function (errorMessage) {
|
|
|
+ map_callback_async(errorMessage, undefined);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ map_callback_async(undefined, {
|
|
|
+ text: script.text,
|
|
|
+ type: script.type
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ map_callback_async(undefined, {
|
|
|
+ text: script,
|
|
|
+ type: undefined
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }, function (err, scripts) /* async */ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.kernel.capturingAsyncs(function () {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ replicating && self.models.kernel.disable();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ scripts.forEach(function (script) {
|
|
|
+ self.execute(childID, script.text, script.type);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Object.keys(deferredInitializations).forEach(function (propertyName) {
|
|
|
+ self.setProperty(childID, propertyName, deferredInitializations[propertyName]);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (self.execute(childID, "Boolean( this.tick )")) {
|
|
|
+ self.tickable.nodeIDs.push(childID);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ replicating && self.models.kernel.enable();
|
|
|
+
|
|
|
+ }, function () {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async.forEachSeries(self.prototypes(childID, true).reverse().concat(childID),
|
|
|
+ function (childInitializingNodeID, each_callback_async /* err */ ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.kernel.capturingAsyncs(function () {
|
|
|
+
|
|
|
+ self.models.forEach(function (model) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ replicating && self.models.kernel.disable();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (childInitializingNodeID !== childID) {
|
|
|
+ model.initializingNodeFromPrototype &&
|
|
|
+ model.initializingNodeFromPrototype(nodeID, childID, childInitializingNodeID);
|
|
|
+ } else {
|
|
|
+ model.initializingNode &&
|
|
|
+ model.initializingNode(nodeID, childID, childPrototypeID, childBehaviorIDs,
|
|
|
+ resolvedSource, childComponent.type, childIndex, childName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ replicating && self.models.kernel.enable();
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }, function () {
|
|
|
+ each_callback_async(undefined);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+ function (err) /* async */ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.views.forEach(function (view) {
|
|
|
+ view.initializedNode && view.initializedNode(nodeID, childID, childPrototypeID, childBehaviorIDs,
|
|
|
+ resolvedSource, childComponent.type, childIndex, childName);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.nodes.initialize(childID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!replicating && nodeID !== 0) {
|
|
|
+ self.fireEvent(nodeID, ["children", "added"],
|
|
|
+ [childIndex, self.kutility.nodeReference(childID)]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (childID === self.application()) {
|
|
|
+
|
|
|
+ NProgress.done();
|
|
|
+ NProgress.remove();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ series_callback_async(err, undefined);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ ], function (err, results) /* async */ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (callback_async) {
|
|
|
+
|
|
|
+ self.virtualTime.suspend("before completing " + childID);
|
|
|
+
|
|
|
+ async.nextTick(function () {
|
|
|
+ callback_async(childID);
|
|
|
+ self.virtualTime.resume("after completing " + childID);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ deleteChild(nodeID, childName) {
|
|
|
+
|
|
|
+ var childID = this.children(nodeID).filter(function (childID) {
|
|
|
+ return this.name(childID) === childName;
|
|
|
+ }, this)[0];
|
|
|
+
|
|
|
+ if (childID !== undefined) {
|
|
|
+ return this.deleteNode(childID);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ addChild(nodeID, childID, childName) {
|
|
|
+
|
|
|
+ this.logger.debuggx("addChild", nodeID, childID, childName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ model.addingChild && model.addingChild(nodeID, childID, childName);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.addedChild && view.addedChild(nodeID, childID, childName);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ removeChild(nodeID, childID) {
|
|
|
+
|
|
|
+ this.logger.debuggx("removeChild", nodeID, childID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ model.removingChild && model.removingChild(nodeID, childID);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.removedChild && view.removedChild(nodeID, childID);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setProperties(nodeID, properties) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("setProperties", nodeID, properties);
|
|
|
+
|
|
|
+ var node = self.nodes.existing[nodeID];
|
|
|
+
|
|
|
+ var entrants = this.setProperty.entrants;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ properties = this.models.reduceRight(function (intermediate_properties, model, index) {
|
|
|
+
|
|
|
+ var model_properties = {};
|
|
|
+
|
|
|
+ if (model.settingProperties) {
|
|
|
+
|
|
|
+ model_properties = model.settingProperties(nodeID, properties);
|
|
|
+
|
|
|
+ } else if (model.settingProperty) {
|
|
|
+
|
|
|
+ Object.keys(node.properties.existing).forEach(function (propertyName) {
|
|
|
+
|
|
|
+ if (properties[propertyName] !== undefined) {
|
|
|
+
|
|
|
+ var reentry = entrants[nodeID + '-' + propertyName] = {
|
|
|
+ index: index
|
|
|
+ };
|
|
|
+
|
|
|
+ model_properties[propertyName] =
|
|
|
+ model.settingProperty(nodeID, propertyName, properties[propertyName]);
|
|
|
+ if (self.models.kernel.blocked()) {
|
|
|
+ model_properties[propertyName] = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ delete entrants[nodeID + '-' + propertyName];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Object.keys(node.properties.existing).forEach(function (propertyName) {
|
|
|
+ if (model_properties[propertyName] !== undefined) {
|
|
|
+ intermediate_properties[propertyName] = model_properties[propertyName];
|
|
|
+ } else if (intermediate_properties[propertyName] === undefined) {
|
|
|
+ intermediate_properties[propertyName] = undefined;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return intermediate_properties;
|
|
|
+
|
|
|
+ }, {});
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (node.initialized && node.patchable) {
|
|
|
+ Object.keys(properties).forEach(function (propertyName) {
|
|
|
+ node.properties.change(propertyName);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+
|
|
|
+ if (view.satProperties) {
|
|
|
+ view.satProperties(nodeID, properties);
|
|
|
+ } else if (view.satProperty) {
|
|
|
+ for (var propertyName in properties) {
|
|
|
+ view.satProperty(nodeID, propertyName, properties[propertyName]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getProperties(nodeID) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("getProperties", nodeID);
|
|
|
+
|
|
|
+ var node = self.nodes.existing[nodeID];
|
|
|
+
|
|
|
+ var entrants = this.getProperty.entrants;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var properties = this.models.reduceRight(function (intermediate_properties, model, index) {
|
|
|
+
|
|
|
+ var model_properties = {};
|
|
|
+
|
|
|
+ if (model.gettingProperties) {
|
|
|
+
|
|
|
+ model_properties = model.gettingProperties(nodeID, properties);
|
|
|
+
|
|
|
+ } else if (model.gettingProperty) {
|
|
|
+
|
|
|
+ Object.keys(node.properties.existing).forEach(function (propertyName) {
|
|
|
+
|
|
|
+ var reentry = entrants[nodeID + '-' + propertyName] = {
|
|
|
+ index: index
|
|
|
+ };
|
|
|
+
|
|
|
+ model_properties[propertyName] =
|
|
|
+ model.gettingProperty(nodeID, propertyName, intermediate_properties[propertyName]);
|
|
|
+ if (self.models.kernel.blocked()) {
|
|
|
+ model_properties[propertyName] = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ delete entrants[nodeID + '-' + propertyName];
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Object.keys(node.properties.existing).forEach(function (propertyName) {
|
|
|
+ if (model_properties[propertyName] !== undefined) {
|
|
|
+ intermediate_properties[propertyName] = model_properties[propertyName];
|
|
|
+ } else if (intermediate_properties[propertyName] === undefined) {
|
|
|
+ intermediate_properties[propertyName] = undefined;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return intermediate_properties;
|
|
|
+
|
|
|
+ }, {});
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+
|
|
|
+ if (view.gotProperties) {
|
|
|
+ view.gotProperties(nodeID, properties);
|
|
|
+ } else if (view.gotProperty) {
|
|
|
+ for (var propertyName in properties) {
|
|
|
+ view.gotProperty(nodeID, propertyName, properties[propertyName]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return properties;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ createProperty(nodeID, propertyName, propertyValue, propertyGet, propertySet) {
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("createProperty", function () {
|
|
|
+ return [nodeID, propertyName, JSON.stringify(self.loggableValue(propertyValue)),
|
|
|
+ self.loggableScript(propertyGet), self.loggableScript(propertySet)
|
|
|
+ ];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = self.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ node.properties.create(propertyName, node.initialized && node.patchable);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ model.creatingProperty && model.creatingProperty(nodeID, propertyName, propertyValue,
|
|
|
+ propertyGet, propertySet);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.createdProperty && view.createdProperty(nodeID, propertyName, propertyValue,
|
|
|
+ propertyGet, propertySet);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.models.kernel.enabled()) {
|
|
|
+ this.fireEvent(nodeID, ["properties", "created"], [propertyName]);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return propertyValue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setProperty(nodeID, propertyName, propertyValue) {
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("setProperty", function () {
|
|
|
+ return [nodeID, propertyName, JSON.stringify(self.loggableValue(propertyValue))];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = self.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var entrants = this.setProperty.entrants;
|
|
|
+
|
|
|
+ var entry = entrants[nodeID + '-' + propertyName] || {};
|
|
|
+ var reentry = entrants[nodeID + '-' + propertyName] = {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!node.properties.has(propertyName) || entry.creating) {
|
|
|
+ reentry.creating = true;
|
|
|
+ var settingPropertyEtc = "creatingProperty";
|
|
|
+ var satPropertyEtc = "createdProperty";
|
|
|
+ node.properties.create(propertyName, node.initialized && node.patchable);
|
|
|
+ } else if (!node.properties.hasOwn(propertyName) || entry.initializing) {
|
|
|
+ reentry.initializing = true;
|
|
|
+ var settingPropertyEtc = "initializingProperty";
|
|
|
+ var satPropertyEtc = "initializedProperty";
|
|
|
+ node.properties.create(propertyName, node.initialized && node.patchable);
|
|
|
+ } else {
|
|
|
+ var settingPropertyEtc = "settingProperty";
|
|
|
+ var satPropertyEtc = "satProperty";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var outermost = entrants.assignments === undefined;
|
|
|
+
|
|
|
+ if (outermost) {
|
|
|
+ entrants.assignments = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var reentered = (entry.index !== undefined);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var delegated = false,
|
|
|
+ assigned = false;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.some(function (model, index) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if ((!reentered || index > entry.index) && !reentry.completed) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ reentry.index = index;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var assignments = entrants.assignments;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!delegated && !assigned) {
|
|
|
+ var value = model[settingPropertyEtc] && model[settingPropertyEtc](nodeID, propertyName, propertyValue);
|
|
|
+ } else {
|
|
|
+ model[settingPropertyEtc] && model[settingPropertyEtc](nodeID, propertyName, undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.models.kernel.blocked()) {
|
|
|
+ value = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (entrants.assignments !== assignments) {
|
|
|
+ delegated = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ else if (value !== undefined) {
|
|
|
+ entrants.assignments++;
|
|
|
+ assigned = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (value !== undefined) {
|
|
|
+ propertyValue = value;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return settingPropertyEtc == "settingProperty" && (delegated || assigned);
|
|
|
+ }
|
|
|
+
|
|
|
+ }, this);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (assigned && node.initialized && node.patchable) {
|
|
|
+ node.properties.change(propertyName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (assigned) {
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view[satPropertyEtc] && view[satPropertyEtc](nodeID, propertyName, propertyValue);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (reentered) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ entrants[nodeID + '-' + propertyName] = entry;
|
|
|
+ entry.completed = true;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ delete entrants[nodeID + '-' + propertyName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.models.kernel.enabled()) {
|
|
|
+ if (settingPropertyEtc === "creatingProperty") {
|
|
|
+ this.fireEvent(nodeID, ["properties", "created"], [propertyName]);
|
|
|
+ } else if (settingPropertyEtc === "initializingProperty") {
|
|
|
+ this.fireEvent(nodeID, ["properties", "initialized"], [propertyName]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (outermost) {
|
|
|
+ delete entrants.assignments;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return propertyValue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getProperty(nodeID, propertyName, ignorePrototype) {
|
|
|
+
|
|
|
+ this.logger.debuggx("getProperty", nodeID, propertyName);
|
|
|
+
|
|
|
+ var propertyValue = undefined;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var entrants = this.getProperty.entrants;
|
|
|
+
|
|
|
+ var entry = entrants[nodeID + '-' + propertyName] || {};
|
|
|
+ var reentry = entrants[nodeID + '-' + propertyName] = {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var outermost = entrants.retrievals === undefined;
|
|
|
+
|
|
|
+ if (outermost) {
|
|
|
+ entrants.retrievals = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var reentered = (entry.index !== undefined);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var delegated = false,
|
|
|
+ retrieved = false;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.some(function (model, index) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if ((!reentered || index > entry.index) && !reentry.completed) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ reentry.index = index;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var retrievals = entrants.retrievals;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var value = model.gettingProperty &&
|
|
|
+ model.gettingProperty(nodeID, propertyName, propertyValue);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.models.kernel.blocked()) {
|
|
|
+ value = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (entrants.retrievals !== retrievals) {
|
|
|
+ delegated = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ else if (value !== undefined) {
|
|
|
+ entrants.retrievals++;
|
|
|
+ retrieved = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (value !== undefined) {
|
|
|
+ propertyValue = value;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return delegated || retrieved;
|
|
|
+ }
|
|
|
+
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ if (reentered) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ entrants[nodeID + '-' + propertyName] = entry;
|
|
|
+ entry.completed = true;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ delete entrants[nodeID + '-' + propertyName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (propertyValue === undefined && !ignorePrototype) {
|
|
|
+
|
|
|
+ this.behaviors(nodeID).reverse().concat(this.prototype(nodeID)).
|
|
|
+ some(function (prototypeID, prototypeIndex, prototypeArray) {
|
|
|
+
|
|
|
+ if (prototypeIndex < prototypeArray.length - 1) {
|
|
|
+ propertyValue = this.getProperty(prototypeID, propertyName, true);
|
|
|
+ } else if (prototypeID !== this.kutility.protoNodeURI) {
|
|
|
+ propertyValue = this.getProperty(prototypeID, propertyName);
|
|
|
+ }
|
|
|
+
|
|
|
+ return propertyValue !== undefined;
|
|
|
+
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.gotProperty && view.gotProperty(nodeID, propertyName, propertyValue);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (outermost) {
|
|
|
+ delete entrants.retrievals;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return propertyValue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ createMethod(nodeID, methodName, methodParameters, methodBody) {
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("createMethod", function () {
|
|
|
+ return [nodeID, methodName, methodParameters, self.loggableScript(methodBody)];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = self.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ node.methods.create(methodName, node.initialized && node.patchable);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ model.creatingMethod && model.creatingMethod(nodeID, methodName, methodParameters,
|
|
|
+ methodBody);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.createdMethod && view.createdMethod(nodeID, methodName, methodParameters,
|
|
|
+ methodBody);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.models.kernel.enabled()) {
|
|
|
+ this.fireEvent(nodeID, ["methods", "created"], [methodName]);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setMethod(nodeID, methodName, methodHandler) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ this.logger.debuggx("setMethod", function () {
|
|
|
+ return [nodeID, methodName];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+
|
|
|
+ methodHandler = this.normalizedHandler(methodHandler);
|
|
|
+
|
|
|
+ if (!node.methods.hasOwn(methodName)) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.createMethod(nodeID, methodName, methodHandler.parameters, methodHandler.body);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.some(function (model) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var handler = model.settingMethod && model.settingMethod(nodeID, methodName, methodHandler);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (handler !== undefined) {
|
|
|
+ methodHandler = self.utility.merge({}, handler);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return handler !== undefined;
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (node.initialized && node.patchable) {
|
|
|
+ node.methods.change(methodName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.satMethod && view.satMethod(nodeID, methodName, methodHandler);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return methodHandler;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getMethod(nodeID, methodName) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("getMethod", function () {
|
|
|
+ return [nodeID, methodName];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var methodHandler = {};
|
|
|
+
|
|
|
+ this.models.some(function (model) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var handler = model.gettingMethod && model.gettingMethod(nodeID, methodName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (handler !== undefined) {
|
|
|
+ methodHandler = self.utility.merge({}, handler);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return handler !== undefined;
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.gotMethod && view.gotMethod(nodeID, methodName, methodHandler);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return methodHandler;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ callMethod(nodeID, methodName, methodParameters) {
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("callMethod", function () {
|
|
|
+ return [nodeID, methodName, JSON.stringify(self.loggableValues(methodParameters))];
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var methodValue = undefined;
|
|
|
+
|
|
|
+ this.models.some(function (model) {
|
|
|
+ methodValue = model.callingMethod && model.callingMethod(nodeID, methodName, methodParameters);
|
|
|
+ return methodValue !== undefined;
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.calledMethod && view.calledMethod(nodeID, methodName, methodParameters, methodValue);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return methodValue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ createEvent(nodeID, eventName, eventParameters) {
|
|
|
+
|
|
|
+ this.logger.debuggx("createEvent", nodeID, eventName, eventParameters);
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ node.events.create(encodedEventName, node.initialized && node.patchable, eventParameters);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ model.creatingEvent && model.creatingEvent(nodeID, encodedEventName, eventParameters);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.createdEvent && view.createdEvent(nodeID, encodedEventName, eventParameters);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.models.kernel.enabled()) {
|
|
|
+ this.fireEvent(nodeID, ["events", "created"], [eventName]);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setEvent(nodeID, eventName, eventDescriptor) {
|
|
|
+
|
|
|
+ this.logger.debuggx("setEvent", function () {
|
|
|
+ return [nodeID, eventName];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+ if (!node.events.hasOwn(encodedEventName)) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.createEvent(nodeID, eventName, eventDescriptor.parameters);
|
|
|
+
|
|
|
+ (eventDescriptor.listeners || []).forEach(function (listener) {
|
|
|
+ return this.addEventListener(nodeID, eventName, listener, listener.context, listener.phases);
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var event = node.events.existing[encodedEventName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ eventDescriptor = {
|
|
|
+
|
|
|
+ parameters: event.parameters ?
|
|
|
+ event.parameters.slice() : [],
|
|
|
+
|
|
|
+ listeners: (eventDescriptor.listeners || []).map(function (listener) {
|
|
|
+
|
|
|
+ if (event.listeners.hasOwn(listener.id)) {
|
|
|
+ return this.setEventListener(nodeID, eventName, listener.id, listener);
|
|
|
+ } else {
|
|
|
+ return this.addEventListener(nodeID, eventName, listener, listener.context, listener.phases);
|
|
|
+ }
|
|
|
+
|
|
|
+ }, this),
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return eventDescriptor;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getEvent(nodeID, eventName) {
|
|
|
+
|
|
|
+ this.logger.debuggx("getEvent", function () {
|
|
|
+ return [nodeID, eventName];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var event = node.events.existing[encodedEventName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var eventDescriptor = {};
|
|
|
+
|
|
|
+ if (event.parameters) {
|
|
|
+ eventDescriptor.parameters = event.parameters.slice();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (event.listeners.existing.length) {
|
|
|
+ eventDescriptor.listeners = event.listeners.existing.map(function (eventListenerID) {
|
|
|
+ var listener = this.getEventListener(nodeID, eventName, eventListenerID);
|
|
|
+ listener.id = eventListenerID;
|
|
|
+ return listener;
|
|
|
+ }, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return eventDescriptor;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ addEventListener(nodeID, eventName, eventHandler, eventContextID, eventPhases) {
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("addEventListener", function () {
|
|
|
+ return [nodeID, eventName, self.loggableScript(eventHandler),
|
|
|
+ eventContextID, eventPhases
|
|
|
+ ];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = self.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!node.events.hasOwn(encodedEventName)) {
|
|
|
+ node.events.create(encodedEventName, node.initialized && node.patchable);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var event = node.events.existing[encodedEventName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ eventHandler = this.normalizedHandler(eventHandler, event.parameters);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var eventListenerID = eventHandler.id || this.sequence(nodeID);
|
|
|
+
|
|
|
+ event.listeners.create(eventListenerID, node.initialized && node.patchable);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ model.addingEventListener &&
|
|
|
+ model.addingEventListener(nodeID, encodedEventName, eventListenerID,
|
|
|
+ eventHandler, eventContextID, eventPhases);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.addedEventListener &&
|
|
|
+ view.addedEventListener(nodeID, encodedEventName, eventListenerID,
|
|
|
+ eventHandler, eventContextID, eventPhases);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return eventListenerID;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ removeEventListener(nodeID, eventName, eventListenerID) {
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("removeEventListener", function () {
|
|
|
+ return [nodeID, eventName, self.loggableScript(eventListenerID)];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var event = node.events.existing[encodedEventName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ event.listeners.delete(eventListenerID, node.initialized && node.patchable);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ model.removingEventListener &&
|
|
|
+ model.removingEventListener(nodeID, encodedEventName, eventListenerID);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.removedEventListener &&
|
|
|
+ view.removedEventListener(nodeID, encodedEventName, eventListenerID);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return eventListenerID;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ setEventListener(nodeID, eventName, eventListenerID, eventListener) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("setEventListener", function () {
|
|
|
+ return [nodeID, eventName, eventListenerID];
|
|
|
+ });
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var event = node.events.existing[encodedEventName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ eventListener = this.normalizedHandler(eventListener, event.parameters);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (node.initialized && node.patchable) {
|
|
|
+ event.listeners.change(eventListenerID);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.some(function (model) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var listener = model.settingEventListener &&
|
|
|
+ model.settingEventListener(nodeID, encodedEventName, eventListenerID, eventListener);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (listener !== undefined) {
|
|
|
+ eventListener = self.utility.merge({}, listener);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return listener !== undefined;
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.satEventListener &&
|
|
|
+ view.satEventListener(nodeID, encodedEventName, eventListenerID, eventListener);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return eventListener;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ getEventListener(nodeID, eventName, eventListenerID) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("getEventListener", function () {
|
|
|
+ return [nodeID, eventName, eventListenerID];
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var eventListener = {};
|
|
|
+
|
|
|
+ this.models.some(function (model) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var listener = model.gettingEventListener &&
|
|
|
+ model.gettingEventListener(nodeID, encodedEventName, eventListenerID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (listener !== undefined) {
|
|
|
+ eventListener = self.utility.merge({}, listener);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return listener !== undefined;
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.gotEventListener &&
|
|
|
+ view.gotEventListener(nodeID, encodedEventName, eventListenerID, eventListener);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return eventListener;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ flushEventListeners(nodeID, eventName, eventContextID) {
|
|
|
+
|
|
|
+ this.logger.debuggx("flushEventListeners", nodeID, eventName, eventContextID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var node = this.nodes.existing[nodeID];
|
|
|
+ var event = node.events.existing[encodedEventName];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.models.forEach(function (model) {
|
|
|
+ var removedIds = model.flushingEventListeners &&
|
|
|
+ model.flushingEventListeners(nodeID, encodedEventName, eventContextID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (removedIds && removedIds.length) {
|
|
|
+
|
|
|
+
|
|
|
+ removedIds.forEach(function (removedId) {
|
|
|
+ event.listeners.delete(removedId, node.initialized && node.patchable);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.flushedEventListeners &&
|
|
|
+ view.flushedEventListeners(nodeID, encodedEventName, eventContextID);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ fireEvent(nodeID, eventName, eventParameters) {
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("fireEvent", function () {
|
|
|
+ return [nodeID, eventName, JSON.stringify(self.loggableValues(eventParameters))];
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var encodedEventName = this.namespaceEncodedName(eventName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var handled = this.models.reduce(function (handled, model) {
|
|
|
+ return model.firingEvent && model.firingEvent(nodeID, encodedEventName, eventParameters) || handled;
|
|
|
+ }, false);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.views.forEach(function (view) {
|
|
|
+ view.firedEvent && view.firedEvent(nodeID, encodedEventName, eventParameters);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return handled;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ dispatchEvent(nodeID, eventName, eventParameters, eventNodeParameters) {
|
|
|
+ let self = this;
|
|
|
+ this.logger.debuggx("dispatchEvent", function () {
|
|
|
+ return [nodeID, eventName, JSON.stringify(self.loggableValues(eventParameters)),
|
|
|
+ JSON.stringify(self.loggableIndexedValues(eventNodeParameters))
|
|
|
+ ];
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ eventParameters = eventParameters || [];
|
|
|
+ eventNodeParameters = eventNodeParameters || {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var ancestorIDs = this.ancestors(nodeID);
|
|
|
+ var lastAncestorID = "";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var cascadedEventNodeParameters = {
|
|
|
+ "": eventNodeParameters[""] || []
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var targetEventParameters = undefined;
|
|
|
+
|
|
|
+ var phase = undefined;
|
|
|
+ var handled = false;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ phase = "capture";
|
|
|
+
|
|
|
+ handled = handled || ancestorIDs.reverse().some(function (ancestorID) {
|
|
|
+
|
|
|
+ cascadedEventNodeParameters[ancestorID] = eventNodeParameters[ancestorID] ||
|
|
|
+ cascadedEventNodeParameters[lastAncestorID];
|
|
|
+
|
|
|
+ lastAncestorID = ancestorID;
|
|
|
+
|
|
|
+ targetEventParameters =
|
|
|
+ eventParameters.concat(cascadedEventNodeParameters[ancestorID], phase);
|
|
|
+
|
|
|
+ targetEventParameters.phase = phase;
|
|
|
+
|
|
|
+ return this.fireEvent(ancestorID, eventName, targetEventParameters);
|
|
|
+
|
|
|
+ }, this);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ phase = undefined;
|
|
|
+
|
|
|
+ cascadedEventNodeParameters[nodeID] = eventNodeParameters[nodeID] ||
|
|
|
+ cascadedEventNodeParameters[lastAncestorID];
|
|
|
+
|
|
|
+ targetEventParameters =
|
|
|
+ eventParameters.concat(cascadedEventNodeParameters[nodeID], phase);
|
|
|
+
|
|
|
+ handled = handled || this.fireEvent(nodeID, eventName, targetEventParameters);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ phase = undefined;
|
|
|
+
|
|
|
+ handled = handled || ancestorIDs.reverse().some(function (ancestorID) {
|
|
|
+
|
|
|
+ targetEventParameters =
|
|
|
+ eventParameters.concat(cascadedEventNodeParameters[ancestorID], phase);
|
|
|
+
|
|
|
+ return this.fireEvent(ancestorID, eventName, targetEventParameters);
|
|
|
+
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ execute(nodeID, scriptText, scriptType, callback_async ) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ this.logger.debuggx("execute", function () {
|
|
|
+ return [nodeID, self.loggableScript(scriptText), scriptType];
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!scriptType && (typeof scriptText == "string" || scriptText instanceof String)) {
|
|
|
+ scriptType = "application/javascript";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var scriptValue = undefined;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.models.kernel.capturingAsyncs(function () {
|
|
|
+ self.models.some(function (model) {
|
|
|
+ scriptValue = model.executing &&
|
|
|
+ model.executing(nodeID, scriptText, scriptType);
|
|
|
+ return scriptValue !== undefined;
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.views.forEach(function (view) {
|
|
|
+ view.executed && view.executed(nodeID, scriptText, scriptType);
|
|
|
+ });
|
|
|
+
|
|
|
+ }, function () {
|
|
|
+ callback_async && callback_async(scriptValue);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.logger.debugu();
|
|
|
+
|
|
|
+ return scriptValue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ random(nodeID) {
|
|
|
+ return this.models.object.random(nodeID);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ seed(nodeID, seed) {
|
|
|
+ return this.models.object.seed(nodeID, seed);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ now() {
|
|
|
+ return this.virtualTime.now;
|
|
|
+ }
|
|
|
+
|
|
|
+ time() {
|
|
|
+ return this.virtualTime.now;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ client() {
|
|
|
+ return this.virtualTime.client_;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ moniker() {
|
|
|
+ return this.moniker_;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ application(initializedOnly) {
|
|
|
+ let self = this;
|
|
|
+ var applicationID;
|
|
|
+
|
|
|
+ Object.keys(self.nodes.globals).forEach(function (globalID) {
|
|
|
+ var global = self.nodes.existing[globalID];
|
|
|
+ if ((!initializedOnly || global.initialized) && global.name === "application") {
|
|
|
+ applicationID = globalID;
|
|
|
+ }
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ return applicationID;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ intrinsics(nodeID, result) {
|
|
|
+ return this.models.object.intrinsics(nodeID, result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ uri(nodeID, searchAncestors, initializedOnly) {
|
|
|
+
|
|
|
+ var uri = this.models.object.uri(nodeID);
|
|
|
+
|
|
|
+ if (searchAncestors) {
|
|
|
+ while (!uri && (nodeID = this.parent(nodeID, initializedOnly))) {
|
|
|
+ uri = this.models.object.uri(nodeID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return uri;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ name(nodeID) {
|
|
|
+ return this.models.object.name(nodeID);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ prototype(nodeID) {
|
|
|
+ return this.models.object.prototype(nodeID);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ prototypes(nodeID, includeBehaviors) {
|
|
|
+
|
|
|
+ var prototypes = [];
|
|
|
+
|
|
|
+ do {
|
|
|
+
|
|
|
+
|
|
|
+ if (includeBehaviors) {
|
|
|
+ var b = [].concat(this.behaviors(nodeID));
|
|
|
+ Array.prototype.push.apply(prototypes, b.reverse());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ nodeID = this.prototype(nodeID);
|
|
|
+
|
|
|
+
|
|
|
+ if (nodeID) {
|
|
|
+ prototypes.push(nodeID);
|
|
|
+ }
|
|
|
+
|
|
|
+ } while (nodeID);
|
|
|
+
|
|
|
+ return prototypes;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ behaviors(nodeID) {
|
|
|
+ return this.models.object.behaviors(nodeID);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ globals(initializedOnly) {
|
|
|
+ let self = this;
|
|
|
+ var globals = {};
|
|
|
+
|
|
|
+ Object.keys(self.nodes.globals).forEach(function (globalID) {
|
|
|
+ if (!initializedOnly || self.nodes.existing[globalID].initialized) {
|
|
|
+ globals[globalID] = undefined;
|
|
|
+ }
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ return globals;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ global(globalReference, initializedOnly) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ var globals = this.globals(initializedOnly);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return matches("uri") || matches("name");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function matches(field) {
|
|
|
+
|
|
|
+ var matchingID;
|
|
|
+
|
|
|
+ Object.keys(globals).some(function (globalID) {
|
|
|
+ if (self.nodes.existing[globalID][field] === globalReference) {
|
|
|
+ matchingID = globalID;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return matchingID;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ root(nodeID, initializedOnly) {
|
|
|
+
|
|
|
+ var rootID;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ do {
|
|
|
+ rootID = nodeID;
|
|
|
+ nodeID = this.parent(nodeID, initializedOnly);
|
|
|
+ } while (nodeID);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return nodeID === undefined ? undefined : rootID;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ancestors(nodeID, initializedOnly) {
|
|
|
+
|
|
|
+ var ancestors = [];
|
|
|
+
|
|
|
+ nodeID = this.parent(nodeID, initializedOnly);
|
|
|
+
|
|
|
+ while (nodeID) {
|
|
|
+ ancestors.push(nodeID);
|
|
|
+ nodeID = this.parent(nodeID, initializedOnly);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ancestors;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ parent(nodeID, initializedOnly) {
|
|
|
+ return this.models.object.parent(nodeID, initializedOnly);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ children(nodeID, initializedOnly) {
|
|
|
+
|
|
|
+ if (nodeID === undefined) {
|
|
|
+ this.logger.errorx("children", "cannot retrieve children of nonexistent node");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.models.object.children(nodeID, initializedOnly);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ child(nodeID, childReference, initializedOnly) {
|
|
|
+
|
|
|
+ var children = this.children(nodeID, initializedOnly);
|
|
|
+
|
|
|
+ if (typeof childReference === "number" || childReference instanceof Number) {
|
|
|
+ return children[childReference];
|
|
|
+ } else {
|
|
|
+ return children.filter(function (childID) {
|
|
|
+ return childID && this.name(childID) === childReference;
|
|
|
+ }, this)[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ descendants(nodeID, initializedOnly) {
|
|
|
+
|
|
|
+ if (nodeID === undefined) {
|
|
|
+ this.logger.errorx("descendants", "cannot retrieve children of nonexistent node");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var descendants = [];
|
|
|
+
|
|
|
+ this.children(nodeID, initializedOnly).forEach(function (childID) {
|
|
|
+ descendants.push(childID);
|
|
|
+ childID && Array.prototype.push.apply(descendants, this.descendants(childID, initializedOnly));
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ return descendants;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sequence(nodeID) {
|
|
|
+ return this.models.object.sequence(nodeID);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ find(nodeID, matchPattern, initializedOnly, callback ) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof initializedOnly == "function" || initializedOnly instanceof Function) {
|
|
|
+ callback = initializedOnly;
|
|
|
+ initializedOnly = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var matchIDs = find.call(this, nodeID, matchPattern, initializedOnly);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (callback) {
|
|
|
+
|
|
|
+ matchIDs.forEach(function (matchID) {
|
|
|
+ callback(matchID);
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return matchIDs;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ findClients(nodeID, matchPattern, callback ) {
|
|
|
+
|
|
|
+ this.logger.warn("`kernel.findClients` is deprecated. Use " +
|
|
|
+ "`kernel.find( nodeID, \"doc('proxy/clients.vwf')/pattern\" )`" +
|
|
|
+ " instead.");
|
|
|
+
|
|
|
+ var clientsMatchPattern = "doc('proxy/clients.vwf')" +
|
|
|
+ (matchPattern[0] === "/" ? "" : "/") + matchPattern;
|
|
|
+
|
|
|
+ return this.find(nodeID || this.application(), clientsMatchPattern, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ test(nodeID, matchPattern, testID, initializedOnly) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var matchIDs = this.find.call(this, nodeID, matchPattern, initializedOnly);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return matchIDs.some(function (matchID) {
|
|
|
+ return matchID == testID;
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loadComponent(nodeURI, baseURI, callback_async , errback_async ) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ if (nodeURI == self.kutility.protoNodeURI) {
|
|
|
+
|
|
|
+ callback_async(self.kutility.protoNodeDescriptor);
|
|
|
+
|
|
|
+ } else if (nodeURI.match(RegExp("^data:application/json;base64,"))) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ callback_async(JSON.parse(atob(nodeURI.substring(29))));
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ self.virtualTime.suspend("while loading " + nodeURI);
|
|
|
+
|
|
|
+ let fetchUrl = self.remappedURI(nodeURI, baseURI);
|
|
|
+ let dbName = fetchUrl.split(".").join("_");
|
|
|
+
|
|
|
+ const parseComp = function (f) {
|
|
|
+
|
|
|
+ let result = JSON.parse(f);
|
|
|
+
|
|
|
+ let nativeObject = result;
|
|
|
+
|
|
|
+
|
|
|
+ if (nativeObject) {
|
|
|
+ callback_async(nativeObject);
|
|
|
+ self.virtualTime.resume("after loading " + nodeURI);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ self.logger.warnx("loadComponent", "error loading", nodeURI + ":", error);
|
|
|
+ errback_async(error);
|
|
|
+ self.virtualTime.resume("after loading " + nodeURI);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (dbName.includes("proxy")) {
|
|
|
+
|
|
|
+ let proxyDB = self.proxy ? _LCSDB.user(self.proxy) : _LCSDB.user(_LCS_WORLD_USER.pub);
|
|
|
+ let fileName = dbName + '_json';
|
|
|
+ let dbNode = proxyDB.get('proxy').get(fileName);
|
|
|
+ let nodeProm = new Promise(res => dbNode.once(res));
|
|
|
+
|
|
|
+ nodeProm.then(comp => {
|
|
|
+ parseComp(comp);
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ let worldName = dbName.split('/')[1];
|
|
|
+ let fileName = dbName.split('/')[2] + '_json';
|
|
|
+ let dbNode = _LCSDB.user(_LCS_WORLD_USER.pub).get('worlds').path(worldName).get(fileName);
|
|
|
+
|
|
|
+ let nodeProm = new Promise(res => dbNode.once(res))
|
|
|
+ nodeProm.then(comp => {
|
|
|
+ parseComp(comp);
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loadScript(scriptURI, baseURI, callback_async , errback_async ) {
|
|
|
+
|
|
|
+ let self = this;
|
|
|
+ if (scriptURI.match(RegExp("^data:application/javascript;base64,"))) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ callback_async(atob(scriptURI.substring(35)));
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ self.virtualTime.suspend("while loading " + scriptURI);
|
|
|
+
|
|
|
+ let fetchUrl = self.remappedURI(scriptURI, baseURI);
|
|
|
+ let dbName = fetchUrl.split(".").join("_")
|
|
|
+
|
|
|
+ const parseComp = function (res) {
|
|
|
+
|
|
|
+ let scriptText = res;
|
|
|
+
|
|
|
+ try {
|
|
|
+ callback_async(scriptText);
|
|
|
+ self.virtualTime.resume("after loading " + scriptURI);
|
|
|
+
|
|
|
+ } catch (e) {
|
|
|
+
|
|
|
+ self.logger.warnx("loadScript", "error loading", scriptURI + ":", error);
|
|
|
+ errback_async(error);
|
|
|
+ self.virtualTime.resume("after loading " + scriptURI);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let worldName = dbName.split('/')[1];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (dbName.includes("proxy")) {
|
|
|
+ let proxyDB = self.proxy ? _LCSDB.user(self.proxy) : _LCSDB.user(_LCS_WORLD_USER.pub);
|
|
|
+
|
|
|
+
|
|
|
+ let fileName = dbName;
|
|
|
+ let dbNode = proxyDB.get('proxy').get(fileName);
|
|
|
+ let nodeProm = new Promise(res => dbNode.once(res))
|
|
|
+
|
|
|
+ nodeProm.then(comp => {
|
|
|
+ parseComp(comp);
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ let fileName = dbName.split('/')[2];
|
|
|
+
|
|
|
+ let dbNode = _LCSDB.user(_LCS_WORLD_USER.pub).get('worlds').path(worldName).get(fileName);
|
|
|
+ let nodeProm = new Promise(res => dbNode.once(res))
|
|
|
+ nodeProm.then(comp => {
|
|
|
+ parseComp(comp);
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodePropertyHasSetter(nodeID, propertyName) {
|
|
|
+ var node = this.models.javascript.nodes[nodeID];
|
|
|
+ var setter = node.private.setters && node.private.setters[propertyName];
|
|
|
+ return typeof setter == "function" || setter instanceof Function;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodePropertyHasOwnSetter(nodeID, propertyName) {
|
|
|
+ var node = this.models.javascript.nodes[nodeID];
|
|
|
+ var setter = node.private.setters && node.private.setters.hasOwnProperty(propertyName) && node.private.setters[propertyName];
|
|
|
+ return typeof setter == "function" || setter instanceof Function;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeHasChild(nodeID, childName) {
|
|
|
+ var node = this.models.javascript.nodes[nodeID];
|
|
|
+ return childName in node.children;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ nodeHasOwnChild(nodeID, childName) {
|
|
|
+ var node = this.models.javascript.nodes[nodeID];
|
|
|
+ var hasChild = false;
|
|
|
+ if (parseInt(childName).toString() !== childName) {
|
|
|
+ hasChild = node.children.hasOwnProperty(childName);
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ for (var i = 0, il = node.children.length; i < il; i++) {
|
|
|
+ if (childName === node.children[i].name) {
|
|
|
+ hasChild = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return hasChild;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ componentIsURI(candidate) {
|
|
|
+ return (typeof candidate == "string" || candidate instanceof String) && !this.componentIsID(candidate);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ componentIsDescriptor(candidate) {
|
|
|
+ return typeof candidate == "object" && candidate != null && !this.isPrimitive(candidate);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ componentIsID(candidate) {
|
|
|
+ return this.isPrimitive(candidate) && this.models.object.exists(candidate) &&
|
|
|
+ !(this.components[candidate] instanceof Array);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ isPrimitive(candidate) {
|
|
|
+
|
|
|
+ switch (typeof candidate) {
|
|
|
+
|
|
|
+ case "string":
|
|
|
+ case "number":
|
|
|
+ case "boolean":
|
|
|
+ return true;
|
|
|
+
|
|
|
+ case "object":
|
|
|
+ return candidate instanceof String || candidate instanceof Number ||
|
|
|
+ candidate instanceof Boolean;
|
|
|
+
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ objectIsComponent(candidate) {
|
|
|
+
|
|
|
+ var componentAttributes = [
|
|
|
+ "extends",
|
|
|
+ "implements",
|
|
|
+ "source",
|
|
|
+ "type",
|
|
|
+ "properties",
|
|
|
+ "methods",
|
|
|
+ "events",
|
|
|
+ "children",
|
|
|
+ "scripts",
|
|
|
+ ];
|
|
|
+
|
|
|
+ var isComponent = false;
|
|
|
+
|
|
|
+ if (typeof candidate == "object" && candidate != null) {
|
|
|
+
|
|
|
+ isComponent = componentAttributes.some(function (attributeName) {
|
|
|
+ return candidate.hasOwnProperty(attributeName);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return isComponent;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ valueHasAccessors(candidate) {
|
|
|
+
|
|
|
+ var accessorAttributes = [
|
|
|
+ "get",
|
|
|
+ "set",
|
|
|
+ "value",
|
|
|
+ "node",
|
|
|
+ "create",
|
|
|
+ "undefined",
|
|
|
+ ];
|
|
|
+
|
|
|
+ var hasAccessors = false;
|
|
|
+
|
|
|
+ if (typeof candidate == "object" && candidate != null) {
|
|
|
+
|
|
|
+ hasAccessors = accessorAttributes.some(function (attributeName) {
|
|
|
+ return candidate.hasOwnProperty(attributeName);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasAccessors;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ valueHasBody(candidate) {
|
|
|
+
|
|
|
+ var bodyAttributes = [
|
|
|
+ "parameters",
|
|
|
+ "body",
|
|
|
+ "listeners",
|
|
|
+ ];
|
|
|
+
|
|
|
+ var hasBody = false;
|
|
|
+
|
|
|
+ if (typeof candidate == "object" && candidate != null) {
|
|
|
+
|
|
|
+ hasBody = bodyAttributes.some(function (attributeName) {
|
|
|
+ return candidate.hasOwnProperty(attributeName);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasBody;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ valueHasType(candidate) {
|
|
|
+
|
|
|
+ var typeAttributes = [
|
|
|
+ "source",
|
|
|
+ "text",
|
|
|
+ "type",
|
|
|
+ ];
|
|
|
+
|
|
|
+ var hasType = false;
|
|
|
+
|
|
|
+ if (typeof candidate == "object" && candidate != null) {
|
|
|
+
|
|
|
+ hasType = typeAttributes.some(function (attributeName) {
|
|
|
+ return candidate.hasOwnProperty(attributeName);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasType;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ namespaceEncodedName(memberName) {
|
|
|
+
|
|
|
+ if (typeof memberName === "object" && memberName instanceof Array) {
|
|
|
+ return (memberName.length !== 1) ? "vwf$" + memberName.join("$") : memberName[0];
|
|
|
+ } else {
|
|
|
+ return memberName;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ normalizedComponent(component) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (this.componentIsURI(component)) {
|
|
|
+ if (component.match(/\.vwf$/)) {
|
|
|
+ component = {
|
|
|
+ extends: component
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ component = {
|
|
|
+ source: component
|
|
|
+ };
|
|
|
+ }
|
|
|
+ } else if (this.componentIsID(component)) {
|
|
|
+ component = {
|
|
|
+ extends: component
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (component.source && !component.type) {
|
|
|
+
|
|
|
+ var match = component.source.match(/\.([^.]*)$/);
|
|
|
+
|
|
|
+ if (match) {
|
|
|
+
|
|
|
+ switch (match[1]) {
|
|
|
+ case "unity3d":
|
|
|
+ component.type = "application/vnd.unity";
|
|
|
+ break;
|
|
|
+ case "dae":
|
|
|
+ component.type = "model/vnd.collada+xml";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (component.type && !component.extends) {
|
|
|
+
|
|
|
+ switch (component.type) {
|
|
|
+ case "application/vnd.unity":
|
|
|
+ component.extends = "http://vwf.example.com/scene.vwf";
|
|
|
+ break;
|
|
|
+ case "model/vnd.collada+xml":
|
|
|
+ component.extends = "http://vwf.example.com/navscene.vwf";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return component;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ normalizedHandler(handler, defaultParameters) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (typeof handler !== "object" || handler instanceof Array) {
|
|
|
+ handler = {
|
|
|
+ body: handler
|
|
|
+ };
|
|
|
+ } else if (this.configuration["preserve-script-closures"] && (typeof handler == "function" || handler instanceof Function)) {
|
|
|
+ handler = {
|
|
|
+ body: handler
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!handler.parameters && defaultParameters) {
|
|
|
+ handler.parameters = defaultParameters;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (handler.type === undefined) {
|
|
|
+ if (typeof handler.body === "string" || handler.body instanceof String) {
|
|
|
+ handler.type = "application/javascript";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return handler;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loggableFields(fields) {
|
|
|
+ return this.utility.transform(fields, this.utility.transforms.transit);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loggableComponent(component) {
|
|
|
+ return this.utility.transform(component, this.loggableComponentTransformation);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loggableValue(value) {
|
|
|
+ let self = this;
|
|
|
+ return this.utility.transform(value, function (object, names, depth) {
|
|
|
+ object = self.utility.transforms.transit(object, names, depth);
|
|
|
+ return typeof object == "number" ? Number(object.toPrecision(5)) : object;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loggableValues(values) {
|
|
|
+ return this.loggableValue(values);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loggableIndexedValues(values) {
|
|
|
+ return this.loggableValue(values);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loggableScript(script) {
|
|
|
+ return (script || "").replace(/\s+/g, " ").substring(0, 100);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ remappedURI(uri, baseURI) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (baseURI && uri[0] !== "/") {
|
|
|
+
|
|
|
+ let newURI = "";
|
|
|
+ let parts = baseURI.split('/');
|
|
|
+ parts[parts.length - 1] = uri;
|
|
|
+ parts.map(el => {
|
|
|
+ newURI = newURI + el + '/';
|
|
|
+ })
|
|
|
+
|
|
|
+ return newURI.slice(0, -1)
|
|
|
+
|
|
|
+ }
|
|
|
+ return uri
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ resolvedDescriptor(component, baseURI) {
|
|
|
+
|
|
|
+ return this.utility.transform(component, resolvedDescriptorTransformationWithBaseURI);
|
|
|
+
|
|
|
+ function resolvedDescriptorTransformationWithBaseURI(object, names, depth) {
|
|
|
+ return resolvedDescriptorTransformation.call(this, object, names, depth, baseURI);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loggableComponentTransformation(object, names, depth) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var markers = this.descriptorMarkers(object, names, depth);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ switch (markers.containerName) {
|
|
|
+
|
|
|
+ case "extends":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (markers.memberIndex == 0 && this.componentIsDescriptor(object)) {
|
|
|
+ return {};
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "implements":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (markers.memberIndex == 0 && this.componentIsDescriptor(object)) {
|
|
|
+ return {};
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "properties":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (markers.memberIndex == 0 && !this.valueHasAccessors(object) ||
|
|
|
+ markers.memberIndex == 1 && names[0] == "value") {
|
|
|
+ return this.loggableValue(object);
|
|
|
+ } else if (markers.memberIndex == 1 && (names[0] == "get" || names[0] == "set")) {
|
|
|
+ return "...";
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "methods":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (markers.memberIndex == 0 && !this.valueHasBody(object) ||
|
|
|
+ markers.memberIndex == 1 && names[0] == "body") {
|
|
|
+ return "...";
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "events":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "children":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (markers.memberIndex == 0 && this.componentIsDescriptor(object)) {
|
|
|
+ return {};
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "scripts":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (markers.memberIndex == 0 && !this.valueHasType(object) ||
|
|
|
+ markers.memberIndex == 1 && names[0] == "text") {
|
|
|
+ return "...";
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ resolvedDescriptorTransformation(object, names, depth, baseURI) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var markers = this.descriptorMarkers(object, names, depth);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ switch (markers.containerName) {
|
|
|
+
|
|
|
+ case "extends":
|
|
|
+ case "implements":
|
|
|
+ case "source":
|
|
|
+ case "children":
|
|
|
+
|
|
|
+ if (markers.memberIndex == 0 && this.componentIsURI(object)) {
|
|
|
+ return object
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "scripts":
|
|
|
+
|
|
|
+ if (markers.memberIndex == 1 && names[0] == "source") {
|
|
|
+ return object
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ descriptorMarkers(object, names, depth) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var componentIndex = names.length;
|
|
|
+
|
|
|
+ while (componentIndex > 2 && names[componentIndex - 1] == "children") {
|
|
|
+ componentIndex -= 2;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (componentIndex > 0) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var containerIndex = componentIndex - 1;
|
|
|
+ var containerName = names[containerIndex];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (containerName == "extends") {
|
|
|
+
|
|
|
+ var memberIndex = containerIndex;
|
|
|
+ var memberName = names[memberIndex];
|
|
|
+
|
|
|
+ } else if (containerName == "implements") {
|
|
|
+
|
|
|
+ if (containerIndex > 0) {
|
|
|
+ if (typeof names[containerIndex - 1] == "number") {
|
|
|
+ var memberIndex = containerIndex - 1;
|
|
|
+ var memberName = names[memberIndex];
|
|
|
+ } else {
|
|
|
+ var memberIndex = containerIndex;
|
|
|
+ var memberName = undefined;
|
|
|
+ }
|
|
|
+ } else if (typeof object != "object" || !(object instanceof Array)) {
|
|
|
+ var memberIndex = containerIndex;
|
|
|
+ var memberName = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (containerName == "source" || containerName == "type") {
|
|
|
+
|
|
|
+ var memberIndex = containerIndex;
|
|
|
+ var memberName = names[memberIndex];
|
|
|
+
|
|
|
+ } else if (containerName == "properties" || containerName == "methods" || containerName == "events" ||
|
|
|
+ containerName == "children") {
|
|
|
+
|
|
|
+ if (containerIndex > 0) {
|
|
|
+ var memberIndex = containerIndex - 1;
|
|
|
+ var memberName = names[memberIndex];
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (containerName == "scripts") {
|
|
|
+
|
|
|
+ if (containerIndex > 0) {
|
|
|
+ if (typeof names[containerIndex - 1] == "number") {
|
|
|
+ var memberIndex = containerIndex - 1;
|
|
|
+ var memberName = names[memberIndex];
|
|
|
+ } else {
|
|
|
+ var memberIndex = containerIndex;
|
|
|
+ var memberName = undefined;
|
|
|
+ }
|
|
|
+ } else if (typeof object != "object" || !(object instanceof Array)) {
|
|
|
+ var memberIndex = containerIndex;
|
|
|
+ var memberName = undefined;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ containerIndex = undefined;
|
|
|
+ containerName = undefined;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ containerIndex: containerIndex,
|
|
|
+ containerName: containerName,
|
|
|
+ memberIndex: memberIndex,
|
|
|
+ memberName: memberName,
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ find(nodeID, matchPattern, initializedOnly) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var rootID = nodeID ? this.root(nodeID, initializedOnly) :
|
|
|
+ this.application(initializedOnly);
|
|
|
+
|
|
|
+ return this.xpath.resolve(matchPattern, rootID, nodeID,
|
|
|
+ resolverWithInitializedOnly, this);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ function resolverWithInitializedOnly(step, contextID, resolveAttributes) {
|
|
|
+ return this.xpathResolver.call(this, step, contextID, resolveAttributes, initializedOnly);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ xpathResolver(step, contextID, resolveAttributes, initializedOnly) {
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ var resultIDs = [];
|
|
|
+
|
|
|
+ switch (step.axis) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ case "ancestor-or-self":
|
|
|
+ resultIDs.push(contextID);
|
|
|
+ Array.prototype.push.apply(resultIDs, this.ancestors(contextID, initializedOnly));
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "ancestor":
|
|
|
+ Array.prototype.push.apply(resultIDs, this.ancestors(contextID, initializedOnly));
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "parent":
|
|
|
+ var parentID = this.parent(contextID, initializedOnly);
|
|
|
+ parentID && resultIDs.push(parentID);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "self":
|
|
|
+ resultIDs.push(contextID);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "child":
|
|
|
+ Array.prototype.push.apply(resultIDs,
|
|
|
+ this.children(contextID, initializedOnly).filter(function (childID) {
|
|
|
+ return childID;
|
|
|
+ }, this)
|
|
|
+ );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "descendant":
|
|
|
+ Array.prototype.push.apply(resultIDs,
|
|
|
+ this.descendants(contextID, initializedOnly).filter(function (descendantID) {
|
|
|
+ return descendantID;
|
|
|
+ }, this)
|
|
|
+ );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "descendant-or-self":
|
|
|
+ resultIDs.push(contextID);
|
|
|
+ Array.prototype.push.apply(resultIDs,
|
|
|
+ this.descendants(contextID, initializedOnly).filter(function (descendantID) {
|
|
|
+ return descendantID;
|
|
|
+ }, this)
|
|
|
+ );
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ case "attribute":
|
|
|
+ if (resolveAttributes) {
|
|
|
+ resultIDs.push("@" + contextID);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (step.kind) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ case undefined:
|
|
|
+
|
|
|
+ resultIDs = resultIDs.filter(function (resultID) {
|
|
|
+ if (resultID[0] != "@") {
|
|
|
+ return self.xpathNodeMatchesStep.call(this, resultID, step.name);
|
|
|
+ } else {
|
|
|
+ return self.xpathPropertyMatchesStep.call(this, resultID.slice(1), step.name);
|
|
|
+ }
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ case "element":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ resultIDs = resultIDs.filter(function (resultID) {
|
|
|
+ return resultID[0] != "@" && self.xpathNodeMatchesStep.call(this, resultID, step.name, step.type);
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ case "attribute":
|
|
|
+
|
|
|
+ resultIDs = resultIDs.filter(function (resultID) {
|
|
|
+ return resultID[0] == "@" && self.xpathPropertyMatchesStep.call(this, resultID.slice(1), step.name);
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ case "doc":
|
|
|
+
|
|
|
+ if (this.root(contextID, initializedOnly)) {
|
|
|
+ var globalID = this.global(step.name, initializedOnly);
|
|
|
+ resultIDs = globalID ? [globalID] : [];
|
|
|
+ } else {
|
|
|
+ resultIDs = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ case "node":
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ default:
|
|
|
+
|
|
|
+ resultIDs = [];
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultIDs;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ xpathNodeMatchesStep(nodeID, name, type) {
|
|
|
+
|
|
|
+ if (name && this.name(nodeID) != name) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var matches_type = !type || this.uri(nodeID) == type ||
|
|
|
+ this.prototypes(nodeID, true).some(function (prototypeID) {
|
|
|
+ return this.uri(prototypeID) == type;
|
|
|
+ }, this);
|
|
|
+
|
|
|
+ return matches_type;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ xpathPropertyMatchesStep(nodeID, name) {
|
|
|
+
|
|
|
+ var properties = this.models.object.properties(nodeID);
|
|
|
+
|
|
|
+ if (name) {
|
|
|
+ return properties[name];
|
|
|
+ } else {
|
|
|
+ return Object.keys(properties).some(function (propertyName) {
|
|
|
+ return properties[propertyName];
|
|
|
+ }, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ mergeDescriptors(nodeDescriptor, prototypeDescriptor) {
|
|
|
+
|
|
|
+ if (nodeDescriptor.implements) {
|
|
|
+ prototypeDescriptor.implements = (prototypeDescriptor.implements || []).
|
|
|
+ concat(nodeDescriptor.implements);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nodeDescriptor.source) {
|
|
|
+ prototypeDescriptor.source = nodeDescriptor.source;
|
|
|
+ prototypeDescriptor.type = nodeDescriptor.type;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nodeDescriptor.properties) {
|
|
|
+
|
|
|
+ prototypeDescriptor.properties = prototypeDescriptor.properties || {};
|
|
|
+
|
|
|
+ for (var propertyName in nodeDescriptor.properties) {
|
|
|
+ prototypeDescriptor.properties[propertyName] = nodeDescriptor.properties[propertyName];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nodeDescriptor.methods) {
|
|
|
+
|
|
|
+ prototypeDescriptor.methods = prototypeDescriptor.methods || {};
|
|
|
+
|
|
|
+ for (var methodName in nodeDescriptor.methods) {
|
|
|
+ prototypeDescriptor.methods[methodName] = nodeDescriptor.methods[methodName];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nodeDescriptor.events) {
|
|
|
+
|
|
|
+ prototypeDescriptor.events = prototypeDescriptor.events || {};
|
|
|
+
|
|
|
+ for (var eventName in nodeDescriptor.events) {
|
|
|
+ prototypeDescriptor.events[eventName] = nodeDescriptor.events[eventName];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nodeDescriptor.children) {
|
|
|
+
|
|
|
+ prototypeDescriptor.children = prototypeDescriptor.children || {};
|
|
|
+
|
|
|
+ for (var childName in nodeDescriptor.children) {
|
|
|
+ prototypeDescriptor.children[childName] = nodeDescriptor.children[childName];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nodeDescriptor.scripts) {
|
|
|
+ prototypeDescriptor.scripts = (prototypeDescriptor.scripts || []).
|
|
|
+ concat(nodeDescriptor.scripts);
|
|
|
+ }
|
|
|
+
|
|
|
+ return prototypeDescriptor;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ enumerable(value) {
|
|
|
+ return {
|
|
|
+ value: value,
|
|
|
+ enumerable: true,
|
|
|
+ writable: false,
|
|
|
+ configurable: false,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ writable(value) {
|
|
|
+ return {
|
|
|
+ value: value,
|
|
|
+ enumerable: true,
|
|
|
+ writable: true,
|
|
|
+ configurable: false,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ configurable(value) {
|
|
|
+ return {
|
|
|
+ value: value,
|
|
|
+ enumerable: true,
|
|
|
+ writable: true,
|
|
|
+ configurable: true,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ async chooseConnection(data) {
|
|
|
+ if (this.isLuminary) {
|
|
|
+ return await this.luminary.connect(data)
|
|
|
+ } else {
|
|
|
+ return data
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+export {
|
|
|
+ VWF
|
|
|
+}
|