@@ -113,19 +113,6 @@ type Option struct {
113
113
// use of the common <script type="x-template"> trick to include templates.
114
114
Template string `js:"template"`
115
115
116
- // Type: Boolean
117
- //
118
- // Default: true
119
- //
120
- // Restriction: only respected if the template option is also present.
121
- //
122
- // Details:
123
- //
124
- // Determines whether to replace the element being mounted on with the
125
- // template. If set to false, the template will overwrite the element’s inner
126
- // content without replacing the element itself.
127
- Replace bool `js:"replace"`
128
-
129
116
// parent
130
117
//
131
118
// Type: Vue instance
@@ -186,6 +173,9 @@ func (c *Option) prepare() (opts *js.Object) {
186
173
// SetDataWithMethods set data and methods of the genereated VueJS instance
187
174
// based on `structPtr` and `js.MakeWrapper(structPtr)`
188
175
func (c * Option ) SetDataWithMethods (structPtr interface {}) * Option {
176
+ if structPtr == nil {
177
+ return c
178
+ }
189
179
c .Set ("data" , structPtr )
190
180
c .Set ("methods" , js .MakeWrapper (structPtr ))
191
181
return c
@@ -203,6 +193,43 @@ func (o *Option) AddMethod(name string, fn func(vm *ViewModel, args []*js.Object
203
193
})
204
194
}
205
195
196
+ type CreateElement func (tagName string , data interface {}, children []interface {}) (vnode * js.Object )
197
+ type Render func (vm * ViewModel , fn CreateElement )
198
+
199
+ func (o * Option ) SetRender (r Render ) {
200
+ fn := js .MakeFunc (func (this * js.Object , arguments []* js.Object ) interface {} {
201
+ vm := newViewModel (this )
202
+ jsCreateElement := arguments [0 ]
203
+ createElement := func (tagName string , data interface {}, children []interface {}) (vnode * js.Object ) {
204
+ return jsCreateElement .Call (tagName , data , children )
205
+ }
206
+ r (vm , createElement )
207
+ return nil
208
+ })
209
+ o .Object .Set ("render" , fn )
210
+ }
211
+
212
+ // AddComputed set computed data
213
+ func (o * Option ) AddComputed (name string , getter func (vm * ViewModel ) interface {}, setter ... func (vm * ViewModel , val * js.Object )) {
214
+ conf := make (map [string ]js.M )
215
+ conf [name ] = make (js.M )
216
+ fnGetter := js .MakeFunc (func (this * js.Object , arguments []* js.Object ) interface {} {
217
+ vm := newViewModel (this )
218
+ return getter (vm )
219
+ })
220
+ conf [name ]["get" ] = fnGetter
221
+ if len (setter ) > 0 {
222
+ fnSetter := js .MakeFunc (func (this * js.Object , arguments []* js.Object ) interface {} {
223
+ vm := newViewModel (this )
224
+ setter [0 ](vm , arguments [0 ])
225
+ return nil
226
+ })
227
+ conf [name ]["set" ] = fnSetter
228
+ }
229
+ // using mixin here
230
+ o .addMixin ("computed" , conf )
231
+ }
232
+
206
233
func (o * Option ) OnLifeCycleEvent (evt LifeCycleEvent , fn func (vm * ViewModel )) * Option {
207
234
return o .addMixin (
208
235
string (evt ),
0 commit comments