Merge pull request #1271 from jareguo/master

CCClass: ctor of mixin should be called only once
This commit is contained in:
Jare Guo
2016-11-08 21:01:19 +08:00
committed by GitHub
3 changed files with 29 additions and 5 deletions
-2
View File
@@ -24,7 +24,6 @@
'use strict';
var EventTarget = require('./event/event-target');
var PrefabHelper = require('./utils/prefab-helper');
var JS = cc.js;
@@ -327,7 +326,6 @@ function findChildComponents (children, constructor, components) {
var Node = cc.Class({
name: 'cc.Node',
extends: require('./utils/base-node'),
mixins: [EventTarget],
properties: {
/**
+8 -2
View File
@@ -542,11 +542,17 @@ function _createCtor (ctor, baseClass, mixins, className, options) {
if (CCClass._isCCClass(baseOrMixin)) {
var baseCtors = baseOrMixin.__ctors__;
if (baseCtors) {
ctors = ctors.concat(baseCtors);
for (var c = 0; c < baseCtors.length; c++) {
if (ctors.indexOf(baseCtors[c]) < 0) {
ctors.push(baseCtors[c]);
}
}
}
}
else if (baseOrMixin) {
ctors.push(baseOrMixin);
if (ctors.indexOf(baseOrMixin) < 0) {
ctors.push(baseOrMixin);
}
}
}
}
+21 -1
View File
@@ -280,7 +280,7 @@ test('prop initial times', function () {
configurable: true
});
Base.call(instanceMocker);
fooTester.once('property should init once');
fooTester.once('property should init only once');
var Sub = cc.Class({
extends: Base,
@@ -591,6 +591,26 @@ test('mixins', function () {
strictEqual(cc.Class.attr(BigDog, 'p1').default, 'Defined by BigDog', "should override base property");
});
test('mixins ctor', function () {
var ctorOfMixin = Callback().enable();
var Mixin = cc.Class({
ctor: function () {
ctorOfMixin();
},
});
var Dog = cc.Class({
mixins: [Mixin],
});
var BigDog = cc.Class({
extends: Dog,
mixins: [Mixin],
});
new BigDog();
ctorOfMixin.once('ctor of mixin should be called only once');
});
asyncTest('instantiate properties in the next frame', function () {
var Dog = cc.Class({
properties: function () {