objectmakr
Advanced tools
Comparing version 0.7.2 to 0.7.3
@@ -70,2 +70,17 @@ define(function() { return /******/ (function(modules) { // webpackBootstrap | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(1)], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, ObjectMakr_1) { | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(ObjectMakr_1); | ||
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), | ||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports) { | ||
@@ -75,2 +90,15 @@ "use strict"; | ||
/** | ||
* Deep copies all members of the donor to the recipient recursively. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
*/ | ||
var shallowCopy = function (recipient, donor) { | ||
for (var i in donor) { | ||
if ({}.hasOwnProperty.call(donor, i)) { | ||
recipient[i] = donor[i]; | ||
} | ||
} | ||
}; | ||
/** | ||
* An abstract factory for dynamic attribute-based classes. | ||
@@ -95,37 +123,15 @@ */ | ||
this.generateClassParentNames(this.inheritance, "Object"); | ||
if (settings.doPropertiesFull) { | ||
this.propertiesFull = {}; | ||
} | ||
} | ||
/** | ||
* Gets the immediate (non-inherited) properties of a class. | ||
* Gets the prototype of a class, which contains its base properties. | ||
* | ||
* @template T Type of class properties being retrieved. | ||
* @param name Name of a class. | ||
* @returns The properties for a the class. | ||
* @returns Base properties for the class. | ||
*/ | ||
ObjectMakr.prototype.getPropertiesOf = function (name) { | ||
ObjectMakr.prototype.getPrototypeOf = function (name) { | ||
this.ensureClassExists(name); | ||
return this.properties[name]; | ||
return this.classes[name].prototype; | ||
}; | ||
/** | ||
* Gets the full properties of a class. | ||
* | ||
* @param name Name of a class. | ||
* @returns Full properties for a the class, if doPropertiesFull is true. | ||
*/ | ||
ObjectMakr.prototype.getFullPropertiesOf = function (name) { | ||
this.ensureClassExists(name); | ||
return this.propertiesFull ? this.propertiesFull[name] : undefined; | ||
}; | ||
/** | ||
* Gets a named class. | ||
* | ||
* @param name Name of a class. | ||
* @returns The class. | ||
*/ | ||
ObjectMakr.prototype.getClass = function (name) { | ||
this.ensureClassExists(name); | ||
return this.classes[name]; | ||
}; | ||
/** | ||
* Gets whether a class exists. | ||
@@ -140,3 +146,3 @@ * | ||
/** | ||
* Creates a new instance of the specified class. | ||
* Creates a new instance of a class. | ||
* | ||
@@ -150,10 +156,10 @@ * @template T Type of class being created. | ||
this.ensureClassExists(name); | ||
var output = new this.classes[name](); | ||
var instance = new this.classes[name](); | ||
if (settings !== undefined) { | ||
this.proliferate(output, settings); | ||
shallowCopy(instance, settings); | ||
} | ||
if (this.onMake && output[this.onMake]) { | ||
output[this.onMake].call(output, output, name, settings, (this.propertiesFull ? this.propertiesFull : this.properties)[name]); | ||
if (this.onMake && instance[this.onMake] !== undefined) { | ||
instance[this.onMake].call(instance, instance, name); | ||
} | ||
return output; | ||
return instance; | ||
}; | ||
@@ -174,5 +180,2 @@ /** | ||
var parentName = this.classParentNames[name]; | ||
if (this.propertiesFull) { | ||
this.propertiesFull[name] = {}; | ||
} | ||
if (parentName) { | ||
@@ -187,7 +190,2 @@ this.extendClass(newClass, name, parentName); | ||
} | ||
if (this.propertiesFull) { | ||
for (var i in this.properties[name]) { | ||
this.propertiesFull[name][i] = this.properties[name][i]; | ||
} | ||
} | ||
return newClass; | ||
@@ -208,7 +206,2 @@ }; | ||
newClass.prototype.constructor = newClass; | ||
if (this.propertiesFull) { | ||
for (var i in this.propertiesFull[parentName]) { | ||
this.propertiesFull[name][i] = this.propertiesFull[parentName][i]; | ||
} | ||
} | ||
}; | ||
@@ -218,8 +211,8 @@ /** | ||
* | ||
* @param properties An Array with indiced versions of properties. | ||
* @param properties An array with indiced versions of properties. | ||
*/ | ||
ObjectMakr.prototype.processIndexMappedProperties = function (indexMap) { | ||
ObjectMakr.prototype.processIndexMappedProperties = function (shorthandProperties) { | ||
var output = {}; | ||
for (var i = 0; i < indexMap.length; i += 1) { | ||
output[this.indexMap[i]] = indexMap[i]; | ||
for (var i = 0; i < shorthandProperties.length; i += 1) { | ||
output[this.indexMap[i]] = shorthandProperties[i]; | ||
} | ||
@@ -253,22 +246,2 @@ return output; | ||
}; | ||
/** | ||
* Deep copies all members of the donor to the recipient recursively. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
*/ | ||
ObjectMakr.prototype.proliferate = function (recipient, donor) { | ||
for (var i in donor) { | ||
var setting = donor[i]; | ||
if (typeof setting === "object") { | ||
if (!this.hasOwnProperty.call(recipient, i)) { | ||
recipient[i] = new setting.constructor(); | ||
} | ||
this.proliferate(recipient[i], setting); | ||
} | ||
else { | ||
recipient[i] = setting; | ||
} | ||
} | ||
}; | ||
return ObjectMakr; | ||
@@ -275,0 +248,0 @@ }()); |
var typedoc = typedoc || {}; | ||
typedoc.search = typedoc.search || {}; | ||
typedoc.search.data = {"kinds":{"1":"External module","64":"Function","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","4194304":"Type alias"},"rows":[{"id":0,"kind":1,"name":"\"IObjectMakr\"","url":"modules/_iobjectmakr_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":256,"name":"IClassInheritance","url":"interfaces/_iobjectmakr_.iclassinheritance.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":2,"kind":256,"name":"IClassProperties","url":"interfaces/_iobjectmakr_.iclassproperties.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":3,"kind":256,"name":"IClassFunctions","url":"interfaces/_iobjectmakr_.iclassfunctions.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":4,"kind":256,"name":"IClassParentNames","url":"interfaces/_iobjectmakr_.iclassparentnames.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":5,"kind":256,"name":"IClass","url":"interfaces/_iobjectmakr_.iclass.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":6,"kind":512,"name":"constructor","url":"interfaces/_iobjectmakr_.iclass.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-interface","parent":"\"IObjectMakr\".IClass"},{"id":7,"kind":256,"name":"IObjectMakrSettings","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":8,"kind":1024,"name":"inheritance","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#inheritance","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":9,"kind":1024,"name":"properties","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#properties","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":10,"kind":1024,"name":"doPropertiesFull","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#dopropertiesfull","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":11,"kind":1024,"name":"indexMap","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#indexmap","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":12,"kind":1024,"name":"onMake","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#onmake","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":13,"kind":1024,"name":"functions","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#functions","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":14,"kind":256,"name":"IObjectMakr","url":"interfaces/_iobjectmakr_.iobjectmakr.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":15,"kind":2048,"name":"getPropertiesOf","url":"interfaces/_iobjectmakr_.iobjectmakr.html#getpropertiesof","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakr"},{"id":16,"kind":2048,"name":"getFullPropertiesOf","url":"interfaces/_iobjectmakr_.iobjectmakr.html#getfullpropertiesof","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakr"},{"id":17,"kind":2048,"name":"getClass","url":"interfaces/_iobjectmakr_.iobjectmakr.html#getclass","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakr"},{"id":18,"kind":2048,"name":"hasClass","url":"interfaces/_iobjectmakr_.iobjectmakr.html#hasclass","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakr"},{"id":19,"kind":2048,"name":"make","url":"interfaces/_iobjectmakr_.iobjectmakr.html#make","classes":"tsd-kind-method tsd-parent-kind-interface tsd-has-type-parameter","parent":"\"IObjectMakr\".IObjectMakr"},{"id":20,"kind":4194304,"name":"IOnMakeFunction","url":"modules/_iobjectmakr_.html#ionmakefunction","classes":"tsd-kind-type-alias tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":21,"kind":65536,"name":"__type","url":"modules/_iobjectmakr_.html#ionmakefunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"IObjectMakr\".IOnMakeFunction"},{"id":22,"kind":1,"name":"\"ObjectMakr\"","url":"modules/_objectmakr_.html","classes":"tsd-kind-external-module"},{"id":23,"kind":128,"name":"ObjectMakr","url":"classes/_objectmakr_.objectmakr.html","classes":"tsd-kind-class tsd-parent-kind-external-module","parent":"\"ObjectMakr\""},{"id":24,"kind":1024,"name":"inheritance","url":"classes/_objectmakr_.objectmakr.html#inheritance","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":25,"kind":1024,"name":"properties","url":"classes/_objectmakr_.objectmakr.html#properties","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":26,"kind":1024,"name":"propertiesFull","url":"classes/_objectmakr_.objectmakr.html#propertiesfull","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":27,"kind":1024,"name":"classes","url":"classes/_objectmakr_.objectmakr.html#classes","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":28,"kind":1024,"name":"classParentNames","url":"classes/_objectmakr_.objectmakr.html#classparentnames","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":29,"kind":1024,"name":"indexMap","url":"classes/_objectmakr_.objectmakr.html#indexmap","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":30,"kind":1024,"name":"onMake","url":"classes/_objectmakr_.objectmakr.html#onmake","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":31,"kind":512,"name":"constructor","url":"classes/_objectmakr_.objectmakr.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"ObjectMakr\".ObjectMakr"},{"id":32,"kind":2048,"name":"getPropertiesOf","url":"classes/_objectmakr_.objectmakr.html#getpropertiesof","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ObjectMakr\".ObjectMakr"},{"id":33,"kind":2048,"name":"getFullPropertiesOf","url":"classes/_objectmakr_.objectmakr.html#getfullpropertiesof","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ObjectMakr\".ObjectMakr"},{"id":34,"kind":2048,"name":"getClass","url":"classes/_objectmakr_.objectmakr.html#getclass","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ObjectMakr\".ObjectMakr"},{"id":35,"kind":2048,"name":"hasClass","url":"classes/_objectmakr_.objectmakr.html#hasclass","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ObjectMakr\".ObjectMakr"},{"id":36,"kind":2048,"name":"make","url":"classes/_objectmakr_.objectmakr.html#make","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter","parent":"\"ObjectMakr\".ObjectMakr"},{"id":37,"kind":2048,"name":"createClass","url":"classes/_objectmakr_.objectmakr.html#createclass","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":38,"kind":2048,"name":"extendClass","url":"classes/_objectmakr_.objectmakr.html#extendclass","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":39,"kind":2048,"name":"processIndexMappedProperties","url":"classes/_objectmakr_.objectmakr.html#processindexmappedproperties","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":40,"kind":2048,"name":"generateClassParentNames","url":"classes/_objectmakr_.objectmakr.html#generateclassparentnames","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":41,"kind":2048,"name":"ensureClassExists","url":"classes/_objectmakr_.objectmakr.html#ensureclassexists","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":42,"kind":2048,"name":"proliferate","url":"classes/_objectmakr_.objectmakr.html#proliferate","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":43,"kind":1,"name":"\"fakes\"","url":"modules/_fakes_.html","classes":"tsd-kind-external-module"},{"id":44,"kind":64,"name":"stubObjectMakr","url":"modules/_fakes_.html#stubobjectmakr","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"fakes\""},{"id":45,"kind":1,"name":"\"index\"","url":"modules/_index_.html","classes":"tsd-kind-external-module"},{"id":46,"kind":1,"name":"\"ObjectMakr.test\"","url":"modules/_objectmakr_test_.html","classes":"tsd-kind-external-module"}]}; | ||
typedoc.search.data = {"kinds":{"1":"External module","64":"Function","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","4194304":"Type alias"},"rows":[{"id":0,"kind":1,"name":"\"IObjectMakr\"","url":"modules/_iobjectmakr_.html","classes":"tsd-kind-external-module"},{"id":1,"kind":256,"name":"IClassInheritance","url":"interfaces/_iobjectmakr_.iclassinheritance.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":2,"kind":256,"name":"IClassProperties","url":"interfaces/_iobjectmakr_.iclassproperties.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":3,"kind":256,"name":"IClassFunctions","url":"interfaces/_iobjectmakr_.iclassfunctions.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":4,"kind":256,"name":"IClassParentNames","url":"interfaces/_iobjectmakr_.iclassparentnames.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":5,"kind":256,"name":"IClass","url":"interfaces/_iobjectmakr_.iclass.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":6,"kind":512,"name":"constructor","url":"interfaces/_iobjectmakr_.iclass.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-interface","parent":"\"IObjectMakr\".IClass"},{"id":7,"kind":256,"name":"IObjectMakrSettings","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":8,"kind":1024,"name":"inheritance","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#inheritance","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":9,"kind":1024,"name":"properties","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#properties","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":10,"kind":1024,"name":"indexMap","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#indexmap","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":11,"kind":1024,"name":"onMake","url":"interfaces/_iobjectmakr_.iobjectmakrsettings.html#onmake","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakrSettings"},{"id":12,"kind":256,"name":"IObjectMakr","url":"interfaces/_iobjectmakr_.iobjectmakr.html","classes":"tsd-kind-interface tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":13,"kind":2048,"name":"getPrototypeOf","url":"interfaces/_iobjectmakr_.iobjectmakr.html#getprototypeof","classes":"tsd-kind-method tsd-parent-kind-interface tsd-has-type-parameter","parent":"\"IObjectMakr\".IObjectMakr"},{"id":14,"kind":2048,"name":"hasClass","url":"interfaces/_iobjectmakr_.iobjectmakr.html#hasclass","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"\"IObjectMakr\".IObjectMakr"},{"id":15,"kind":2048,"name":"make","url":"interfaces/_iobjectmakr_.iobjectmakr.html#make","classes":"tsd-kind-method tsd-parent-kind-interface tsd-has-type-parameter","parent":"\"IObjectMakr\".IObjectMakr"},{"id":16,"kind":4194304,"name":"IOnMakeFunction","url":"modules/_iobjectmakr_.html#ionmakefunction","classes":"tsd-kind-type-alias tsd-parent-kind-external-module","parent":"\"IObjectMakr\""},{"id":17,"kind":65536,"name":"__type","url":"modules/_iobjectmakr_.html#ionmakefunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"IObjectMakr\".IOnMakeFunction"},{"id":18,"kind":1,"name":"\"ObjectMakr\"","url":"modules/_objectmakr_.html","classes":"tsd-kind-external-module"},{"id":19,"kind":128,"name":"ObjectMakr","url":"classes/_objectmakr_.objectmakr.html","classes":"tsd-kind-class tsd-parent-kind-external-module","parent":"\"ObjectMakr\""},{"id":20,"kind":1024,"name":"inheritance","url":"classes/_objectmakr_.objectmakr.html#inheritance","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":21,"kind":1024,"name":"properties","url":"classes/_objectmakr_.objectmakr.html#properties","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":22,"kind":1024,"name":"classes","url":"classes/_objectmakr_.objectmakr.html#classes","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":23,"kind":1024,"name":"classParentNames","url":"classes/_objectmakr_.objectmakr.html#classparentnames","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":24,"kind":1024,"name":"indexMap","url":"classes/_objectmakr_.objectmakr.html#indexmap","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":25,"kind":1024,"name":"onMake","url":"classes/_objectmakr_.objectmakr.html#onmake","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":26,"kind":512,"name":"constructor","url":"classes/_objectmakr_.objectmakr.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"\"ObjectMakr\".ObjectMakr"},{"id":27,"kind":2048,"name":"getPrototypeOf","url":"classes/_objectmakr_.objectmakr.html#getprototypeof","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter","parent":"\"ObjectMakr\".ObjectMakr"},{"id":28,"kind":2048,"name":"hasClass","url":"classes/_objectmakr_.objectmakr.html#hasclass","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"ObjectMakr\".ObjectMakr"},{"id":29,"kind":2048,"name":"make","url":"classes/_objectmakr_.objectmakr.html#make","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter","parent":"\"ObjectMakr\".ObjectMakr"},{"id":30,"kind":2048,"name":"createClass","url":"classes/_objectmakr_.objectmakr.html#createclass","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":31,"kind":2048,"name":"extendClass","url":"classes/_objectmakr_.objectmakr.html#extendclass","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":32,"kind":2048,"name":"processIndexMappedProperties","url":"classes/_objectmakr_.objectmakr.html#processindexmappedproperties","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":33,"kind":2048,"name":"generateClassParentNames","url":"classes/_objectmakr_.objectmakr.html#generateclassparentnames","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":34,"kind":2048,"name":"ensureClassExists","url":"classes/_objectmakr_.objectmakr.html#ensureclassexists","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"\"ObjectMakr\".ObjectMakr"},{"id":35,"kind":64,"name":"shallowCopy","url":"modules/_objectmakr_.html#shallowcopy","classes":"tsd-kind-function tsd-parent-kind-external-module tsd-has-type-parameter tsd-is-not-exported","parent":"\"ObjectMakr\""},{"id":36,"kind":1,"name":"\"fakes\"","url":"modules/_fakes_.html","classes":"tsd-kind-external-module"},{"id":37,"kind":64,"name":"stubObjectMakr","url":"modules/_fakes_.html#stubobjectmakr","classes":"tsd-kind-function tsd-parent-kind-external-module","parent":"\"fakes\""},{"id":38,"kind":1,"name":"\"index\"","url":"modules/_index_.html","classes":"tsd-kind-external-module"},{"id":39,"kind":1,"name":"\"ObjectMakr.test\"","url":"modules/_objectmakr_test_.html","classes":"tsd-kind-external-module"}]}; |
@@ -10,9 +10,10 @@ { | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
}, | ||
"description": "An abstract factory for dynamic attribute-based classes.", | ||
"devDependencies": { | ||
"@types/chai": "^4.0.4", | ||
"@types/lolex": "^1.5.32", | ||
"@types/mocha": "^2.2.44", | ||
"@types/sinon": "^4.0.0", | ||
"@types/lolex": "^2.1.1", | ||
"@types/mocha": "^2.2.46", | ||
"@types/sinon": "^4.1.3", | ||
"@types/sinon-chai": "^2.7.29", | ||
@@ -22,11 +23,12 @@ "chai": "^4.1.2", | ||
"lolex": "^2.3.0", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^4.0.1", | ||
"mocha-headless-chrome": "^1.7.1", | ||
"mocha-headless-chrome": "^1.8.1", | ||
"requirejs": "^2.3.5", | ||
"run-for-every-file": "^1.1.0", | ||
"shenanigans-manager": "^0.2.5", | ||
"sinon": "^4.1.2", | ||
"shenanigans-manager": "^0.2.20", | ||
"sinon": "^4.1.5", | ||
"sinon-chai": "^2.14.0", | ||
"tslint": "5.8.0", | ||
"tsutils": "^2.14.0", | ||
"tslint": "5.9.1", | ||
"tsutils": "^2.17.0", | ||
"typedoc": "^0.9.0", | ||
@@ -55,8 +57,9 @@ "typescript": "^2.6.2", | ||
"src:tsc": "tsc -p .", | ||
"src:tslint": "tslint -c tslint.json -e ./node_modules/**/*.ts* -p tsconfig.json -t stylish", | ||
"src:tslint": "tslint -c tslint.json -p tsconfig.json -t stylish", | ||
"test": "npm run test:setup && npm run test:run", | ||
"test:run": "mocha-headless-chrome --file test/index.html", | ||
"test:setup": "npm run test:setup:copy && npm run test:setup:html && npm run test:setup:tsc", | ||
"test:setup": "npm run test:setup:dir && npm run test:setup:copy && npm run test:setup:html && npm run test:setup:tsc", | ||
"test:setup:copy": "npm run test:setup:copy:default", | ||
"test:setup:copy:default": "run-for-every-file --dot --src \"node_modules/shenanigans-manager/setup/test/\" --file \"**/*\" --run \"mustache package.json {{src-file}} ./test/{{file}}\" --dest \".\" --only-files", | ||
"test:setup:dir": "mkdirp test", | ||
"test:setup:html": "shenanigans-manager generate-test-html", | ||
@@ -71,3 +74,3 @@ "test:setup:tsc": "tsc -p test", | ||
"types": "./src/index.d.ts", | ||
"version": "0.7.2" | ||
} | ||
"version": "0.7.3" | ||
} |
134
README.md
<!-- {{Top}} --> | ||
# ObjectMakr | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/FullScreenShenanigans/ObjectMakr.svg)](https://greenkeeper.io/) | ||
[![Build Status](https://travis-ci.org/FullScreenShenanigans/ObjectMakr.svg?branch=master)](https://travis-ci.org/FullScreenShenanigans/ObjectMakr) | ||
@@ -9,8 +10,139 @@ [![NPM version](https://badge.fury.io/js/objectmakr.svg)](http://badge.fury.io/js/objectmakr) | ||
## Usage | ||
ObjectMakr lazily creates classes based on `inheritance` trees with additional `properties`. | ||
You can then `make` new instances of those classes at runtime. | ||
The system works almost identically to traditional classes that `extend` each other, with the added benefit of lazy instantiation from plain old JavaScript objects. | ||
### Constructor | ||
```typescript | ||
import { ObjectMakr } from "objectmakr"; | ||
const objectMaker = new ObjectMakr({ | ||
inheritance: { | ||
Solid: { | ||
Block: {}, | ||
}, | ||
}, | ||
properties: { | ||
Block: { | ||
photo: "Question Mark", | ||
}, | ||
Solid: { | ||
size: 8, | ||
}, | ||
}, | ||
}); | ||
const block = objectMaker.make("Block"); | ||
block.photo; // "Question Mark" | ||
block.size; // 8 | ||
``` | ||
### `inheritance` | ||
A tree representing class inheritances, where keys are class names. | ||
The sub-objects under each class name key are classes inheriting from that class. | ||
The root object is always `Object`, as with normal JavaScript classes. | ||
### `properties` | ||
Flat mapping of class names to any properties added to that class' prototype. | ||
### `indexMap` | ||
How properties can be mapped from an array to indices on created members. | ||
If this is passed in, class properties will be allowed to be specified as arrays. | ||
```typescript | ||
const objectMaker = new ObjectMakr({ | ||
indexMap: ["photo", "contents"], | ||
inheritance: { | ||
Solid: { | ||
Block: ["Question Mark", "Coin"], | ||
Brick: ["Bricks"], | ||
}, | ||
}, | ||
properties: { | ||
Block: ["Question Mark"], | ||
Solid: { | ||
size: 8, | ||
}, | ||
}, | ||
}); | ||
const block = objectMaker.make("Block"); | ||
block.photo; // "Question Mark" | ||
block.contents; // "Coin" | ||
const brick = objectMaker.make("Brick"); | ||
brick.photo; // "Bricks" | ||
brick.contents; // undefined | ||
``` | ||
### `onMake` | ||
Member name for a function on instances to be called upon creation. | ||
If this is provided, any class instance with a member under this name will call that member as a function when made with `make`. | ||
The function is called with the member as its scope, and takes in the member and the class name. | ||
```typescript | ||
const calledOnMake = console.log.bind(console, "Creating:"); | ||
const objectMaker = new ObjectMakr({ | ||
inheritance: { | ||
Solid: { | ||
Block: {}, | ||
}, | ||
}, | ||
onMake: "creator", | ||
properties: { | ||
Solid: { | ||
creator: calledOnMake, | ||
}, | ||
}, | ||
}); | ||
// Creating: class_1 {} Block | ||
objectMaker.make("Block"); | ||
``` | ||
## `make` | ||
Creates a new instance of a class. | ||
If the class doesn't yet exist in-memory, it's created based on its `inheritance` and `properties`. | ||
```typescript | ||
const block = objectMaker.make("Block"); | ||
block.photo; // "Question Mark" | ||
block.size; // 8 | ||
``` | ||
`make` also accepts an additional `settings` parameter with any settings overrides to be shallow-copied onto the object. | ||
```typescript | ||
const bigBlock = objectMaker.make("Block", { | ||
size: 16, | ||
}); | ||
block.photo; // "Question Mark" | ||
bigBlock.size; // 16 | ||
``` | ||
<!-- {{Development}} --> | ||
## Development | ||
After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo/): | ||
``` | ||
git clone https://github.com/FullScreenShenanigans/ObjectMakr | ||
git clone https://github.com/<your-name-here>/ObjectMakr | ||
cd ObjectMakr | ||
npm install | ||
npm run setup | ||
@@ -17,0 +149,0 @@ npm run verify |
@@ -40,3 +40,3 @@ /** | ||
*/ | ||
export declare type IOnMakeFunction<T> = (this: T, output: T, name: string, settings: any, defaults: any) => any; | ||
export declare type IOnMakeFunction<T> = (this: T, output: T, name: string) => void; | ||
/** | ||
@@ -47,3 +47,3 @@ * Settings to initialize a new IObjectMakr. | ||
/** | ||
* A sketch of class inheritance. | ||
* A tree representing class inheritances, where keys are class names. | ||
*/ | ||
@@ -56,17 +56,9 @@ inheritance?: IClassInheritance; | ||
/** | ||
* Whether a full property mapping should be made for each type. | ||
*/ | ||
doPropertiesFull?: boolean; | ||
/** | ||
* How properties can be mapped from an Array to indices. | ||
*/ | ||
indexMap?: any[]; | ||
indexMap?: string[]; | ||
/** | ||
* An index for each generated Object's Function to be run when made. | ||
* Member name for a function on instances to be called upon creation. | ||
*/ | ||
onMake?: string; | ||
/** | ||
* Optionally, existing classes that can be passed in instead of using auto-generated ones. | ||
*/ | ||
functions?: IClassFunctions; | ||
} | ||
@@ -78,18 +70,13 @@ /** | ||
/** | ||
* Gets the prototype of a class, which contains its base properties. | ||
* | ||
* @template T Type of class properties being retrieved. | ||
* @param name Name of a class. | ||
* @returns The properties for a the class. | ||
* @returns Base properties for the class. | ||
*/ | ||
getPropertiesOf(name: string): any; | ||
getPrototypeOf<T extends {}>(name: string): T; | ||
/** | ||
* Gets whether a class exists. | ||
* | ||
* @param name Name of a class. | ||
* @returns Full properties for a the class, if doPropertiesFull is true. | ||
*/ | ||
getFullPropertiesOf(name: string): any; | ||
/** | ||
* @param name Name of a class. | ||
* @returns The class. | ||
*/ | ||
getClass(name: string): IClass; | ||
/** | ||
* @param name Name of a class. | ||
* @returns Whether that class exists. | ||
@@ -99,3 +86,3 @@ */ | ||
/** | ||
* Creates a new instance of the specified class. | ||
* Creates a new instance of a class. | ||
* | ||
@@ -107,3 +94,3 @@ * @template T Type of class being created. | ||
*/ | ||
make<T extends any>(name: string, settings?: any): T; | ||
make<T extends {}>(name: string, settings?: Partial<T>): T; | ||
} |
@@ -45,3 +45,3 @@ /** | ||
*/ | ||
export type IOnMakeFunction<T> = (this: T, output: T, name: string, settings: any, defaults: any) => any; | ||
export type IOnMakeFunction<T> = (this: T, output: T, name: string) => void; | ||
@@ -53,3 +53,3 @@ /** | ||
/** | ||
* A sketch of class inheritance. | ||
* A tree representing class inheritances, where keys are class names. | ||
*/ | ||
@@ -64,20 +64,10 @@ inheritance?: IClassInheritance; | ||
/** | ||
* Whether a full property mapping should be made for each type. | ||
*/ | ||
doPropertiesFull?: boolean; | ||
/** | ||
* How properties can be mapped from an Array to indices. | ||
*/ | ||
indexMap?: any[]; | ||
indexMap?: string[]; | ||
/** | ||
* An index for each generated Object's Function to be run when made. | ||
* Member name for a function on instances to be called upon creation. | ||
*/ | ||
onMake?: string; | ||
/** | ||
* Optionally, existing classes that can be passed in instead of using auto-generated ones. | ||
*/ | ||
functions?: IClassFunctions; | ||
} | ||
@@ -89,23 +79,15 @@ | ||
export interface IObjectMakr { | ||
/** | ||
* Gets the prototype of a class, which contains its base properties. | ||
* | ||
* @template T Type of class properties being retrieved. | ||
* @param name Name of a class. | ||
* @returns The properties for a the class. | ||
* @returns Base properties for the class. | ||
*/ | ||
getPropertiesOf(name: string): any; | ||
getPrototypeOf<T extends {}>(name: string): T; | ||
/** | ||
* Gets whether a class exists. | ||
* | ||
* @param name Name of a class. | ||
* @returns Full properties for a the class, if doPropertiesFull is true. | ||
*/ | ||
getFullPropertiesOf(name: string): any; | ||
/** | ||
* @param name Name of a class. | ||
* @returns The class. | ||
*/ | ||
getClass(name: string): IClass; | ||
/** | ||
* @param name Name of a class. | ||
* @returns Whether that class exists. | ||
@@ -116,3 +98,3 @@ */ | ||
/** | ||
* Creates a new instance of the specified class. | ||
* Creates a new instance of a class. | ||
* | ||
@@ -124,3 +106,3 @@ * @template T Type of class being created. | ||
*/ | ||
make<T extends any>(name: string, settings?: any): T; | ||
make<T extends {}>(name: string, settings?: Partial<T>): T; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { IClass, IObjectMakr, IObjectMakrSettings } from "./IObjectMakr"; | ||
import { IObjectMakr, IObjectMakrSettings } from "./IObjectMakr"; | ||
/** | ||
@@ -15,6 +15,2 @@ * An abstract factory for dynamic attribute-based classes. | ||
/** | ||
* If requested, each class' entire prototype chain of properties. | ||
*/ | ||
private readonly propertiesFull?; | ||
/** | ||
* Generated classes, keyed by name. | ||
@@ -28,7 +24,7 @@ */ | ||
/** | ||
* How properties can be mapped from an Array to indices. | ||
* How properties can be mapped from an array to indices. | ||
*/ | ||
private readonly indexMap; | ||
/** | ||
* An index for each generated Object's Function to be run when made. | ||
* Member name for a function on instances to be called upon creation. | ||
*/ | ||
@@ -43,23 +39,10 @@ private readonly onMake?; | ||
/** | ||
* Gets the immediate (non-inherited) properties of a class. | ||
* Gets the prototype of a class, which contains its base properties. | ||
* | ||
* @template T Type of class properties being retrieved. | ||
* @param name Name of a class. | ||
* @returns The properties for a the class. | ||
* @returns Base properties for the class. | ||
*/ | ||
getPropertiesOf(name: string): any; | ||
getPrototypeOf<T extends any>(name: string): T; | ||
/** | ||
* Gets the full properties of a class. | ||
* | ||
* @param name Name of a class. | ||
* @returns Full properties for a the class, if doPropertiesFull is true. | ||
*/ | ||
getFullPropertiesOf(name: string): any; | ||
/** | ||
* Gets a named class. | ||
* | ||
* @param name Name of a class. | ||
* @returns The class. | ||
*/ | ||
getClass(name: string): IClass; | ||
/** | ||
* Gets whether a class exists. | ||
@@ -72,3 +55,3 @@ * | ||
/** | ||
* Creates a new instance of the specified class. | ||
* Creates a new instance of a class. | ||
* | ||
@@ -80,3 +63,3 @@ * @template T Type of class being created. | ||
*/ | ||
make<T extends any>(name: string, settings?: any): T; | ||
make<T extends any>(name: string, settings?: Partial<T>): T; | ||
/** | ||
@@ -100,5 +83,5 @@ * Creates a class from the recorded properties. | ||
* | ||
* @param properties An Array with indiced versions of properties. | ||
* @param properties An array with indiced versions of properties. | ||
*/ | ||
private processIndexMappedProperties(indexMap); | ||
private processIndexMappedProperties(shorthandProperties); | ||
/** | ||
@@ -117,9 +100,2 @@ * Recursively records the parent names for classes in an inheritance. | ||
private ensureClassExists(name); | ||
/** | ||
* Deep copies all members of the donor to the recipient recursively. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
*/ | ||
private proliferate(recipient, donor); | ||
} |
@@ -5,2 +5,15 @@ define(["require", "exports"], function (require, exports) { | ||
/** | ||
* Deep copies all members of the donor to the recipient recursively. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
*/ | ||
var shallowCopy = function (recipient, donor) { | ||
for (var i in donor) { | ||
if ({}.hasOwnProperty.call(donor, i)) { | ||
recipient[i] = donor[i]; | ||
} | ||
} | ||
}; | ||
/** | ||
* An abstract factory for dynamic attribute-based classes. | ||
@@ -25,37 +38,15 @@ */ | ||
this.generateClassParentNames(this.inheritance, "Object"); | ||
if (settings.doPropertiesFull) { | ||
this.propertiesFull = {}; | ||
} | ||
} | ||
/** | ||
* Gets the immediate (non-inherited) properties of a class. | ||
* Gets the prototype of a class, which contains its base properties. | ||
* | ||
* @template T Type of class properties being retrieved. | ||
* @param name Name of a class. | ||
* @returns The properties for a the class. | ||
* @returns Base properties for the class. | ||
*/ | ||
ObjectMakr.prototype.getPropertiesOf = function (name) { | ||
ObjectMakr.prototype.getPrototypeOf = function (name) { | ||
this.ensureClassExists(name); | ||
return this.properties[name]; | ||
return this.classes[name].prototype; | ||
}; | ||
/** | ||
* Gets the full properties of a class. | ||
* | ||
* @param name Name of a class. | ||
* @returns Full properties for a the class, if doPropertiesFull is true. | ||
*/ | ||
ObjectMakr.prototype.getFullPropertiesOf = function (name) { | ||
this.ensureClassExists(name); | ||
return this.propertiesFull ? this.propertiesFull[name] : undefined; | ||
}; | ||
/** | ||
* Gets a named class. | ||
* | ||
* @param name Name of a class. | ||
* @returns The class. | ||
*/ | ||
ObjectMakr.prototype.getClass = function (name) { | ||
this.ensureClassExists(name); | ||
return this.classes[name]; | ||
}; | ||
/** | ||
* Gets whether a class exists. | ||
@@ -70,3 +61,3 @@ * | ||
/** | ||
* Creates a new instance of the specified class. | ||
* Creates a new instance of a class. | ||
* | ||
@@ -80,10 +71,10 @@ * @template T Type of class being created. | ||
this.ensureClassExists(name); | ||
var output = new this.classes[name](); | ||
var instance = new this.classes[name](); | ||
if (settings !== undefined) { | ||
this.proliferate(output, settings); | ||
shallowCopy(instance, settings); | ||
} | ||
if (this.onMake && output[this.onMake]) { | ||
output[this.onMake].call(output, output, name, settings, (this.propertiesFull ? this.propertiesFull : this.properties)[name]); | ||
if (this.onMake && instance[this.onMake] !== undefined) { | ||
instance[this.onMake].call(instance, instance, name); | ||
} | ||
return output; | ||
return instance; | ||
}; | ||
@@ -104,5 +95,2 @@ /** | ||
var parentName = this.classParentNames[name]; | ||
if (this.propertiesFull) { | ||
this.propertiesFull[name] = {}; | ||
} | ||
if (parentName) { | ||
@@ -117,7 +105,2 @@ this.extendClass(newClass, name, parentName); | ||
} | ||
if (this.propertiesFull) { | ||
for (var i in this.properties[name]) { | ||
this.propertiesFull[name][i] = this.properties[name][i]; | ||
} | ||
} | ||
return newClass; | ||
@@ -138,7 +121,2 @@ }; | ||
newClass.prototype.constructor = newClass; | ||
if (this.propertiesFull) { | ||
for (var i in this.propertiesFull[parentName]) { | ||
this.propertiesFull[name][i] = this.propertiesFull[parentName][i]; | ||
} | ||
} | ||
}; | ||
@@ -148,8 +126,8 @@ /** | ||
* | ||
* @param properties An Array with indiced versions of properties. | ||
* @param properties An array with indiced versions of properties. | ||
*/ | ||
ObjectMakr.prototype.processIndexMappedProperties = function (indexMap) { | ||
ObjectMakr.prototype.processIndexMappedProperties = function (shorthandProperties) { | ||
var output = {}; | ||
for (var i = 0; i < indexMap.length; i += 1) { | ||
output[this.indexMap[i]] = indexMap[i]; | ||
for (var i = 0; i < shorthandProperties.length; i += 1) { | ||
output[this.indexMap[i]] = shorthandProperties[i]; | ||
} | ||
@@ -183,22 +161,2 @@ return output; | ||
}; | ||
/** | ||
* Deep copies all members of the donor to the recipient recursively. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
*/ | ||
ObjectMakr.prototype.proliferate = function (recipient, donor) { | ||
for (var i in donor) { | ||
var setting = donor[i]; | ||
if (typeof setting === "object") { | ||
if (!this.hasOwnProperty.call(recipient, i)) { | ||
recipient[i] = new setting.constructor(); | ||
} | ||
this.proliferate(recipient[i], setting); | ||
} | ||
else { | ||
recipient[i] = setting; | ||
} | ||
} | ||
}; | ||
return ObjectMakr; | ||
@@ -205,0 +163,0 @@ }()); |
@@ -7,2 +7,16 @@ import { | ||
/** | ||
* Deep copies all members of the donor to the recipient recursively. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
*/ | ||
const shallowCopy = <T extends {}>(recipient: T, donor: Partial<T>): void => { | ||
for (const i in donor) { | ||
if ({}.hasOwnProperty.call(donor, i)) { | ||
(recipient as any)[i] = donor[i]; | ||
} | ||
} | ||
}; | ||
/** | ||
* An abstract factory for dynamic attribute-based classes. | ||
@@ -22,7 +36,2 @@ */ | ||
/** | ||
* If requested, each class' entire prototype chain of properties. | ||
*/ | ||
private readonly propertiesFull?: IClassProperties; | ||
/** | ||
* Generated classes, keyed by name. | ||
@@ -38,3 +47,3 @@ */ | ||
/** | ||
* How properties can be mapped from an Array to indices. | ||
* How properties can be mapped from an array to indices. | ||
*/ | ||
@@ -44,3 +53,3 @@ private readonly indexMap: string[]; | ||
/** | ||
* An index for each generated Object's Function to be run when made. | ||
* Member name for a function on instances to be called upon creation. | ||
*/ | ||
@@ -65,42 +74,17 @@ private readonly onMake?: string; | ||
this.generateClassParentNames(this.inheritance, "Object"); | ||
if (settings.doPropertiesFull) { | ||
this.propertiesFull = {}; | ||
} | ||
} | ||
/** | ||
* Gets the immediate (non-inherited) properties of a class. | ||
* Gets the prototype of a class, which contains its base properties. | ||
* | ||
* @template T Type of class properties being retrieved. | ||
* @param name Name of a class. | ||
* @returns The properties for a the class. | ||
* @returns Base properties for the class. | ||
*/ | ||
public getPropertiesOf(name: string): any { | ||
public getPrototypeOf<T extends any>(name: string): T { | ||
this.ensureClassExists(name); | ||
return this.properties[name]; | ||
return this.classes[name].prototype; | ||
} | ||
/** | ||
* Gets the full properties of a class. | ||
* | ||
* @param name Name of a class. | ||
* @returns Full properties for a the class, if doPropertiesFull is true. | ||
*/ | ||
public getFullPropertiesOf(name: string): any { | ||
this.ensureClassExists(name); | ||
return this.propertiesFull ? this.propertiesFull[name] : undefined; | ||
} | ||
/** | ||
* Gets a named class. | ||
* | ||
* @param name Name of a class. | ||
* @returns The class. | ||
*/ | ||
public getClass(name: string): IClass { | ||
this.ensureClassExists(name); | ||
return this.classes[name]; | ||
} | ||
/** | ||
* Gets whether a class exists. | ||
@@ -116,3 +100,3 @@ * | ||
/** | ||
* Creates a new instance of the specified class. | ||
* Creates a new instance of a class. | ||
* | ||
@@ -124,20 +108,15 @@ * @template T Type of class being created. | ||
*/ | ||
public make<T extends any>(name: string, settings?: any): T { | ||
public make<T extends any>(name: string, settings?: Partial<T>): T { | ||
this.ensureClassExists(name); | ||
const output: T = new this.classes[name](); | ||
const instance: T = new this.classes[name](); | ||
if (settings !== undefined) { | ||
this.proliferate(output, settings); | ||
shallowCopy(instance, settings); | ||
} | ||
if (this.onMake && output[this.onMake]) { | ||
(output[this.onMake] as IOnMakeFunction<T>).call( | ||
output, | ||
output, | ||
name, | ||
settings, | ||
(this.propertiesFull ? this.propertiesFull : this.properties)[name]); | ||
if (this.onMake && instance[this.onMake] !== undefined) { | ||
(instance[this.onMake] as IOnMakeFunction<T>).call(instance, instance, name); | ||
} | ||
return output; | ||
return instance; | ||
} | ||
@@ -156,6 +135,2 @@ | ||
if (this.propertiesFull) { | ||
this.propertiesFull[name] = {}; | ||
} | ||
if (parentName) { | ||
@@ -173,8 +148,2 @@ this.extendClass(newClass, name, parentName); | ||
if (this.propertiesFull) { | ||
for (const i in this.properties[name]) { | ||
this.propertiesFull[name][i] = this.properties[name][i]; | ||
} | ||
} | ||
return newClass; | ||
@@ -197,8 +166,2 @@ } | ||
newClass.prototype.constructor = newClass; | ||
if (this.propertiesFull) { | ||
for (const i in this.propertiesFull[parentName]) { | ||
this.propertiesFull[name][i] = this.propertiesFull[parentName][i]; | ||
} | ||
} | ||
} | ||
@@ -209,9 +172,9 @@ | ||
* | ||
* @param properties An Array with indiced versions of properties. | ||
* @param properties An array with indiced versions of properties. | ||
*/ | ||
private processIndexMappedProperties(indexMap: string[]): any { | ||
private processIndexMappedProperties(shorthandProperties: string[]): any { | ||
const output: any = {}; | ||
for (let i = 0; i < indexMap.length; i += 1) { | ||
output[this.indexMap[i]] = indexMap[i]; | ||
for (let i = 0; i < shorthandProperties.length; i += 1) { | ||
output[this.indexMap[i]] = shorthandProperties[i]; | ||
} | ||
@@ -249,24 +212,2 @@ | ||
} | ||
/** | ||
* Deep copies all members of the donor to the recipient recursively. | ||
* | ||
* @param recipient An object receiving the donor's members. | ||
* @param donor An object whose members are copied to recipient. | ||
*/ | ||
private proliferate(recipient: any, donor: any): void { | ||
for (const i in donor) { | ||
const setting: any = donor[i]; | ||
if (typeof setting === "object") { | ||
if (!this.hasOwnProperty.call(recipient, i)) { | ||
recipient[i] = new setting.constructor(); | ||
} | ||
this.proliferate(recipient[i], setting); | ||
} else { | ||
recipient[i] = setting; | ||
} | ||
} | ||
} | ||
} |
@@ -5,2 +5,3 @@ { | ||
"experimentalDecorators": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react", | ||
@@ -7,0 +8,0 @@ "lib": ["dom", "es2015.collection", "es2015.promise", "es5"], |
{ | ||
"extends": "./node_modules/shenanigans-manager/setup/tslint.json", | ||
"linterOptions": { | ||
"exclude": [ | ||
"./node_modules/**/*" | ||
] | ||
}, | ||
"rules": { | ||
@@ -4,0 +9,0 @@ "ban-types": false, |
@@ -10,3 +10,3 @@ const glob = require("glob"); | ||
{ | ||
entry: `./src/${package.shenanigans.name}.js`, | ||
entry: `./src/index.js`, | ||
name: package.shenanigans.name, | ||
@@ -45,5 +45,4 @@ sources: [ | ||
// multiple entries? | ||
module.exports = { | ||
entry, // IDictionary<string> | ||
entry, | ||
externals, | ||
@@ -50,0 +49,0 @@ output: { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
676134
46
7130
175
21
4