File tree Expand file tree Collapse file tree 4 files changed +69
-28
lines changed Expand file tree Collapse file tree 4 files changed +69
-28
lines changed Original file line number Diff line number Diff line change 11import { h } from "../../lib/m-vue.esm.js" ;
22
3- // debugger instance
4- window . vueInstance = null ;
5-
63export const App = {
7- // vue template -> render
4+ // TODO: vue template -> render
85 render ( ) {
9- window . vueInstance = this ;
10- // return h("div", {}, "shi-wen" + this.msg);
116 return h (
127 "div" ,
138 {
14- id : "mini-vue-page" ,
15- class : "first-layer" ,
9+ class : "red" ,
10+ onClick ( ) {
11+ console . log ( "click" ) ;
12+ } ,
13+ onMousemove ( ) {
14+ console . log ( "mousemove" ) ;
15+ } ,
1616 } ,
17- [
18- h (
19- "div" ,
20- {
21- class : "red" ,
22- } ,
23- `${ this . msg } `
24- ) ,
25- h (
26- "div" ,
27- {
28- class : "blue" ,
29- } ,
30- `Hello Branlice ${ this . subMessage } `
31- ) ,
32- ]
17+ this . msg
3318 ) ;
34- } ,
3519
20+ // return h(
21+ // "div",
22+ // {
23+ // id: "mini-vue-page",
24+ // class: "first-layer",
25+ // },
26+ // [
27+ // h(
28+ // "div",
29+ // {
30+ // class: "red",
31+ // },
32+ // `${this.msg}`
33+ // ),
34+ // h(
35+ // "div",
36+ // {
37+ // class: "blue",
38+ // },
39+ // `Hello Branlice ${this.subMessage}`
40+ // ),
41+ // ]
42+ // );
43+ } ,
3644 setup ( ) {
3745 return {
3846 msg : "hello world 2022" ,
Original file line number Diff line number Diff line change @@ -131,12 +131,23 @@ function mountElement(vnode, container) {
131131function mountChildren ( children = [ ] , container ) {
132132 children . forEach ( child => { patch ( child , container ) ; } ) ;
133133}
134+ function isOnEvent ( propertyName ) {
135+ return / ^ o n [ A - Z ] / . test ( propertyName ) ;
136+ }
137+ isOnEvent . getEventName = function onEventName ( propertyName ) {
138+ return propertyName . slice ( 2 ) . toLowerCase ( ) ;
139+ } ;
134140function addAttrs ( vnode , container ) {
135141 const props = vnode . props || { } ;
136142 for ( const key in props ) {
137143 if ( Object . prototype . hasOwnProperty . call ( props , key ) ) {
138144 const value = props [ key ] ;
139- container . setAttribute ( key , value ) ;
145+ if ( isOnEvent ( key ) ) {
146+ container . addEventListener ( isOnEvent . getEventName ( key ) , value , false ) ;
147+ }
148+ else {
149+ container . setAttribute ( key , value ) ;
150+ }
140151 }
141152 }
142153}
Original file line number Diff line number Diff line change @@ -127,12 +127,23 @@ function mountElement(vnode, container) {
127127function mountChildren ( children = [ ] , container ) {
128128 children . forEach ( child => { patch ( child , container ) ; } ) ;
129129}
130+ function isOnEvent ( propertyName ) {
131+ return / ^ o n [ A - Z ] / . test ( propertyName ) ;
132+ }
133+ isOnEvent . getEventName = function onEventName ( propertyName ) {
134+ return propertyName . slice ( 2 ) . toLowerCase ( ) ;
135+ } ;
130136function addAttrs ( vnode , container ) {
131137 const props = vnode . props || { } ;
132138 for ( const key in props ) {
133139 if ( Object . prototype . hasOwnProperty . call ( props , key ) ) {
134140 const value = props [ key ] ;
135- container . setAttribute ( key , value ) ;
141+ if ( isOnEvent ( key ) ) {
142+ container . addEventListener ( isOnEvent . getEventName ( key ) , value , false ) ;
143+ }
144+ else {
145+ container . setAttribute ( key , value ) ;
146+ }
136147 }
137148 }
138149}
Original file line number Diff line number Diff line change @@ -50,12 +50,23 @@ function mountChildren(children = [], container) {
5050 children . forEach ( child => { patch ( child , container ) } )
5151}
5252
53+ function isOnEvent ( propertyName ) {
54+ return / ^ o n [ A - Z ] / . test ( propertyName )
55+ }
56+ isOnEvent . getEventName = function onEventName ( propertyName ) {
57+ return propertyName . slice ( 2 ) . toLowerCase ( )
58+ }
59+
5360function addAttrs ( vnode , container ) {
5461 const props = vnode . props || { } ;
5562 for ( const key in props ) {
5663 if ( Object . prototype . hasOwnProperty . call ( props , key ) ) {
5764 const value = props [ key ] ;
58- container . setAttribute ( key , value ) ;
65+ if ( isOnEvent ( key ) ) {
66+ container . addEventListener ( isOnEvent . getEventName ( key ) , value , false ) ;
67+ } else {
68+ container . setAttribute ( key , value ) ;
69+ }
5970 }
6071 }
6172}
You can’t perform that action at this time.
0 commit comments