mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 02:02:41 +08:00
Merge pull request #1271 from jareguo/master
CCClass: ctor of mixin should be called only once
This commit is contained in:
@@ -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: {
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user