luy
Version:
所谓类```React```框架就是**和React用法一模一样**的框架。其实当初制造这个框架的目的是为了能更好的学习React内部结构,了解其原理而制作的玩具。但是随着框架的渐渐成长,代码越来越多,我还是决定将其发展下去. 
51 lines (48 loc) • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SyntheticEvent = SyntheticEvent;
/**事件合成,暂时这么写 */
function SyntheticEvent(event) {
if (event.nativeEvent) {
return event;
}
for (var i in event) {
if (!eventProto[i]) {
this[i] = event[i];
}
}
if (!this.target) {
this.target = event.srcElement;
}
this.fixEvent();
this.timeStamp = new Date() - 0;
this.nativeEvent = event;
}
var eventProto = SyntheticEvent.prototype = {
fixEvent: function fixEvent() {}, //留给以后扩展用
preventDefault: function preventDefault() {
var e = this.nativeEvent || {};
e.returnValue = this.returnValue = false;
if (e.preventDefault) {
e.preventDefault();
}
},
fixHooks: function fixHooks() {},
stopPropagation: function stopPropagation() {
var e = this.nativeEvent || {};
e.cancelBubble = this._stopPropagation = true;
if (e.stopPropagation) {
e.stopPropagation();
}
},
persist: function noop() {},
stopImmediatePropagation: function stopImmediatePropagation() {
this.stopPropagation();
this.stopImmediate = true;
},
toString: function toString() {
return "[object Event]";
}
};