Lucifier129 / react-lite

An implementation of React v15.x that optimizes for small script size
MIT License
1.73k stars 98 forks source link

binding event inside onClick prop (inconsistent with react) #25

Closed fritx closed 8 years ago

fritx commented 8 years ago
<div className="op-btn" onClick={()=>{
                alert(1)
                window.addEventListener('click', () => {
                  alert(2)
                })

                // this.refs.filePanel.toggle()
              }}>发送文件</div>

Hello, here is one more difference I found between react and react-lite. In react, both 1 and 2 are alerted, while in react-lite, only 1 is alerted. In my case, I have to wrap the second binding with a setTimeout to make it work in react. Yes, in this case, the result of react-lite is expected. But there is such an inconsistency to be noticed ;)

dhenson02 commented 8 years ago

I'd like to say you should post this on the React issues board as a bug report.

Lucifier129 commented 8 years ago

The most different between react and react-lite is their event system.

React's cross-browser custom event system base on bubble cost a lot of code, and reat-lite use DOM-level 1 for optimizing size.

With react-lite, every event handler would be stopPropagation, so inline event binding will not be invoked.

fritx commented 8 years ago

Thanks guy!