cubekit-meta
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -28,5 +28,2 @@ var webpack = require('karma-webpack'); | ||
], | ||
instrumenterOptions: { | ||
istanbul: { noCompact: true } | ||
} | ||
}, | ||
@@ -40,6 +37,2 @@ webpack: { | ||
loader: 'eslint-loader', | ||
}, { | ||
test: /\.js$/, | ||
include: /src/, | ||
loader: 'isparta', | ||
}], | ||
@@ -46,0 +39,0 @@ |
@@ -16,2 +16,4 @@ 'use strict'; | ||
_classCallCheck(this, MetaDecorator); | ||
this._decoratedClasses = []; | ||
} | ||
@@ -46,6 +48,30 @@ | ||
MetaDecorator.prototype._getOrCreateMeta = function _getOrCreateMeta(Class) { | ||
if (!Class.__cubekitMeta__) { | ||
Class.__cubekitMeta__ = this._createDefaultMeta(); | ||
} else if (!Class.hasOwnProperty('__cubekitMeta__')) { | ||
Class.__cubekitMeta__ = _lodash2['default'].cloneDeep(Class.__cubekitMeta__); | ||
if (!this._hasBeenAlreadyDecorated(Class)) { | ||
if (Class.__cubekitMeta__) { | ||
/** | ||
* If the class hasn't been decorated yet, but has a | ||
* meta property, than it was copied from its parent | ||
* class. In this case we must clone it to prevent | ||
* the parent meta from mutating by children. | ||
* | ||
* In the previous version we used `hasOwnProperty('__cubekitMeta__')` | ||
* to determine was the property received from the | ||
* parent class or created by another meta method | ||
* on the current class, but it doesn't work when | ||
* Babel is configured to support inheriting of | ||
* static properties in old browsers. | ||
*/ | ||
Class.__cubekitMeta__ = _lodash2['default'].cloneDeep(Class.__cubekitMeta__); | ||
/** | ||
* We don't want types from the parent class to merge | ||
* with types of the child class. The child class must | ||
* take care to pass right things into the parent constructor. | ||
*/ | ||
Class.__cubekitMeta__.constructor.types = []; | ||
} else { | ||
Class.__cubekitMeta__ = this._createDefaultMeta(); | ||
} | ||
this._markAsDecorated(Class); | ||
} | ||
@@ -56,2 +82,10 @@ | ||
MetaDecorator.prototype._hasBeenAlreadyDecorated = function _hasBeenAlreadyDecorated(Class) { | ||
return this._decoratedClasses.indexOf(Class) != -1; | ||
}; | ||
MetaDecorator.prototype._markAsDecorated = function _markAsDecorated(Class) { | ||
this._decoratedClasses.push(Class); | ||
}; | ||
MetaDecorator.prototype._createDefaultMeta = function _createDefaultMeta() { | ||
@@ -58,0 +92,0 @@ return { |
{ | ||
"name": "cubekit-meta", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Decorators for easy define types-meta", | ||
@@ -25,3 +25,2 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"babel": "^5.6.23", | ||
"babel-core": "^5.8.19", | ||
@@ -36,2 +35,4 @@ "babel-eslint": "^3.1.15", | ||
"istanbul-instrumenter-loader": "^0.1.3", | ||
"mocha": "^2.3.4", | ||
"karma": "^0.13.16", | ||
"karma-chai": "^0.1.0", | ||
@@ -38,0 +39,0 @@ "karma-chai-plugins": "^0.5.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15976
131
23