Просмотр исходного кода

Update viewmodel.js

Allow passing false to constructor to bypass compilation. Add vue.init( config) to defer setting configuration after construction has completed.
Ted Patrick 12 лет назад
Родитель
Сommit
b784efe748
1 измененных файлов с 11 добавлено и 2 удалено
  1. 11 2
      src/viewmodel.js

+ 11 - 2
src/viewmodel.js

@@ -16,7 +16,8 @@ var Compiler   = require('./compiler'),
  *  and a few reserved methods
  */
 function ViewModel (options) {
-    // just compile. options are passed directly to compiler
+    // compile if options passed, if false return. options are passed directly to compiler
+    if( options === false ) return;
     new Compiler(this, options)
 }
 
@@ -24,6 +25,14 @@ function ViewModel (options) {
 // so it can be stringified/looped through as raw data
 var VMProto = ViewModel.prototype
 
+/**
+ *  init allows config compilation after instantiation
+ *  var a = new Vue(false); a.init( config );
+ */
+def(VMProto, 'init', function (options) {
+    new Compiler( this, options )
+})
+
 /**
  *  Convenience function to get a value from
  *  a keypath
@@ -177,4 +186,4 @@ function query (el) {
         : el
 }
 
-module.exports = ViewModel
+module.exports = ViewModel