diff src/implab/di/ValueDescriptor.js @ 0:fc2517695ee1

Initial commit, draft import of existing work
author cin
date Thu, 01 Jun 2017 13:20:03 +0300
parents
children 93fb6c09f2e1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/implab/di/ValueDescriptor.js	Thu Jun 01 13:20:03 2017 +0300
@@ -0,0 +1,38 @@
+define([ "dojo/_base/declare", "./Descriptor", "../safe" ],
+
+function(declare, Descriptor, safe) {
+    return declare(Descriptor, {
+        _value : undefined,
+        _raw : false,
+        constructor : function(value, raw) {
+            this._value = value;
+            this._raw = Boolean(raw);
+        },
+
+        activate : function(context, name) {
+            context.enter(name, this);
+            var v = this._raw ? this._value : context.parse(
+                this._value,
+                ".params");
+            context.leave(this);
+            return v;
+        },
+
+        isInstanceCreated : function() {
+            return this._raw;
+        },
+
+        getInstance : function() {
+            if (!this._raw)
+                throw new Error("The instance isn't constructed");
+            return this._value;
+        },
+
+        toString : function() {
+            if (this._raw)
+                return "@value {raw}";
+            else
+                return safe.isNull(this._value) ? "@value <null>" : "@value";
+        }
+    });
+});
\ No newline at end of file