Include L.Mixin.Events again; add deprecation notice (#5365)
Close #5358
This commit is contained in:
parent
da1a89871d
commit
c18ac11efb
@ -604,4 +604,20 @@ describe('Events', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#L.Mixin.Events', function () {
|
||||||
|
it('can be used from includes', function () {
|
||||||
|
var EventClass = L.Class.extend({
|
||||||
|
includes: L.Mixin.Events
|
||||||
|
});
|
||||||
|
var obj = new EventClass();
|
||||||
|
var spy = sinon.spy();
|
||||||
|
|
||||||
|
obj.on('test', spy);
|
||||||
|
|
||||||
|
obj.fire('test');
|
||||||
|
|
||||||
|
expect(spy.called).to.be(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -48,6 +48,7 @@ Class.extend = function (props) {
|
|||||||
|
|
||||||
// mix includes into the prototype
|
// mix includes into the prototype
|
||||||
if (props.includes) {
|
if (props.includes) {
|
||||||
|
checkDeprecatedMixinEvents(props.includes);
|
||||||
Util.extend.apply(null, [proto].concat(props.includes));
|
Util.extend.apply(null, [proto].concat(props.includes));
|
||||||
delete props.includes;
|
delete props.includes;
|
||||||
}
|
}
|
||||||
@ -109,3 +110,17 @@ Class.addInitHook = function (fn) { // (Function) || (String, args...)
|
|||||||
this.prototype._initHooks.push(init);
|
this.prototype._initHooks.push(init);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function checkDeprecatedMixinEvents(includes) {
|
||||||
|
if (!L || !L.Mixin) { return; }
|
||||||
|
|
||||||
|
includes = L.Util.isArray(includes) ? includes : [includes];
|
||||||
|
|
||||||
|
for (var i = 0; i < includes.length; i++) {
|
||||||
|
if (includes[i] === L.Mixin.Events) {
|
||||||
|
console.warn('Deprecated include of L.Mixin.Events: ' +
|
||||||
|
'this property will be removed in future releases, ' +
|
||||||
|
'please inherit from L.Evented instead.', new Error().stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,8 +3,9 @@ export {Browser};
|
|||||||
|
|
||||||
export {Class} from './Class';
|
export {Class} from './Class';
|
||||||
|
|
||||||
export {Evented} from './Events';
|
import {Evented} from './Events';
|
||||||
// export var Mixin = {Events: Evented.prototype};
|
export {Evented};
|
||||||
|
export var Mixin = {Events: Evented.prototype};
|
||||||
|
|
||||||
export {Handler} from './Handler';
|
export {Handler} from './Handler';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user