view src/implab/di/ValueDescriptor.js @ 1:93fb6c09f2e1

minor fixes
author cin
date Fri, 02 Jun 2017 18:15:22 +0300
parents fc2517695ee1
children
line wrap: on
line source

define([ "../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";
        }
    });
});