lib/directive/form.js
function initText(elem, parsed, extra){
  var param = extra.param;
  var throttle, lazy = param.lazy

  if('throttle' in param){
    // <input throttle r-model>
    if(param.throttle === true){
      throttle = 400;
    }else{
      throttle = parseInt(param.throttle, 10)
    }
  }

  var self = this;
  var wc = this.$watch(parsed, function(newValue){
    if(elem.value !== newValue) elem.value = newValue == null? "": "" + newValue;
  }, STABLE);

  // @TODO to fixed event
  var isCompositing = false;
  var handler = function (ev){

    if(isCompositing) return;

    isCompositing = false;

    var that = this;
    if(ev.type==='cut' || ev.type==='paste'){
      _.nextTick(function(){
        var value = that.value
        parsed.set(self, value);
        wc.last = value;
        self.$update();
      })
    }else{
        var value = that.value
        parsed.set(self, value);
        wc.last = value;
        self.$update();
    }
  };

  function onCompositionStart(){
    isCompositing = true;
  }

  function onCompositionEnd(ev){
    isCompositing = false;
    handler.call(this,ev)
  }

  if(throttle && !lazy){
    var preHandle = handler, tid;
    handler = _.throttle(handler, throttle);
  }

  if(hasInput === undefined){
    hasInput = dom.msie !== 9 && "oninput" in document.createElement('input')
  }

  if(lazy){
    dom.on(elem, 'change', handler)
  }else{

    if(typeof CompositionEvent === 'function' ){ //lazy的情况不需要compositionend
      elem.addEventListener("compositionstart", onCompositionStart );
      elem.addEventListener("compositionend", onCompositionEnd );
    }

    if( hasInput){
      elem.addEventListener("input", handler );
    }else{
      dom.on(elem, "paste keyup cut change", handler)
    }
  }
  if(parsed.get(self) === undefined && elem.value){
     parsed.set(self, elem.value);
  }
  return function (){
    if(lazy) return dom.off(elem, "change", handler);
    if( hasInput ){
      elem.removeEventListener("input", handler );
    }else{
      dom.off(elem, "paste keyup cut change", handler)
    }
  }
}
function initText(elem, parsed, extra){
  var param = extra.param;
  var throttle, lazy = param.lazy

  if('throttle' in param){
    // <input throttle r-model>
    if(param.throttle === true){
      throttle = 400;
    }else{
      throttle = parseInt(param.throttle, 10)
    }
  }

  var self = this;
  var wc = this.$watch(parsed, function(newValue){
    if(elem.value !== newValue) elem.value = newValue == null? "": "" + newValue;
  }, STABLE);

  // @TODO to fixed event
  var isCompositing = false;
  var handler = function (ev){

    if(isCompositing) return;

    isCompositing = false;

    var that = this;
    if(ev.type==='cut' || ev.type==='paste'){
      _.nextTick(function(){
        var value = that.value
        parsed.set(self, value);
        wc.last = value;
        self.$update();
      })
    }else{
        var value = that.value
        parsed.set(self, value);
        wc.last = value;
        self.$update();
    }
  };

  function onCompositionStart(){
    isCompositing = true;
  }

  function onCompositionEnd(ev){
    isCompositing = false;
    handler.call(this,ev)
  }

  if(throttle && !lazy){
    var preHandle = handler, tid;
    handler = _.throttle(handler, throttle);
  }

  if(hasInput === undefined){
    hasInput = dom.msie !== 9 && "oninput" in document.createElement('input')
  }

  if(lazy){
    dom.on(elem, 'change', handler)
  }else{

    if(typeof CompositionEvent === 'function' ){ //lazy的情况不需要compositionend
      elem.addEventListener("compositionstart", onCompositionStart );
      elem.addEventListener("compositionend", onCompositionEnd );
    }

    if( hasInput){
      elem.addEventListener("input", handler );
    }else{
      dom.on(elem, "paste keyup cut change", handler)
    }
  }
  if(parsed.get(self) === undefined && elem.value){
     parsed.set(self, elem.value);
  }
  return function (){
    if(lazy) return dom.off(elem, "change", handler);
    if( hasInput ){
      elem.removeEventListener("input", handler );
    }else{
      dom.off(elem, "paste keyup cut change", handler)
    }
  }
}
function initText ( elem , parsed , extra ) { var param = extra . param ; var throttle , lazy = param . lazy if ( 'throttle' in param ) { // <input throttle r-model> if ( param . throttle === true ) { throttle = 400 ; } else { throttle = parseInt ( param . throttle , 10 ) } } var self = this ; var wc = this . $watch ( parsed , function ( newValue ) { if ( elem . value !== newValue ) elem . value = newValue == null ? "" : "" + newValue ; } , STABLE ) ; // @TODO to fixed event var isCompositing = false ; var handler = function ( ev ) { if ( isCompositing ) return ; isCompositing = false ; var that = this ; if ( ev . type === 'cut' || ev . type === 'paste' ) { _ . nextTick ( function ( ) { var value = that . value parsed . set ( self , value ) ; wc . last = value ; self . $update ( ) ; } ) } else { var value = that . value parsed . set ( self , value ) ; wc . last = value ; self . $update ( ) ; } } ; function onCompositionStart ( ) { isCompositing = true ; } function onCompositionEnd ( ev ) { isCompositing = false ; handler . call ( this , ev ) } if ( throttle && ! lazy ) { var preHandle = handler , tid ; handler = _ . throttle ( handler , throttle ) ; } if ( hasInput === undefined ) { hasInput = dom . msie !== 9 && "oninput" in document . createElement ( 'input' ) } if ( lazy ) { dom . on ( elem , 'change' , handler ) } else { if ( typeof CompositionEvent === 'function' ) { //lazy的情况不需要compositionend elem . addEventListener ( "compositionstart" , onCompositionStart ) ; elem . addEventListener ( "compositionend" , onCompositionEnd ) ; } if ( hasInput ) { elem . addEventListener ( "input" , handler ) ; } else { dom . on ( elem , "paste keyup cut change" , handler ) } } if ( parsed . get ( self ) === undefined && elem . value ) { parsed . set ( self , elem . value ) ; } return function ( ) { if ( lazy ) return dom . off ( elem , "change" , handler ) ; if ( hasInput ) { elem . removeEventListener ( "input" , handler ) ; } else { dom . off ( elem , "paste keyup cut change" , handler ) } } }
input,textarea binding
input textarea binding